Skip to content

Commit

Permalink
Move ApplicationForm into /reveal endpoint. Fixes hasgeek#343
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Jun 10, 2016
1 parent 5f743fe commit b46109e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 66 deletions.
40 changes: 10 additions & 30 deletions hasjob/templates/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,7 @@ <h2>Apply for this position
{%- if post.is_draft() %}{# Always show when in draft state #}
{{ post.how_to_apply|hideemail }}
{%- elif g.user %}
{% if jobview.applied %}{# User has already hit the reveal button #}
{{ post.how_to_apply|hideemail }}
{%- else %}
<a class="btn btn-primary" id="reveal-button" href="{{ post.url_for('reveal') }}">Show instructions</a>
{%- endif %}
<a class="btn btn-primary" id="reveal-button" href="{{ post.url_for('reveal') }}">Show instructions</a> <span class="loading hidden"></span>
{%- else %}
<a class="btn btn-primary" href="{{ post.url_for('reveal') }}">Login with Twitter or Google</a>
to see instructions on how to apply.
Expand All @@ -291,9 +287,7 @@ <h2>Apply for this position
{%- endif %}
</div>
{%- if not post.is_draft() and (g.user or g.kiosk) and applyform %}
<div id="apply-section" class="section {%- if g.kiosk or (jobview and not jobview.applied) %} hidden {%- endif -%}">
{#- This form must be part of the page (even if hidden) in kiosk mode, so remember that if we ever remove it pre-reveal #}
{% include "inc/applyform.html" %}
<div id="apply-section" class="section hidden">
</div>
{%- endif %}
{%- if post.hr_contact is not none %}{# Don't display notice on old posts #}
Expand All @@ -316,17 +310,6 @@ <h2>Apply for this position
</p>
</div>
{%- endif %}
{%- if job_application %}
<div class="section">
<h3>You have applied for this position</h3>
<p>
<strong>Name:</strong> {{ job_application.fullname }}<br>
<strong>Email:</strong> {{ job_application.email }}<br>
<strong>Phone:</strong> {{ job_application.phone }}
</p>
{{ job_application.message|safe }}
</div>
{%- endif %}
{%- if is_siteadmin %}
<div class="section unmarked" id="tagcloud">
<p>
Expand Down Expand Up @@ -435,16 +418,19 @@ <h2>A/B test results</h2>
});
$(function() {
$("#reveal-button").on('click dblclick', function(e) {
var reveal_button = this;
e.preventDefault();
$(this).attr('disabled', 'disabled');
$.ajax($(this).attr('href')).done(function(html) {
$("#apply-info-para").html(html);
$(reveal_button).attr('disabled', 'disabled');
$('#reveal-button + .loading').removeClass('hidden');
$.ajax($(reveal_button).attr('href'), {method: 'POST'}).done(function(html) {
$("#apply-info-para").replaceWith(html);
{%- if applyform %}
$("#apply-section").removeClass('hidden');
{%- endif %}
})
.fail(function(msg){
$(this).removeAttr("disabled");
$('#reveal-button + .loading').addClass('hidden');
$(reveal_button).removeAttr('disabled');
});
return false;
});
Expand All @@ -469,13 +455,7 @@ <h2>A/B test results</h2>
{{ ajaxform('rejectform', request, force=true) }}
{{ ajaxform('pinnedform', request, force=true) }}
{{ ajaxform('moderateform', request, force=true) }}
{% if applyform %}
{{ ajaxform('applyform', request, force=true) }}
{% assets "js_tinymce" %}<script src="{{ ASSET_URL }}" type="text/javascript"></script>{% endassets %}
<script type="text/javascript">
{% include "inc/tinymce.js" %}
</script>
{% endif %}
{% assets "js_tinymce" %}<script src="{{ ASSET_URL }}" type="text/javascript"></script>{% endassets %}
{%- if is_siteadmin or post.admin_is(g.user) or (g.user and g.user.flags.is_employer_month) %}{% with stats = post.viewstats[1], max = stats.max|tojson %}
<script type="text/javascript">
$(function() {
Expand Down
4 changes: 3 additions & 1 deletion hasjob/templates/inc/applyform.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
{%- if request.is_xhr %}
{{ ajaxform("applyform", request) }}
<script type="text/javascript">
tinymce.editors[0].remove(); {#- FIXME: Do this right with Baseframe’s richtext editor #}
if (typeof tinymce.editors[0] !== 'undefined') {
tinymce.editors[0].remove(); {#- FIXME: Do this right with Baseframe’s richtext editor #}
};
{% include "inc/tinymce.js" %}
</script>
{%- endif %}
15 changes: 15 additions & 0 deletions hasjob/templates/jobpost_reveal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% from "baseframe/forms.html" import ajaxform -%}
<p id="apply-info-para">{{ instructions }}</p>
{%- if job_application %}
<h3>You have applied for this position</h3>
<p>
<strong>Name:</strong> {{ job_application.fullname }}<br>
<strong>Email:</strong> {{ job_application.email }}<br>
<strong>Phone:</strong> {{ job_application.phone }}
</p>
{{ job_application.message|safe }}
{%- else %}
{%- if applyform %}
{% include "inc/applyform.html" %}
{% endif %}
{%- endif %}
62 changes: 27 additions & 35 deletions hasjob/views/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ def jobdetail(domain, hashid):
is_siteadmin = lastuser.has_permission('siteadmin')
query = JobPost.query.filter_by(hashid=hashid).options(
db.subqueryload('locations'), db.subqueryload('taglinks'))
# if g.user:
# query = query.outerjoin(UserJobView,
# db.and_(UserJobView.user_id == g.user.id, UserJobView.jobpost_id == JobPost.id))
post = query.first_or_404()

# If we're on a board (that's not 'www') and this post isn't on this board,
Expand Down Expand Up @@ -123,17 +120,7 @@ def jobdetail(domain, hashid):
pinnedform = forms.PinnedForm(obj=post.link_to_board(g.board))
else:
pinnedform = forms.PinnedForm(obj=post)
applyform = None # User isn't allowed to apply unless non-None
if g.user:
job_application = JobApplication.query.filter_by(user=g.user, jobpost=post).first()
if not job_application:
applyform = forms.ApplicationForm()
applyform.apply_phone.data = g.user.phone
elif g.kiosk and g.peopleflow_url:
applyform = forms.KioskApplicationForm()
job_application = None
else:
job_application = None

if reportform.validate_on_submit():
if g.user:
if report is None:
Expand Down Expand Up @@ -178,7 +165,7 @@ def jobdetail(domain, hashid):
headline = post.headlineb if is_bgroup and post.headlineb else post.headline

return render_template('detail.html', post=post, headline=headline, reportform=reportform, rejectform=rejectform,
pinnedform=pinnedform, applyform=applyform, job_application=job_application,
pinnedform=pinnedform,
jobview=jobview, report=report, moderateform=moderateform,
domain_mismatch=domain_mismatch, header_campaign=header_campaign,
is_bgroup=is_bgroup, is_siteadmin=is_siteadmin
Expand Down Expand Up @@ -235,48 +222,53 @@ def starjob(domain, hashid):
return response


@app.route('/<domain>/<hashid>/reveal', subdomain='<subdomain>')
@app.route('/<domain>/<hashid>/reveal')
@app.route('/reveal/<hashid>', defaults={'domain': None}, subdomain='<subdomain>')
@app.route('/reveal/<hashid>', defaults={'domain': None})
@csrf.exempt
@app.route('/<domain>/<hashid>/reveal', methods=['POST'], subdomain='<subdomain>')
@app.route('/<domain>/<hashid>/reveal', methods=['POST'])
@app.route('/reveal/<hashid>', methods=['POST'], defaults={'domain': None}, subdomain='<subdomain>')
@app.route('/reveal/<hashid>', methods=['POST'], defaults={'domain': None})
@lastuser.requires_login
def revealjob(domain, hashid):
"""
This view is a GET request and that is intentional.
Reveal job application form
"""
post = JobPost.query.filter_by(hashid=hashid).first_or_404()
# If the domain doesn't match, redirect to correct URL
if post.email_domain != domain:
return redirect(post.url_for('reveal'), code=301)

if post.status in [POSTSTATUS.REJECTED, POSTSTATUS.WITHDRAWN, POSTSTATUS.SPAM]:
if post.status in POSTSTATUS.GONE:
abort(410)
jobview = UserJobView.query.get((post.id, g.user.id))
if jobview is None:
jobview = UserJobView(user=g.user, jobpost=post, applied=True)
post.uncache_viewcounts('opened')
cache.delete_memoized(viewstats_by_id_qhour, post.id)
cache.delete_memoized(viewstats_by_id_hour, post.id)
cache.delete_memoized(viewstats_by_id_day, post.id)
db.session.add(jobview)
try:
db.session.commit()
post.uncache_viewcounts('opened')
cache.delete_memoized(viewstats_by_id_qhour, post.id)
cache.delete_memoized(viewstats_by_id_hour, post.id)
cache.delete_memoized(viewstats_by_id_day, post.id)
post.viewcounts # Re-populate cache
except IntegrityError:
db.session.rollback()
pass # User double-clicked. Ignore.
post.viewcounts # Re-populate cache
elif not jobview.applied:
jobview.applied = True
db.session.commit()
post.uncache_viewcounts('opened')
cache.delete_memoized(viewstats_by_id_qhour, post.id)
cache.delete_memoized(viewstats_by_id_hour, post.id)
cache.delete_memoized(viewstats_by_id_day, post.id)
db.session.commit()
post.viewcounts # Re-populate cache
if request.is_xhr:
return redactemail(post.how_to_apply)
else:
return redirect(post.url_for(), 303)

applyform = None
job_application = JobApplication.query.filter_by(user=g.user, jobpost=post).first()
if not job_application:
applyform = forms.ApplicationForm()
applyform.apply_phone.data = g.user.phone

return render_template('jobpost_reveal.html',
post=post,
instructions=redactemail(post.how_to_apply),
applyform=applyform,
job_application=job_application)


@csrf.exempt
Expand Down

0 comments on commit b46109e

Please sign in to comment.