Skip to content

Commit

Permalink
Switch to new URL structure. Fixes #145
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Feb 16, 2015
1 parent fc8867b commit 54bb4ab
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 101 deletions.
45 changes: 41 additions & 4 deletions hasjob/models/jobpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ def is_listed(self):
return (self.status in POSTSTATUS.LISTED) and (
self.datetime > now - agelimit)

def is_public(self):
return self.status in POSTSTATUS.LISTED

def is_flagged(self):
return self.status == POSTSTATUS.FLAGGED

Expand All @@ -218,16 +221,38 @@ def pay_type_label(self):
return PAY_TYPE.get(self.pay_type)

def url_for(self, action='view', _external=False, **kwargs):
if self.status in POSTSTATUS.UNPUBLISHED and action in ('view', 'edit'):
domain = None
else:
domain = self.email_domain

if action == 'view':
return url_for('jobdetail', hashid=self.hashid, _external=_external, **kwargs)
return url_for('jobdetail', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
elif action == 'reveal':
return url_for('revealjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
elif action == 'apply':
return url_for('applyjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
elif action == 'edit':
return url_for('editjob', hashid=self.hashid, _external=_external, **kwargs)
return url_for('editjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
elif action == 'withdraw':
return url_for('withdraw', hashid=self.hashid, _external=_external, **kwargs)
return url_for('withdraw', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
elif action == 'moderate':
return url_for('moderatejob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
elif action == 'pin':
return url_for('pinnedjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
elif action == 'reject':
return url_for('rejectjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
elif action == 'confirm':
return url_for('confirm', hashid=self.hashid, _external=_external, **kwargs)
elif action == 'logo':
return url_for('logoimage', hashid=self.hashid, _external=True, **kwargs)
return url_for('logoimage', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
elif action == 'confirm-link':
return url_for('confirm_email', hashid=self.hashid, domain=domain,
key=self.email_verify_key, _external=True, **kwargs)
elif action == 'star':
return url_for('starjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
elif action == 'manage':
return url_for('managejob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
elif action == 'browse':
if self.email_domain in webmail_domains:
return url_for('browse_by_email', md5sum=self.md5sum, _external=_external, **kwargs)
Expand Down Expand Up @@ -668,6 +693,18 @@ def application_count(self):
'rejected': counts[EMPLOYER_RESPONSE.REJECTED],
}

def url_for(self, action='view', _external=False, **kwargs):
domain = self.jobpost.email_domain
if action == 'view':
return url_for('view_application', hashid=self.jobpost.hashid, domain=domain, application=self.hashid,
_external=_external, **kwargs)
elif action == 'process':
return url_for('process_application', hashid=self.jobpost.hashid, domain=domain, application=self.hashid,
_external=_external, **kwargs)
elif action == 'track-open':
return url_for('view_application_email_gif', hashid=self.jobpost.hashid, domain=domain, application=self.hashid,
_external=_external, **kwargs)


JobApplication.jobpost = db.relationship(JobPost,
backref=db.backref('applications', order_by=(
Expand Down
4 changes: 2 additions & 2 deletions hasjob/templates/application.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h2>{{ job_application.fullname }}</h2>
</p>
{{ job_application.message|safe }}
<hr>
<form id="response_form" method="POST" action="{{ url_for('process_application', hashid=post.hashid, application=job_application.hashid) }}">
<form id="response_form" method="POST" action="{{ job_application.url_for('process') }}">
<input type="hidden" name="_charset_"/>
<input type="hidden" name="form.id" value="process_application_form"/>
{{ response_form.hidden_tag() }}
Expand Down Expand Up @@ -97,7 +97,7 @@ <h2>{{ job_application.fullname }}</h2>
<div class="col-md-3">
<div class="list-group">
{%- for appl in post.applications %}
<a class="list-group-item status_{{ appl.status|lower }}" href="{{ url_for('view_application', hashid=post.hashid, application=appl.hashid) }}">
<a class="list-group-item status_{{ appl.status|lower }}" href="{{ appl.url_for() }}">
{%- if appl == job_application -%}
<strong>{{ appl.fullname }}</strong>
{%- else -%}
Expand Down
2 changes: 1 addition & 1 deletion hasjob/templates/apply_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
</p>
<p>
<strong>Note:</strong> The message above is exactly as the candidate submitted it. We do not accept attachments or reformat documents.
<img src="{{ url_for('view_application_email_gif', hashid=post.hashid, application=job_application.hashid, _external=true) }}" alt="" width="1" height="1">
<img src="{{ job_application.url_for('track-open', _external=true) }}" alt="" width="1" height="1">
</p>
{% endblock %}
2 changes: 1 addition & 1 deletion hasjob/templates/confirm.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h1>Terms of service</h1>
</div>
{% else %}
<div class="flash">
<p>Nothing to confirm. <a href="{{ url_for('detail', post.hashid) }}">See the post</a>?</p>
<p>Nothing to confirm. <a href="{{ post.url_for() }}">See the post</a>?</p>
</div>
{% endif %}
{% endblock %}
2 changes: 1 addition & 1 deletion hasjob/templates/confirm_email.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is a confirmation email for the job you listed at {% if g.board -%} {{ g.bo

[Click here to confirm your email address and publish the job][confirm]

[confirm]: {{ url_for('confirm_email', _external=true, hashid=post.hashid, key=post.email_verify_key) }}
[confirm]: {{ post.url_for('confirm-link', _external=true) }}

Save this email for the next 30 days while the post is active. Use these
links if you need to edit the post, or if the position has been filled
Expand Down
20 changes: 11 additions & 9 deletions hasjob/templates/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ <h2>Job Perks</h2>
</div>
<div class="col-md-3">{% if not g.kiosk %}
<div class="list-group">
<a class="list-group-item" href="mailto:?subject=Job%3A%20{{ post.headline|urlquoteplus }}&amp;body={{ post.url_for('view', utm_campaign='share', utm_medium='email', _external=true)|urlquoteplus }}">
<a class="list-group-item" href="mailto:?subject=Job%3A%20{{ post.headline|urlquoteplus }}&amp;body={{ post.url_for(utm_campaign='share', utm_medium='email', _external=true)|urlquoteplus }}">
<i class="fa fa-fw fa-envelope"></i>&nbsp;&nbsp; Email this
</a>
<a class="list-group-item visible-xs-block visible-sm-block" href="whatsapp://send?text={{ post.headline|urlquoteplus }}+{{ post.url_for('view', utm_campaign='share', utm_medium='whatsapp', _external=true)|urlquoteplus }}">
<a class="list-group-item visible-xs-block visible-sm-block" href="whatsapp://send?text={{ post.headline|urlquoteplus }}+{{ post.url_for(utm_campaign='share', utm_medium='whatsapp', _external=true)|urlquoteplus }}">
<i class="fa fa-fw fa-whatsapp"></i>&nbsp;&nbsp; Share on WhatsApp
</a>
<a class="list-group-item share-popup" data-width="550" data-height="250" target="_blank" href="https://twitter.com/share?url={{ post.url_for(utm_campaign='share', utm_medium='twitter', _external=true)|urlquoteplus }}&amp;counturl={{ post.url_for(_external=true)|urlquoteplus }}&amp;via=hasjob&amp;related=hasjob:HasGeek%20Job%20Board&amp;text=Job%3A%20{{ post.headline|urlquoteplus }}">
<span class="badge" id="tweet-count"></span><i class="fa fa-fw fa-twitter"></i>&nbsp;&nbsp; Tweet this
</a>
<a class="list-group-item share-popup" data-width="520" data-height="230" target="_blank" href="http://www.facebook.com/sharer.php?s=100&p[url]={{ post.url_for('view', utm_campaign='share', utm_medium='facebook', _external=true)|urlquoteplus }}">
<a class="list-group-item share-popup" data-width="520" data-height="230" target="_blank" href="http://www.facebook.com/sharer.php?s=100&p[url]={{ post.url_for(utm_campaign='share', utm_medium='facebook', _external=true)|urlquoteplus }}">
<i class="fa fa-fw fa-facebook"></i>&nbsp;&nbsp; Share on Facebook
</a>
{%- if not g.kiosk and not post.is_announcement() %}
Expand Down Expand Up @@ -124,9 +124,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>
<a class="list-group-item" href="{{ post.url_for('withdraw') }}">
<i class="fa fa-fw fa-trash-o"></i>&nbsp;&nbsp; Withdraw this
</a>
{%- 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
</a>
{%- endif %}
{%- endif %}
{%- if is_siteadmin %}
<div class="list-group-item">
Expand Down Expand Up @@ -184,7 +186,7 @@ <h2>What’s wrong with it?</h2>
</span>
{%- endif %}
{%- with appl=post.viewcounts['applied'], newappl=post.new_applications %}{% if appl %}
<a class="list-group-item" href="{{ url_for('managejob', hashid=post.hashid) }}">
<a class="list-group-item" href="{{ post.url_for('manage') }}">
<i class="fa fa-fw fa-file-text-o"></i>&nbsp;&nbsp; View candidates
{%- if newappl %} <span class="badge badge-new">{{ newappl }}/{{ appl }}</span>
{%- else %} <span class="badge">{{ appl }}</span>
Expand Down Expand Up @@ -245,10 +247,10 @@ <h2>Apply for this position
{% 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="{{ url_for('revealjob', hashid=post.hashid) }}">Show instructions</a>
<a class="btn btn-primary" id="reveal-button" href="{{ post.url_for('reveal') }}">Show instructions</a>
{%- endif %}
{%- else %}
<a class="btn btn-primary" href="{{ url_for('revealjob', hashid=post.hashid) }}">Login with Twitter or Google</a>
<a class="btn btn-primary" href="{{ post.url_for('reveal') }}">Login with Twitter or Google</a>
to see instructions on how to apply.
Your identity will not be revealed to the employer.
{%- endif %}
Expand Down
2 changes: 1 addition & 1 deletion hasjob/templates/inc/applyform.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% from "baseframe/forms.html" import renderfield, rendersubmit, ajaxform %}
<form id="applyform" method="POST" class="form-horizontal" action="{{ url_for('applyjob', hashid=post.hashid) }}">
<form id="applyform" method="POST" class="form-horizontal" action="{{ post.url_for('apply') }}">
<input type="hidden" name="_charset_"/>
<input type="hidden" name="form.id" value="applyform"/>
{{ applyform.hidden_tag() }}
Expand Down
2 changes: 1 addition & 1 deletion hasjob/templates/inc/moderateform.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% from "baseframe/forms.html" import renderfield, ajaxform %}
<form id="moderateform" method="POST" action="{{ url_for('moderatejob', hashid=post.hashid) }}" class="form-horizontal">
<form id="moderateform" method="POST" action="{{ post.url_for('moderate') }}" class="form-horizontal">
<input type="hidden" name="_charset_"/>
<input type="hidden" name="form.id" value="moderateform"/>
{{ moderateform.hidden_tag() }}
Expand Down
2 changes: 1 addition & 1 deletion hasjob/templates/inc/pinnedform.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% from "baseframe/forms.html" import renderfield, ajaxform %}
<form id="pinnedform" method="POST" action="{{ url_for('pinnedjob', hashid=post.hashid) }}" class="form-horizontal">
<form id="pinnedform" method="POST" action="{{ post.url_for('pin') }}" class="form-horizontal">
<input type="hidden" name="_charset_"/>
<input type="hidden" name="form.id" value="pinnedform"/>
{{ pinnedform.hidden_tag() }}
Expand Down
2 changes: 1 addition & 1 deletion hasjob/templates/inc/rejectform.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% from "baseframe/forms.html" import renderfield, ajaxform %}
<form id="rejectform" method="POST" action="{{ url_for('rejectjob', hashid=post.hashid) }}" class="form-horizontal">
<form id="rejectform" method="POST" action="{{ post.url_for('reject') }}" class="form-horizontal">
<input type="hidden" name="_charset_"/>
<input type="hidden" name="form.id" value="rejectform"/>
{{ rejectform.hidden_tag() }}
Expand Down
2 changes: 1 addition & 1 deletion hasjob/templates/inc/replyform.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% from "baseframe/forms.html" import renderfield %}
<form id="replyform" method="POST" class="form-horizontal" action="{{ url_for('process_application', hashid=post.hashid, application=job_application.hashid) }}">
<form id="replyform" method="POST" class="form-horizontal" action="{{ job_application.url_for('process') }}">
<input type="hidden" name="_charset_"/>
<input type="hidden" name="form.id" value="response_form"/>
{{ response_form.hidden_tag() }}
Expand Down
12 changes: 9 additions & 3 deletions hasjob/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,21 @@ def browse_by_type(name):


@csrf.exempt
@app.route('/at/<domain>', methods=['GET', 'POST'], subdomain='<subdomain>')
@app.route('/at/<domain>', methods=['GET', 'POST'])
@app.route('/<domain>', methods=['GET', 'POST'], subdomain='<subdomain>')
@app.route('/<domain>', methods=['GET', 'POST'])
def browse_by_domain(domain):
if not domain:
if not domain or '.' not in domain:
abort(404)
basequery = JobPost.query.filter_by(email_domain=domain)
return index(basequery=basequery, domain=domain, title=domain, showall=True)


@app.route('/at/<domain>', methods=['GET', 'POST'], subdomain='<subdomain>')
@app.route('/at/<domain>', methods=['GET', 'POST'])
def browse_by_domain_legacy(domain):
return redirect(url_for('browse_by_domain', domain=domain), code=301)


@csrf.exempt
@app.route('/category/<name>', methods=['GET', 'POST'], subdomain='<subdomain>')
@app.route('/category/<name>', methods=['GET', 'POST'])
Expand Down
Loading

0 comments on commit 54bb4ab

Please sign in to comment.