diff --git a/hasjob/forms.py b/hasjob/forms.py index 9d8806500..f29a85781 100644 --- a/hasjob/forms.py +++ b/hasjob/forms.py @@ -354,6 +354,34 @@ def validate(self): self.send_signals() return success + def populate_from(self, post): + 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")], diff --git a/hasjob/templates/detail.html b/hasjob/templates/detail.html index f5e6c6cbb..25ba79917 100644 --- a/hasjob/templates/detail.html +++ b/hasjob/templates/detail.html @@ -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> Edit this </a> + {%- if post.is_old() %} + <a class="list-group-item" href="{{ url_for('newjob', template=post.hashid) }}"> + <i class="fa fa-fw fa-refresh"></i> 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> Withdraw this diff --git a/hasjob/templates/postjob.html b/hasjob/templates/postjob.html index d8b2c9b8e..c5af3c937 100644 --- a/hasjob/templates/postjob.html +++ b/hasjob/templates/postjob.html @@ -2,6 +2,13 @@ {% from "baseframe/forms.html" import renderfield, rendersubmit, widgetscripts %} {% block title %}List a job{% endblock %} {% block content %} + {%- 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> diff --git a/hasjob/views/listing.py b/hasjob/views/listing.py index d648e7a55..bc64e2c72 100644 --- a/hasjob/views/listing.py +++ b/hasjob/views/listing.py @@ -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_from(post) return render_template('postjob.html', form=form, no_email=no_email) @@ -924,6 +895,7 @@ def editjob(hashid, key, domain=None, form=None, validated=False, newpost=None): @app.route('/new', methods=('GET', 'POST')) def newjob(): form = forms.ListingForm() + archived_post = None if not g.user: if request.method == 'POST' and request.form.get('form.id') == 'newheadline': session['headline'] = form.job_headline.data @@ -953,6 +925,19 @@ def newjob(): if g.user: # form.poster_name.data = g.user.fullname # Deprecated 2013-11-20 form.poster_email.data = g.user.email + + # Job Reposting + if request.method == 'GET' and request.args.get('template'): + archived_post = JobPost.get(request.args['template']) + if not archived_post: + abort(404) + if not archived_post.admin_is(g.user): + abort(403) + if not archived_post.is_old(): + flash("This post is currently active and cannot be posted again.") + return redirect(archived_post.url_for(), code=303) + form.populate_from(archived_post) + 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 @@ -971,4 +956,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, archived_post=archived_post)