forked from hasgeek/hasjob
/
forms.py
109 lines (95 loc) · 5.83 KB
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
import re
from flask import g, request
from flaskext.wtf import Form, TextField, TextAreaField, RadioField, FileField, BooleanField
from flaskext.wtf import Required, Email, Length, URL, ValidationError
from flaskext.wtf.html5 import URLField, EmailField
from uploads import process_image
from utils import simplify_text
QUOTES_RE = re.compile(ur'[\'"`‘’“”′″‴]+')
def optional_url(form, field):
"""
Validate URL only if present.
"""
if not field.data:
return
else:
if ':' not in field.data:
field.data = 'http://' + field.data
validator = URL(message="Invalid URL. URLs must begin with http:// or https://")
return validator(form, field)
class ListingForm(Form):
"""Form for new job posts"""
job_headline = TextField("Headline",
description="A single-line summary. This goes to the front page and across the network",
validators=[Required("A headline is required"),
Length(min=1, max=100, message="%(max)d characters maximum")])
job_type = RadioField("Type", coerce=int, validators=[Required("The job type must be specified")])
job_category = RadioField("Category", coerce=int, validators=[Required("Select a category")])
job_location = TextField("Location",
description=u'“Accra”, “Kumasi”, “Takoradi”, etc or “Anywhere” (without quotes)',
validators=[Required(u"If this job doesn’t have a fixed location, use “Anywhere”")])
job_relocation_assist = BooleanField("Relocation assistance available")
job_description = TextAreaField("Description",
description=u"Our apologies for the mismatched font you see here. We’re working on it",
validators=[Required("A description of the job is required")])
job_perks = BooleanField("Job perks are available")
job_perks_description = TextAreaField("Describe job perks",
description=u"Stock options, free lunch, free conference passes, etc")
job_how_to_apply = TextAreaField("How do people apply for this job?",
description=u'Example: "Send a resume to kofi@mycompany.com". '
u"Don’t worry about spambots seeing your email address. "
u"We’ll secure it",
validators=[Required("Agbena job does not offer screening services. Please specify how candidates may apply")])
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 company isn’t named yet",
validators=[Required(u"This is required. Posting any name other than that of the actual organization is a violation of the ToS")])
company_logo = FileField("Logo",
description=u"Optional — Your company logo will appear at the top of your listing. "
u"170px wide is optimal. We’ll resize automatically if it’s wider",
)#validators=[file_allowed(uploaded_logos, "That image type is not supported")])
company_logo_remove = BooleanField("Remove existing logo")
company_url = TextField("URL",
description = u"Example: http://www.addhen.org",
validators=[optional_url])
poster_email = EmailField("Email",
description = u"This is where we’ll send your confirmation email. "\
u"It will not be revealed to applicants",
validators=[Required("We need to confirm your email address before the job can be listed"),
Email("That does not appear to be a valid email address")])
def validate_company_logo(form, field):
if not request.files['company_logo']:
return
try:
g.company_logo = process_image(request.files['company_logo'])
except IOError, e:
raise ValidationError(e.message)
except KeyError, e:
raise ValidationError("Unknown file format")
def validate_job_headline(form, field):
# XXX: These validations belong in a config file or in the db, not here.
if simplify_text(field.data) == 'awesome coder wanted at awesome company':
raise ValidationError(u"Come on, write your own headline. You aren’t just another run-of-the-mill company, right?")
if 'awesome' in field.data.lower():
raise ValidationError(u'We’ve had a bit too much awesome around here lately. Got another adjective?')
if 'rockstar' in field.data.lower() or 'rock star' in field.data.lower() or 'rock-star' in field.data.lower():
raise ValidationError(u'You are not rich enough to hire a rockstar. Got another adjective?')
if 'kickass' in field.data.lower() or 'kick ass' in field.data.lower() or 'kick-ass' in field.data.lower():
raise ValidationError(u'We don’t condone kicking asses around here. Got another adjective?')
if 'ninja' in field.data.lower():
raise ValidationError(u'Ninjas kill people. We can’t allow that. Got another adjective?')
if 'urgent' in field.data.lower():
raise ValidationError(u'Sorry, we can’t help with urgent requirements. Geeks don’t grow on trees')
def validate_job_location(form, field):
if QUOTES_RE.search(field.data) is not None:
raise ValidationError(u"Don’t use quotes in the location name")
class ConfirmForm(Form):
terms_accepted = BooleanField("I accept the terms of service",
validators=[Required("You must accept the terms of service to publish this listing")])
#promocode = TextField("Promo code")
class WithdrawForm(Form):
really_withdraw = BooleanField("Yes, I really want to withdraw the job listing",
validators=[Required(u"If you don’t want to withdraw the listing, just close this page")])
class ReportForm(Form):
report_code = RadioField("Code", coerce=int, validators=[Required(u"Pick one")])