Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One click reposting #212

Merged
merged 4 commits into from
Aug 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_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")],
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() %}
<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 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
47 changes: 16 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_from(post)
return render_template('postjob.html', form=form, no_email=no_email)


Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)