Skip to content

Commit

Permalink
added ability to repost an archived job
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas-satish committed Aug 3, 2015
1 parent e368b58 commit 03143f2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 31 deletions.
28 changes: 28 additions & 0 deletions hasjob/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,34 @@ def validate(self):
self.send_signals()
return success

def populate(self, post):

This comment has been minimized.

Copy link
@jace

jace Aug 3, 2015

Member

This method is required only because the form's fields don't have the same names as the model's columns. Good time to ask if we should fix that. Caveat is that in /new and /edit we don't copy all fields as is from form to post and vice versa, so it'll require moving all that validation logic either into the form or the model.

This comment has been minimized.

Copy link
@jace

jace Aug 3, 2015

Member

Let's make this a separate ticket and discuss there. No need to hold up this feature.

self.job_headline.data = post.headline
self.job_headlineb.data = post.headlineb
self.job_type.data = post.type_id
self.job_category.data = post.category_id
self.job_location.data = post.location
self.job_relocation_assist.data = post.relocation_assist
self.job_description.data = post.description
self.job_perks.data = True if post.perks else False
self.job_perks_description.data = post.perks
self.job_how_to_apply.data = post.how_to_apply
self.company_name.data = post.company_name
self.company_url.data = post.company_url
self.poster_email.data = post.email
self.twitter.data = post.twitter
self.hr_contact.data = int(post.hr_contact or False)
self.collaborators.data = post.admins
self.job_pay_type.data = post.pay_type
if post.pay_type is None:
# This kludge required because WTForms doesn't know how to handle None in forms
self.job_pay_type.data = -1
self.job_pay_currency.data = post.pay_currency
self.job_pay_cash_min.data = post.pay_cash_min
self.job_pay_cash_max.data = post.pay_cash_max
self.job_pay_equity.data = bool(post.pay_equity_min and post.pay_equity_max)
self.job_pay_equity_min.data = post.pay_equity_min
self.job_pay_equity_max.data = post.pay_equity_max


