Skip to content

Commit

Permalink
JobType pay/webmail filter (fixes #100)
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Jun 19, 2014
1 parent 9d8af36 commit 2270cb3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
26 changes: 26 additions & 0 deletions alembic/versions/3fc1aa06cbeb_jobtype_flags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""JobType flags
Revision ID: 3fc1aa06cbeb
Revises: 434344d0a2d0
Create Date: 2014-06-19 23:29:23.643414
"""

# revision identifiers, used by Alembic.
revision = '3fc1aa06cbeb'
down_revision = '434344d0a2d0'

from alembic import op
import sqlalchemy as sa


def upgrade():
op.add_column('jobtype', sa.Column('nopay_allowed', sa.Boolean(), nullable=False, server_default='True'))
op.add_column('jobtype', sa.Column('webmail_allowed', sa.Boolean(), nullable=False, server_default='True'))
op.alter_column('jobtype', 'nopay_allowed', server_default=None)
op.alter_column('jobtype', 'webmail_allowed', server_default=None)


def downgrade():
op.drop_column('jobtype', 'webmail_allowed')
op.drop_column('jobtype', 'nopay_allowed')
21 changes: 17 additions & 4 deletions hasjob/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
from wtforms import (TextField, TextAreaField, RadioField, FileField, BooleanField,
ValidationError, validators)
from wtforms.fields.html5 import EmailField
from coaster.utils import getbool
from coaster.utils import getbool, get_email_domain

from .models import JobApplication, EMPLOYER_RESPONSE, PAY_TYPE
from .models import JobType, JobApplication, EMPLOYER_RESPONSE, PAY_TYPE, webmail_domains
from .uploads import process_image, UploadNotAllowed

from . import app, lastuser
from .utils import simplify_text, EMAIL_RE, URL_RE, PHONE_DETECT_RE, get_word_bag

QUOTES_RE = re.compile(ur'[\'"`‘’“”′″‴]+')
QUOTES_RE = re.compile(ur'[\'"`‘’“”′″‴«»]+')

CAPS_RE = re.compile('[A-Z]')
SMALL_RE = re.compile('[a-z]')
Expand Down Expand Up @@ -133,6 +133,11 @@ class ListingForm(Form):
u"to candidates who apply")


def validate_job_type(form, field):
form.job_type_ob = JobType.query.get(field.data)
if not form.job_type_ob:
raise ValidationError("Please select a job type")

def validate_company_name(form, field):
if len(field.data) > 5:
caps = len(CAPS_RE.findall(field.data))
Expand Down Expand Up @@ -256,6 +261,14 @@ def validate_job_pay_equity_max(form, field):
def validate(self, extra_validators=None):
success = super(ListingForm, self).validate(extra_validators)
if success:
# Check for job type flags
if (not self.job_type_ob.nopay_allowed) and self.job_pay_type.data == PAY_TYPE.NOCASH:
self.job_pay_type.errors.append(u"You must specify how much this job pays")
success = False
if (not self.job_type_ob.webmail_allowed) and get_email_domain(self.poster_email.data) in webmail_domains:
self.poster_email.errors.append(
u"Public webmail accounts like Gmail are not accepted. Please use your corporate email address")
success = False
# Check for cash pay range
if self.job_pay_type.data in (PAY_TYPE.ONETIME, PAY_TYPE.RECURRING):
if self.job_pay_cash_min.data == 0:
Expand Down Expand Up @@ -371,7 +384,7 @@ class KioskApplicationForm(Form):
u"post it on LinkedIn or host the file on Dropbox and insert the link here")

def validate_email(form, field):
oldapp = JobApplication.query.filter_by(jobpost=self.post, user=None, email=field.data).count()
oldapp = JobApplication.query.filter_by(jobpost=form.post, user=None, email=field.data).count()
if oldapp:
raise ValidationError("You have already applied for this position")

Expand Down
2 changes: 2 additions & 0 deletions hasjob/models/jobtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class JobType(BaseNameMixin, db.Model):

seq = db.Column(db.Integer, nullable=False, default=0)
public = db.Column(db.Boolean, nullable=False, default=True)
nopay_allowed = db.Column(db.Boolean, nullable=False, default=True)
webmail_allowed = db.Column(db.Boolean, nullable=False, default=True)

def __call__(self):
return self.title
Expand Down
4 changes: 2 additions & 2 deletions hasjob/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ def sitemap():
sitemapxml = '<?xml version="1.0" encoding="UTF-8"?>\n'\
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'
# Add job type pages to sitemap
for item in JobType.query.all():
for item in JobType.query.filter_by(public=True).all():
sitemapxml += ' <url>\n'\
' <loc>%s</loc>\n' % url_for('browse_by_type', name=item.name, _external=True) + \
' </url>\n'
# Add job category pages to sitemap
for item in JobCategory.query.all():
for item in JobCategory.query.filter_by(public=True).all():
sitemapxml += ' <url>\n'\
' <loc>%s</loc>\n' % url_for('browse_by_category', name=item.name, _external=True) + \
' </url>\n'
Expand Down
4 changes: 2 additions & 2 deletions hasjob/views/kiosk.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def kiosk_manifest():
lines.append('/')

# Type/category pages
for item in JobType.query.all():
for item in JobType.query.filter_by(public=True).all():
lines.append(url_for('browse_by_type', name=item.name))

for item in JobCategory.query.all():
for item in JobCategory.query.filter_by(public=True).all():
lines.append(url_for('browse_by_category', name=item.name))

# Posts
Expand Down

0 comments on commit 2270cb3

Please sign in to comment.