Skip to content

Commit

Permalink
Obfuscated email validator; trap Enter key
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Oct 14, 2014
1 parent 58bc6ec commit cc5376f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ baseframe-packed.css
editor.packed.css
uploads/
search/
hasjob/static/gen
30 changes: 10 additions & 20 deletions hasjob/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from flask import g, request, Markup
from baseframe.forms import (Form, ValidEmail, ValidUrl, AllUrlsValid, TinyMce4Field, UserSelectMultiField,
AnnotatedTextField, FormField, NullTextField, ValidName)
AnnotatedTextField, FormField, NullTextField, ValidName, NoObfuscatedEmail)
from baseframe.forms.sqlalchemy import AvailableName
from wtforms import (TextField, TextAreaField, RadioField, FileField, BooleanField,
ValidationError, validators)
Expand Down Expand Up @@ -68,7 +68,8 @@ class ListingForm(Form):
job_headline = TextField("Headline",
description="A single-line summary. This goes to the front page and across the network",
validators=[validators.Required("A headline is required"),
validators.Length(min=1, max=100, message="%(max)d characters maximum")])
validators.Length(min=1, max=100, message="%(max)d characters maximum"),
NoObfuscatedEmail(u"Do not include contact information in the listing")])
job_type = RadioField("Type", coerce=int, validators=[validators.Required("The job type must be specified")])
job_category = RadioField("Category", coerce=int, validators=[validators.Required("Select a category")])
job_location = TextField("Location",
Expand All @@ -80,13 +81,15 @@ class ListingForm(Form):
content_css=content_css,
description=u"Don’t just describe the job, tell a compelling story for why someone should work for you",
validators=[validators.Required("A description of the job is required"),
AllUrlsValid(invalid_urls=invalid_urls)],
AllUrlsValid(invalid_urls=invalid_urls),
NoObfuscatedEmail(u"Do not include contact information in the listing")],
tinymce_options={'convert_urls': True})
job_perks = BooleanField("Job perks are available")
job_perks_description = TinyMce4Field("Describe job perks",
content_css=content_css,
description=u"Stock options, free lunch, free conference passes, etc",
validators=[AllUrlsValid(invalid_urls=invalid_urls)])
validators=[AllUrlsValid(invalid_urls=invalid_urls),
NoObfuscatedEmail(u"Do not include contact information in the listing")])
job_pay_type = RadioField("What does this job pay?", coerce=int,
choices=PAY_TYPE.items())
job_pay_currency = ListingPayCurrencyField("Currency", choices=[("INR", "INR"), ("USD", "USD"), ("EUR", "EUR")])
Expand All @@ -100,8 +103,9 @@ class ListingForm(Form):
u"We now require candidates to apply through the job board only. "
u"Do not include any contact information here. Candidates CANNOT "
u"attach resumes or other documents, so do not ask for that",
validators=[validators.Required(u"We do not offer screening services. "
u"Please specify what candidates should submit")])
validators=[
validators.Required(u"We do not offer screening services. Please specify what candidates should submit"),
NoObfuscatedEmail(u"Do not include contact information in the listing")])
company_name = TextField("Name",
description=u"The name of the organization where the position is. "
u"No intermediaries or unnamed stealth startups. Use your own real name if the organization isn’t named "
Expand Down Expand Up @@ -168,8 +172,6 @@ def validate_company_logo(form, field):
raise ValidationError("Unsupported file format. We accept JPEG, PNG and GIF")

def validate_job_headline(form, field):
if EMAIL_RE.search(field.data) is not None:
raise ValidationError(u"Do not include contact information in the listing")
if simplify_text(field.data) in (
'awesome coder wanted at awesome company',
'pragmatic programmer wanted at outstanding organisation',
Expand All @@ -194,18 +196,6 @@ def validate_job_location(form, field):
if small == 0 or caps / float(small) > 0.5:
raise ValidationError("Surely this location isn't named in uppercase?")

def validate_job_description(form, field):
if EMAIL_RE.search(field.data) is not None:
raise ValidationError(u"Do not include contact information in the listing")

def validate_job_perks_description(form, field):
if EMAIL_RE.search(field.data) is not None:
raise ValidationError(u"Do not include contact information in the listing")

def validate_job_how_to_apply(form, field):
if EMAIL_RE.search(field.data) is not None or URL_RE.search(field.data) is not None:
raise ValidationError(u"Do not include contact information in the listing")

def validate_job_pay_cash_min(form, field):
if form.job_pay_type.data in (PAY_TYPE.ONETIME, PAY_TYPE.RECURRING):
data = field.data.strip()
Expand Down
7 changes: 7 additions & 0 deletions hasjob/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@
$("#newpost_details").hide().removeClass('jshidden');
$("#newpost_headline").focus(function() {
$("#newpost_details").slideDown();
}).keypress(function(event) {
if(event.which == '13') {
$(this).closest("form").submit();
return false;
}
}).blur(function() {
$(this).val($(this).val().replace(/(\r\n|\n|\r)/gm," ").replace(/\s+/g," "));
});
});
</script>
Expand Down
2 changes: 1 addition & 1 deletion hasjob/views/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ def editjob(hashid, key, form=None, post=None, validated=False):
session.permanent = True
return redirect(url_for('jobdetail', hashid=post.hashid), code=303)
elif request.method == 'POST':
flash("Please correct the indicated errors", category='interactive')
flash("Please review the indicated issues", category='interactive')
elif request.method == 'GET':
# Populate form from model
form.job_headline.data = post.headline
Expand Down

0 comments on commit cc5376f

Please sign in to comment.