class ApplicationForm(forms.Form):
apply_email = forms.RadioField("Email", validators=[forms.validators.DataRequired("Pick an email address")],
Expand Down
5 changes: 5 additions & 0 deletions hasjob/templates/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ <h2>What’s wrong with it?</h2>
<a class="list-group-item" href="{{ post.url_for('edit') }}">
<i class="fa fa-fw fa-pencil"></i>&nbsp;&nbsp; Edit this
</a>
{%- if post.is_old() %}

This comment has been minimized.

Copy link
@jace

jace Aug 3, 2015

Member

{%- if post.is_old() and post.owner_is(g.user) %}

This comment has been minimized.

Copy link
@jace

jace Aug 3, 2015

Member

Can't recall if the method is owner_is or admin_is.

This comment has been minimized.

Copy link
@shreyas-satish

shreyas-satish Aug 3, 2015

Author Contributor

This is nested under the admin check.

<a class="list-group-item" href="{{ url_for('newjob', template=post.hashid) }}">
<i class="fa fa-fw fa-refresh"></i>&nbsp;&nbsp; Repost this
</a>
{%- endif %}
{%- if post.is_public() %}
<a class="list-group-item" href="{{ post.url_for('withdraw') }}">
<i class="fa fa-fw fa-trash-o"></i>&nbsp;&nbsp; Withdraw this
Expand Down
7 changes: 7 additions & 0 deletions hasjob/templates/postjob.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
{% from "baseframe/forms.html" import renderfield, rendersubmit, widgetscripts %}
{% block title %}List a job{% endblock %}
{% block content %}
{%- if repost %}

This comment has been minimized.

Copy link
@jace

jace Aug 3, 2015

Member

{%- if archived_post %}

<div class="guide">
<p>
You're reposting <a href="{{archived_post.url_for()}}" target="_blank">{{archived_post.headline}}</a>.
</p>
</div>
{%- endif %}
<div class="sheet">
<div class="section first">
<div class="page-header"><h1>
Expand Down
46 changes: 15 additions & 31 deletions hasjob/views/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,36 +886,7 @@ def editjob(hashid, key, domain=None, form=None, validated=False, newpost=None):
elif request.method == 'POST':
flash("Please review the indicated issues", category='interactive')
elif request.method == 'GET':
# Populate form from model
form.job_headline.data = post.headline
form.job_headlineb.data = post.headlineb
form.job_type.data = post.type_id
form.job_category.data = post.category_id
form.job_location.data = post.location
form.job_relocation_assist.data = post.relocation_assist
form.job_description.data = post.description
form.job_perks.data = True if post.perks else False
form.job_perks_description.data = post.perks
form.job_how_to_apply.data = post.how_to_apply
form.company_name.data = post.company_name
form.company_url.data = post.company_url
# form.poster_name.data = post.fullname # Deprecated 2013-11-20
form.poster_email.data = post.email
form.twitter.data = post.twitter
form.hr_contact.data = int(post.hr_contact or False)
form.collaborators.data = post.admins

form.job_pay_type.data = post.pay_type
if post.pay_type is None:
# This kludge required because WTForms doesn't know how to handle None in forms
form.job_pay_type.data = -1
form.job_pay_currency.data = post.pay_currency
form.job_pay_cash_min.data = post.pay_cash_min
form.job_pay_cash_max.data = post.pay_cash_max
form.job_pay_equity.data = bool(post.pay_equity_min and post.pay_equity_max)
form.job_pay_equity_min.data = post.pay_equity_min
form.job_pay_equity_max.data = post.pay_equity_max

form.populate(post)

This comment has been minimized.

Copy link
@jace

jace Aug 3, 2015

Member

Okay, this is good for now, until we decide on renaming form fields.

return render_template('postjob.html', form=form, no_email=no_email)


Expand All @@ -924,6 +895,8 @@ def editjob(hashid, key, domain=None, form=None, validated=False, newpost=None):
@app.route('/new', methods=('GET', 'POST'))
def newjob():
form = forms.ListingForm()
repost = False

This comment has been minimized.

Copy link
@jace

jace Aug 3, 2015

Member

repost isn't necessary as archived_post is good enough for signalling.

archived_post = None
if not g.user:
if request.method == 'POST' and request.form.get('form.id') == 'newheadline':
session['headline'] = form.job_headline.data
Expand Down Expand Up @@ -953,6 +926,17 @@ def newjob():
if g.user:
# form.poster_name.data = g.user.fullname # Deprecated 2013-11-20
form.poster_email.data = g.user.email

if request.method == 'GET' and request.args.get('template'):
archived_post = JobPost.query.filter_by(hashid=request.args.get('template')).first()

This comment has been minimized.

Copy link
@jace

jace Aug 3, 2015

Member

archived_post = JobPost.get(hashid=request.args.get('template')

if not archived_post or not archived_post.admin_is(g.user):
abort(403)
if not archived_post.is_old():
flash("This listing is already active.")

This comment has been minimized.

Copy link
@jace

jace Aug 3, 2015

Member

Message should be: This listing is currently active and cannot be posted again.

return redirect(archived_post.url_for(), code=303)
form.populate(archived_post)
repost = True

if request.method == 'POST' and request.form.get('form.id') != 'newheadline' and form.validate():
# POST request from new job page, with successful validation
# Move it to the editjob page for handling here forward
Expand All @@ -971,4 +955,4 @@ def newjob():
# 1. GET request, page loaded for the first time
# 2. POST request from main page's Post a Job box
# 3. POST request from this page, with errors
return render_template('postjob.html', form=form, no_removelogo=True)
return render_template('postjob.html', form=form, no_removelogo=True, repost=repost, archived_post=archived_post)

0 comments on commit 03143f2

Please sign in to comment.