def validate(self, extra_validators=None): success = super(ListingForm, self).validate(extra_validators) if success: if (not self.job_type_ob.nopay_allowed) and self.job_pay_type.data == PAY_TYPE.NOCASH: self.job_pay_type.errors.append(u"“%s” cannot pay nothing" % self.job_type_ob.title) 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: if self.job_pay_cash_max.data == 10000000: self.job_pay_cash_max.errors.append(u"Please select a range") success = False else: self.job_pay_cash_min.errors.append(u"Please specify a minimum non-zero pay") success = False else: if self.job_pay_cash_max.data == 10000000: if self.job_pay_currency.data == 'INR': figure = u'1 crore' else: figure = u'10 million' self.job_pay_cash_max.errors.append( u"You’ve selected an upper limit of {figure}. That can’t be right".format(figure=figure)) success = False elif (self.job_pay_type.data == PAY_TYPE.RECURRING and self.job_pay_currency.data == 'INR' and self.job_pay_cash_min.data < 60000): self.job_pay_cash_min.errors.append( u"That’s rather low. Did you specify monthly pay instead of annual pay? Multiply by 12") success = False elif self.job_pay_cash_max.data > self.job_pay_cash_min.data * 4: self.job_pay_cash_max.errors.append(u"Please select a narrower range, with maximum within 4× minimum") success = False if self.job_pay_equity.data: if self.job_pay_equity_min.data == 0: if self.job_pay_equity_max.data == 100: self.job_pay_equity_max.errors.append(u"Please select a range") success = False else: if self.job_pay_equity_min.data <= Decimal('1.0'): multiplier = 10 elif self.job_pay_equity_min.data <= Decimal('2.0'): multiplier = 8 elif self.job_pay_equity_min.data <= Decimal('3.0'): multiplier = 6 else: multiplier = 4 if self.job_pay_equity_max.data > self.job_pay_equity_min.data * multiplier: self.job_pay_equity_max.errors.append( u"Please select a narrower range, with maximum within %d× minimum" % multiplier) success = False return success
def validate(self): success = super(ListingForm, self).validate(send_signals=False) if success: if ( not self.job_type_ob.nopay_allowed ) and self.job_pay_type.data == PAY_TYPE.NOCASH: self.job_pay_type.errors.append( _("“%s” cannot pay nothing") % self.job_type_ob.title ) success = False domain_name = get_email_domain(self.poster_email.data) domain = Domain.get(domain_name) if domain and domain.is_banned: self.poster_email.errors.append( _("%s is banned from posting jobs on Hasjob") % domain_name ) success = False elif (not self.job_type_ob.webmail_allowed) and is_public_email_domain( domain_name, default=False ): self.poster_email.errors.append( _( "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: if self.job_pay_cash_max.data == 10000000: self.job_pay_cash_max.errors.append(_("Please select a range")) success = False else: self.job_pay_cash_min.errors.append( _("Please specify a minimum non-zero pay") ) success = False else: if self.job_pay_cash_max.data == 10000000: if self.job_pay_currency.data == 'INR': figure = _("1 crore") else: figure = _("10 million") self.job_pay_cash_max.errors.append( _( "You’ve selected an upper limit of {figure}. That can’t be right" ).format(figure=figure) ) success = False elif ( self.job_pay_type.data == PAY_TYPE.RECURRING and self.job_pay_currency.data == 'INR' and self.job_pay_cash_min.data < 60000 ): self.job_pay_cash_min.errors.append( _( "That’s rather low. Did you specify monthly pay instead of annual pay? Multiply by 12" ) ) success = False elif self.job_pay_cash_max.data > self.job_pay_cash_min.data * 4: self.job_pay_cash_max.errors.append( _( "Please select a narrower range, with maximum within 4× minimum" ) ) success = False if self.job_pay_equity.data: if self.job_pay_equity_min.data == 0: if self.job_pay_equity_max.data == 100: self.job_pay_equity_max.errors.append( _("Please select a range") ) success = False else: if self.job_pay_equity_min.data <= Decimal('1.0'): multiplier = 10 elif self.job_pay_equity_min.data <= Decimal('2.0'): multiplier = 8 elif self.job_pay_equity_min.data <= Decimal('3.0'): multiplier = 6 else: multiplier = 4 if ( self.job_pay_equity_max.data > self.job_pay_equity_min.data * multiplier ): self.job_pay_equity_max.errors.append( _( "Please select a narrower range, with maximum within %d× minimum" ) % multiplier ) success = False self.send_signals() return success
def editjob(hashid, key, domain=None, form=None, validated=False, newpost=None): if form is None: form = forms.ListingForm(request.form) form.job_type.choices = JobType.choices(g.board) form.job_category.choices = JobCategory.choices(g.board) if g.board and not g.board.require_pay: form.job_pay_type.choices = [(-1, u'Confidential')] + PAY_TYPE.items() post = None no_email = False if not newpost: post = JobPost.query.filter_by(hashid=hashid).first_or_404() if not ((key is None and g.user is not None and post.admin_is(g.user)) or (key == post.edit_key)): abort(403) # Once this post is published, require editing at /domain/<hashid>/edit if not key and post.status not in POSTSTATUS.UNPUBLISHED and post.email_domain != domain: return redirect(post.url_for('edit'), code=301) # Don't allow editing jobs that aren't on this board as that may be a loophole when # the board allows no pay (except in the 'www' root board, where editing is always allowed) with db.session.no_autoflush: if g.board and g.board.not_root and post.link_to_board(g.board) is None and request.method == 'GET': blink = post.postboards.first() if blink: return redirect(post.url_for('edit', subdomain=blink.board.name, _external=True)) else: return redirect(post.url_for('edit', subdomain=None, _external=True)) # Don't allow email address to be changed once it's confirmed if post.status in POSTSTATUS.POSTPENDING: no_email = True if request.method == 'POST' and post and post.status in POSTSTATUS.POSTPENDING: # del form.poster_name # Deprecated 2013-11-20 form.poster_email.data = post.email if request.method == 'POST' and (validated or form.validate()): form_description = bleach.linkify(bleach.clean(form.job_description.data, tags=ALLOWED_TAGS)) form_perks = bleach.linkify(bleach.clean(form.job_perks_description.data, tags=ALLOWED_TAGS)) if form.job_perks.data else '' form_how_to_apply = form.job_how_to_apply.data form_email_domain = get_email_domain(form.poster_email.data) form_words = get_word_bag(u' '.join((form_description, form_perks, form_how_to_apply))) similar = False with db.session.no_autoflush: for oldpost in JobPost.query.filter(db.or_( db.and_( JobPost.email_domain == form_email_domain, JobPost.status.in_(POSTSTATUS.POSTPENDING)), JobPost.status == POSTSTATUS.SPAM)).filter( JobPost.datetime > datetime.utcnow() - agelimit).all(): if not post or (oldpost.id != post.id): if oldpost.words: s = SequenceMatcher(None, form_words, oldpost.words) if s.ratio() > 0.6: similar = True break if similar: flash("This post is very similar to an earlier post. You may not repost the same job " "in less than %d days." % agelimit.days, category='interactive') else: if newpost: post = JobPost(**newpost) db.session.add(post) if g.board: post.add_to(g.board) if g.board.not_root: post.add_to('www') post.headline = form.job_headline.data post.headlineb = form.job_headlineb.data post.type_id = form.job_type.data post.category_id = form.job_category.data post.location = form.job_location.data post.relocation_assist = form.job_relocation_assist.data post.description = form_description post.perks = form_perks post.how_to_apply = form_how_to_apply post.company_name = form.company_name.data post.company_url = form.company_url.data post.hr_contact = form.hr_contact.data post.twitter = form.twitter.data post.pay_type = form.job_pay_type.data if post.pay_type == -1: post.pay_type = None if post.pay_type is not None and post.pay_type != PAY_TYPE.NOCASH: post.pay_currency = form.job_pay_currency.data post.pay_cash_min = form.job_pay_cash_min.data post.pay_cash_max = form.job_pay_cash_max.data else: post.pay_currency = None post.pay_cash_min = None post.pay_cash_max = None if form.job_pay_equity.data: post.pay_equity_min = form.job_pay_equity_min.data post.pay_equity_max = form.job_pay_equity_max.data else: post.pay_equity_min = None post.pay_equity_max = None post.admins = form.collaborators.data # Allow name and email to be set only on non-confirmed posts if not no_email: # post.fullname = form.poster_name.data # Deprecated 2013-11-20 if post.email != form.poster_email.data: # Change the email_verify_key if the email changes post.email_verify_key = random_long_key() post.email = form.poster_email.data post.email_domain = form_email_domain post.md5sum = md5sum(post.email) with db.session.no_autoflush: # This is dependent on the domain's DNS validity already being confirmed # by the form's email validator post.domain = Domain.get(post.email_domain, create=True) # To protect from gaming, don't allow words to be removed in edited posts once the post # has been confirmed. Just add the new words. if post.status in POSTSTATUS.POSTPENDING: prev_words = post.words or u'' else: prev_words = u'' post.words = get_word_bag(u' '.join((prev_words, form_description, form_perks, form_how_to_apply))) post.language, post.language_confidence = identify_language(post) if post.status == POSTSTATUS.MODERATED: post.status = POSTSTATUS.CONFIRMED if request.files['company_logo']: # The form's validator saved the processed logo in g.company_logo. thumbnail = g.company_logo logofilename = uploaded_logos.save(thumbnail, name='%s.' % post.hashid) post.company_logo = logofilename else: if form.company_logo_remove.data: post.company_logo = None db.session.commit() tag_jobpost.delay(post.id) # Keywords tag_locations.delay(post.id) # Locations post.uncache_viewcounts('pay_label') session.pop('userkeys', None) # Remove legacy userkeys dict session.permanent = True return redirect(post.url_for(), code=303) elif request.method == 'POST': flash("Please review the indicated issues", category='interactive') elif request.method == 'GET': form.populate_from(post) return render_template('postjob.html', form=form, no_email=no_email)
def editjob(hashid, key, form=None, post=None, validated=False): if form is None: form = forms.ListingForm(request.form) form.job_type.choices = JobType.choices(g.board) form.job_category.choices = JobCategory.choices(g.board) if g.board and not g.board.require_pay: form.job_pay_type.choices = [(-1, u'Confidential')] + PAY_TYPE.items() if post is None: post = JobPost.query.filter_by(hashid=hashid).first_or_404() if not ((key is None and g.user is not None and post.admin_is(g.user)) or (key == post.edit_key)): abort(403) # Don't allow editing jobs that aren't on this board as that may be a loophole when # the board allows no pay. if g.board and post.link_to_board(g.board) is None and request.method == 'GET': blink = post.postboards.first() if blink: return redirect(url_for('editjob', hashid=post.hashid, subdomain=blink.board.name, _external=True)) else: return redirect(url_for('editjob', hashid=post.hashid, subdomain=None, _external=True)) # Don't allow email address to be changed once it's confirmed if post.status in POSTSTATUS.POSTPENDING: no_email = True else: no_email = False if request.method == 'POST' and post.status in POSTSTATUS.POSTPENDING: # del form.poster_name # Deprecated 2013-11-20 form.poster_email.data = post.email if request.method == 'POST' and (validated or form.validate()): form_description = bleach.linkify(bleach.clean(form.job_description.data, tags=ALLOWED_TAGS)) form_perks = bleach.linkify(bleach.clean(form.job_perks_description.data, tags=ALLOWED_TAGS)) if form.job_perks.data else '' form_how_to_apply = form.job_how_to_apply.data form_email_domain = get_email_domain(form.poster_email.data) form_words = get_word_bag(u' '.join((form_description, form_perks, form_how_to_apply))) similar = False for oldpost in JobPost.query.filter(db.or_( db.and_( JobPost.email_domain == form_email_domain, JobPost.status.in_(POSTSTATUS.POSTPENDING)), JobPost.status == POSTSTATUS.SPAM)).filter( JobPost.datetime > datetime.utcnow() - agelimit).all(): if oldpost.id != post.id: if oldpost.words: s = SequenceMatcher(None, form_words, oldpost.words) if s.ratio() > 0.6: similar = True break if similar: flash("This listing is very similar to an earlier listing. You may not relist the same job " "in less than %d days." % agelimit.days, category='interactive') else: post.headline = form.job_headline.data post.type_id = form.job_type.data post.category_id = form.job_category.data post.location = form.job_location.data post.relocation_assist = form.job_relocation_assist.data post.description = form_description post.perks = form_perks post.how_to_apply = form_how_to_apply post.company_name = form.company_name.data post.company_url = form.company_url.data post.hr_contact = form.hr_contact.data post.pay_type = form.job_pay_type.data if post.pay_type == -1: post.pay_type = None if post.pay_type is not None and post.pay_type != PAY_TYPE.NOCASH: post.pay_currency = form.job_pay_currency.data post.pay_cash_min = form.job_pay_cash_min.data post.pay_cash_max = form.job_pay_cash_max.data else: post.pay_currency = None post.pay_cash_min = None post.pay_cash_max = None if form.job_pay_equity.data: post.pay_equity_min = form.job_pay_equity_min.data post.pay_equity_max = form.job_pay_equity_max.data else: post.pay_equity_min = None post.pay_equity_max = None post.admins = form.collaborators.data # Allow name and email to be set only on non-confirmed posts if not no_email: # post.fullname = form.poster_name.data # Deprecated 2013-11-20 post.email = form.poster_email.data post.email_domain = form_email_domain post.md5sum = md5sum(post.email) # To protect from gaming, don't allow words to be removed in edited listings once the post # has been confirmed. Just add the new words. if post.status in POSTSTATUS.POSTPENDING: prev_words = post.words or u'' else: prev_words = u'' post.words = get_word_bag(u' '.join((prev_words, form_description, form_perks, form_how_to_apply))) post.language = identify_language(post) if post.status == POSTSTATUS.MODERATED: post.status = POSTSTATUS.CONFIRMED if request.files['company_logo']: # The form's validator saved the processed logo in g.company_logo. thumbnail = g.company_logo logofilename = uploaded_logos.save(thumbnail, name='%s.' % post.hashid) post.company_logo = logofilename else: if form.company_logo_remove.data: post.company_logo = None db.session.commit() tag_locations.delay(post.id) userkeys = session.get('userkeys', []) userkeys.append(post.edit_key) session['userkeys'] = userkeys 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') elif request.method == 'GET': # Populate form from model form.job_headline.data = post.headline form.job_type.data = post.type_id form.job_category.data = post.category_id form.job_location.data = post.location form.job_relocation_assist.data = post.relocation_assist form.job_description.data = post.description form.job_perks.data = True if post.perks else False form.job_perks_description.data = post.perks form.job_how_to_apply.data = post.how_to_apply form.company_name.data = post.company_name form.company_url.data = post.company_url # form.poster_name.data = post.fullname # Deprecated 2013-11-20 form.poster_email.data = post.email form.hr_contact.data = int(post.hr_contact or False) form.collaborators.data = post.admins form.job_pay_type.data = post.pay_type if post.pay_type is None: # This kludge required because WTForms doesn't know how to handle None in forms form.job_pay_type.data = -1 form.job_pay_currency.data = post.pay_currency form.job_pay_cash_min.data = post.pay_cash_min form.job_pay_cash_max.data = post.pay_cash_max form.job_pay_equity.data = bool(post.pay_equity_min and post.pay_equity_max) form.job_pay_equity_min.data = post.pay_equity_min form.job_pay_equity_max.data = post.pay_equity_max return render_template('postjob.html', form=form, no_email=no_email)
def editjob(hashid, key, form=None, post=None, validated=False): if form is None: form = forms.ListingForm(request.form) form.job_type.choices = [(ob.id, ob.title) for ob in JobType.query.filter_by(public=True).order_by('seq')] form.job_category.choices = [(ob.id, ob.title) for ob in JobCategory.query.filter_by(public=True).order_by('seq')] if post is None: post = JobPost.query.filter_by(hashid=hashid).first_or_404() if not ((key is None and g.user is not None and post.admin_is(g.user)) or (key == post.edit_key)): abort(403) # Don't allow email address to be changed once its confirmed if post.status in POSTSTATUS.POSTPENDING: no_email = True else: no_email = False if request.method == 'POST' and post.status in POSTSTATUS.POSTPENDING: # del form.poster_name # Deprecated 2013-11-20 form.poster_email.data = post.email if request.method == 'POST' and (validated or form.validate()): form_description = bleach.linkify(bleach.clean(form.job_description.data, tags=ALLOWED_TAGS)) form_perks = bleach.linkify(bleach.clean(form.job_perks_description.data, tags=ALLOWED_TAGS)) if form.job_perks.data else '' form_how_to_apply = form.job_how_to_apply.data form_email_domain = get_email_domain(form.poster_email.data) form_words = get_word_bag(u' '.join((form_description, form_perks, form_how_to_apply))) similar = False for oldpost in JobPost.query.filter(db.or_( db.and_( JobPost.email_domain == form_email_domain, JobPost.status.in_(POSTSTATUS.POSTPENDING)), JobPost.status == POSTSTATUS.SPAM)).filter( JobPost.datetime > datetime.utcnow() - agelimit).all(): if oldpost.id != post.id: if oldpost.words: s = SequenceMatcher(None, form_words, oldpost.words) if s.ratio() > 0.6: similar = True break if similar: flash("This listing is very similar to an earlier listing. You may not relist the same job " "in less than %d days." % agelimit.days, category='interactive') else: post.headline = form.job_headline.data post.type_id = form.job_type.data post.category_id = form.job_category.data post.location = form.job_location.data post.relocation_assist = form.job_relocation_assist.data post.description = form_description post.perks = form_perks post.how_to_apply = form_how_to_apply post.company_name = form.company_name.data post.company_url = form.company_url.data post.hr_contact = form.hr_contact.data post.pay_type = form.job_pay_type.data if post.pay_type != PAY_TYPE.NOCASH: post.pay_currency = form.job_pay_currency.data post.pay_cash_min = form.job_pay_cash_min.data # TODO: Sanitize post.pay_cash_max = form.job_pay_cash_max.data # TODO: Sanitize else: post.pay_currency = None post.pay_cash_min = None post.pay_cash_max = None if form.job_pay_equity.data: post.pay_equity_min = form.job_pay_equity_min.data # TODO: Sanitize post.pay_equity_max = form.job_pay_equity_max.data # TODO: Sanitize else: post.pay_equity_min = None post.pay_equity_max = None if form.collaborators.data: post.admins = [] userdata = lastuser.getuser_by_userids(form.collaborators.data) for userinfo in userdata: if userinfo['type'] == 'user': user = User.query.filter_by(userid=userinfo['buid']).first() if not user: # New user on Hasjob. Don't set username right now. It's not relevant # until first login and we don't want to deal with conflicts user = User(userid=userinfo['buid'], fullname=userinfo['title']) db.session.add(user) post.admins.append(user) # Allow name and email to be set only on non-confirmed posts if not no_email: # post.fullname = form.poster_name.data # Deprecated 2013-11-20 post.email = form.poster_email.data post.email_domain = form_email_domain post.md5sum = md5sum(post.email) # To protect from gaming, don't allow words to be removed in edited listings once the post # has been confirmed. Just add the new words. if post.status in POSTSTATUS.POSTPENDING: prev_words = post.words or u'' else: prev_words = u'' post.words = get_word_bag(u' '.join((prev_words, form_description, form_perks, form_how_to_apply))) post.language = identify_language(post) if post.status == POSTSTATUS.MODERATED: post.status = POSTSTATUS.CONFIRMED if request.files['company_logo']: # The form's validator saved the processed logo in g.company_logo. thumbnail = g.company_logo logofilename = uploaded_logos.save(thumbnail, name='%s.' % post.hashid) post.company_logo = logofilename else: if form.company_logo_remove.data: post.company_logo = None db.session.commit() tag_locations.delay(post.id) userkeys = session.get('userkeys', []) userkeys.append(post.edit_key) session['userkeys'] = userkeys 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') elif request.method == 'GET': # Populate form from model form.job_headline.data = post.headline form.job_type.data = post.type_id form.job_category.data = post.category_id form.job_location.data = post.location form.job_relocation_assist.data = post.relocation_assist form.job_description.data = post.description form.job_perks.data = True if post.perks else False form.job_perks_description.data = post.perks form.job_how_to_apply.data = post.how_to_apply form.company_name.data = post.company_name form.company_url.data = post.company_url # form.poster_name.data = post.fullname # Deprecated 2013-11-20 form.poster_email.data = post.email form.hr_contact.data = int(post.hr_contact or False) form.collaborators.data = [u.userid for u in post.admins] form.job_pay_type.data = post.pay_type form.job_pay_currency.data = post.pay_currency form.job_pay_cash_min.data = post.pay_cash_min form.job_pay_cash_max.data = post.pay_cash_max form.job_pay_equity.data = bool(post.pay_equity_min and post.pay_equity_max) form.job_pay_equity_min.data = post.pay_equity_min form.job_pay_equity_max.data = post.pay_equity_max return render_template('postjob.html', form=form, no_email=no_email, getuser_autocomplete=lastuser.endpoint_url(lastuser.getuser_autocomplete_endpoint), getuser_userids=lastuser.endpoint_url(lastuser.getuser_userids_endpoint))
def editjob(hashid, key, domain=None, form=None, validated=False, newpost=None): if form is None: form = forms.ListingForm(request.form) form.job_type.choices = JobType.choices(g.board) form.job_category.choices = JobCategory.choices(g.board) if g.board and not g.board.require_pay: form.job_pay_type.choices = [(-1, u'Confidential') ] + PAY_TYPE.items() post = None no_email = False if not newpost: post = JobPost.query.filter_by(hashid=hashid).first_or_404() if not ((key is None and g.user is not None and post.admin_is(g.user)) or (key == post.edit_key)): abort(403) # Once this post is published, require editing at /domain/<hashid>/edit if not key and post.status not in POSTSTATUS.UNPUBLISHED and post.email_domain != domain: return redirect(post.url_for('edit'), code=301) # Don't allow editing jobs that aren't on this board as that may be a loophole when # the board allows no pay (except in the 'www' root board, where editing is always allowed) with db.session.no_autoflush: if g.board and g.board.not_root and post.link_to_board( g.board) is None and request.method == 'GET': blink = post.postboards.first() if blink: return redirect( post.url_for('edit', subdomain=blink.board.name, _external=True)) else: return redirect( post.url_for('edit', subdomain=None, _external=True)) # Don't allow email address to be changed once it's confirmed if post.status in POSTSTATUS.POSTPENDING: no_email = True if request.method == 'POST' and post and post.status in POSTSTATUS.POSTPENDING: # del form.poster_name # Deprecated 2013-11-20 form.poster_email.data = post.email if request.method == 'POST' and (validated or form.validate()): form_description = bleach.linkify( bleach.clean(form.job_description.data, tags=ALLOWED_TAGS)) form_perks = bleach.linkify( bleach.clean(form.job_perks_description.data, tags=ALLOWED_TAGS)) if form.job_perks.data else '' form_how_to_apply = form.job_how_to_apply.data form_email_domain = get_email_domain(form.poster_email.data) form_words = get_word_bag(u' '.join( (form_description, form_perks, form_how_to_apply))) similar = False with db.session.no_autoflush: for oldpost in JobPost.query.filter( db.or_( db.and_(JobPost.email_domain == form_email_domain, JobPost.status.in_(POSTSTATUS.POSTPENDING)), JobPost.status == POSTSTATUS.SPAM)).filter( JobPost.datetime > datetime.utcnow() - agelimit).all(): if not post or (oldpost.id != post.id): if oldpost.words: s = SequenceMatcher(None, form_words, oldpost.words) if s.ratio() > 0.6: similar = True break if similar: flash( "This post is very similar to an earlier post. You may not repost the same job " "in less than %d days." % agelimit.days, category='interactive') else: if newpost: post = JobPost(**newpost) db.session.add(post) if g.board: post.add_to(g.board) if g.board.not_root: post.add_to('www') post.headline = form.job_headline.data post.headlineb = form.job_headlineb.data post.type_id = form.job_type.data post.category_id = form.job_category.data post.location = form.job_location.data post.relocation_assist = form.job_relocation_assist.data post.description = form_description post.perks = form_perks post.how_to_apply = form_how_to_apply post.company_name = form.company_name.data post.company_url = form.company_url.data post.hr_contact = form.hr_contact.data post.twitter = form.twitter.data post.pay_type = form.job_pay_type.data if post.pay_type == -1: post.pay_type = None if post.pay_type is not None and post.pay_type != PAY_TYPE.NOCASH: post.pay_currency = form.job_pay_currency.data post.pay_cash_min = form.job_pay_cash_min.data post.pay_cash_max = form.job_pay_cash_max.data else: post.pay_currency = None post.pay_cash_min = None post.pay_cash_max = None if form.job_pay_equity.data: post.pay_equity_min = form.job_pay_equity_min.data post.pay_equity_max = form.job_pay_equity_max.data else: post.pay_equity_min = None post.pay_equity_max = None post.admins = form.collaborators.data # Allow name and email to be set only on non-confirmed posts if not no_email: # post.fullname = form.poster_name.data # Deprecated 2013-11-20 post.email = form.poster_email.data post.email_domain = form_email_domain post.md5sum = md5sum(post.email) with db.session.no_autoflush: # This is dependent on the domain's DNS validity already being confirmed # by the form's email validator post.domain = Domain.get(post.email_domain, create=True) # To protect from gaming, don't allow words to be removed in edited posts once the post # has been confirmed. Just add the new words. if post.status in POSTSTATUS.POSTPENDING: prev_words = post.words or u'' else: prev_words = u'' post.words = get_word_bag(u' '.join( (prev_words, form_description, form_perks, form_how_to_apply))) post.language, post.language_confidence = identify_language(post) if post.status == POSTSTATUS.MODERATED: post.status = POSTSTATUS.CONFIRMED if request.files['company_logo']: # The form's validator saved the processed logo in g.company_logo. thumbnail = g.company_logo logofilename = uploaded_logos.save(thumbnail, name='%s.' % post.hashid) post.company_logo = logofilename else: if form.company_logo_remove.data: post.company_logo = None db.session.commit() tag_jobpost.delay(post.id) # Keywords tag_locations.delay(post.id) # Locations post.uncache_viewcounts('pay_label') session.pop('userkeys', None) # Remove legacy userkeys dict session.permanent = True return redirect(post.url_for(), code=303) elif request.method == 'POST': flash("Please review the indicated issues", category='interactive') elif request.method == 'GET': # Populate form from model form.job_headline.data = post.headline form.job_headlineb.data = post.headlineb form.job_type.data = post.type_id form.job_category.data = post.category_id form.job_location.data = post.location form.job_relocation_assist.data = post.relocation_assist form.job_description.data = post.description form.job_perks.data = True if post.perks else False form.job_perks_description.data = post.perks form.job_how_to_apply.data = post.how_to_apply form.company_name.data = post.company_name form.company_url.data = post.company_url # form.poster_name.data = post.fullname # Deprecated 2013-11-20 form.poster_email.data = post.email form.twitter.data = post.twitter form.hr_contact.data = int(post.hr_contact or False) form.collaborators.data = post.admins form.job_pay_type.data = post.pay_type if post.pay_type is None: # This kludge required because WTForms doesn't know how to handle None in forms form.job_pay_type.data = -1 form.job_pay_currency.data = post.pay_currency form.job_pay_cash_min.data = post.pay_cash_min form.job_pay_cash_max.data = post.pay_cash_max form.job_pay_equity.data = bool(post.pay_equity_min and post.pay_equity_max) form.job_pay_equity_min.data = post.pay_equity_min form.job_pay_equity_max.data = post.pay_equity_max return render_template('postjob.html', form=form, no_email=no_email)
def validate(self): success = super(ListingForm, self).validate(send_signals=False) if success: if (not self.job_type_ob.nopay_allowed) and self.job_pay_type.data == PAY_TYPE.NOCASH: self.job_pay_type.errors.append(_(u"“%%s” cannot pay nothing") % self.job_type_ob.title) success = False domain_name = get_email_domain(self.poster_email.data) domain = Domain.get(domain_name) if domain and domain.is_banned: self.poster_email.errors.append(_(u"%%s is banned from posting jobs on Hasjob") % domain_name) success = False elif (not self.job_type_ob.webmail_allowed) and domain_name 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: if self.job_pay_cash_max.data == 10000000: self.job_pay_cash_max.errors.append(_(u"Please select a range")) success = False else: self.job_pay_cash_min.errors.append(_(u"Please specify a minimum non-zero pay")) success = False else: if self.job_pay_cash_max.data == 10000000: if self.job_pay_currency.data == 'INR': figure = _(u"1 crore") else: figure = _(u"10 million") self.job_pay_cash_max.errors.append( _(u"You’ve selected an upper limit of {figure}. That can’t be right").format(figure=figure)) success = False elif (self.job_pay_type.data == PAY_TYPE.RECURRING and self.job_pay_currency.data == 'INR' and self.job_pay_cash_min.data < 60000): self.job_pay_cash_min.errors.append( _(u"That’s rather low. Did you specify monthly pay instead of annual pay? Multiply by 12")) success = False elif self.job_pay_cash_max.data > self.job_pay_cash_min.data * 4: self.job_pay_cash_max.errors.append(_(u"Please select a narrower range, with maximum within 4× minimum")) success = False if self.job_pay_equity.data: if self.job_pay_equity_min.data == 0: if self.job_pay_equity_max.data == 100: self.job_pay_equity_max.errors.append(_(u"Please select a range")) success = False else: if self.job_pay_equity_min.data <= Decimal('1.0'): multiplier = 10 elif self.job_pay_equity_min.data <= Decimal('2.0'): multiplier = 8 elif self.job_pay_equity_min.data <= Decimal('3.0'): multiplier = 6 else: multiplier = 4 if self.job_pay_equity_max.data > self.job_pay_equity_min.data * multiplier: self.job_pay_equity_max.errors.append( _(u"Please select a narrower range, with maximum within %%d× minimum") % multiplier) success = False self.send_signals() return success
def validate(self, extra_validators=None): success = super(ListingForm, self).validate(extra_validators) if success: if (not self.job_type_ob.nopay_allowed ) and self.job_pay_type.data == PAY_TYPE.NOCASH: self.job_pay_type.errors.append(u"“%s” cannot pay nothing" % self.job_type_ob.title) 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: if self.job_pay_cash_max.data == 10000000: self.job_pay_cash_max.errors.append( u"Please select a range") success = False else: self.job_pay_cash_min.errors.append( u"Please specify a minimum non-zero pay") success = False else: if self.job_pay_cash_max.data == 10000000: if self.job_pay_currency.data == 'INR': figure = u'1 crore' else: figure = u'10 million' self.job_pay_cash_max.errors.append( u"You’ve selected an upper limit of {figure}. That can’t be right" .format(figure=figure)) success = False elif (self.job_pay_type.data == PAY_TYPE.RECURRING and self.job_pay_currency.data == 'INR' and self.job_pay_cash_min.data < 60000): self.job_pay_cash_min.errors.append( u"That’s rather low. Did you specify monthly pay instead of annual pay? Multiply by 12" ) success = False elif self.job_pay_cash_max.data > self.job_pay_cash_min.data * 4: self.job_pay_cash_max.errors.append( u"Please select a narrower range, with maximum within 4× minimum" ) success = False if self.job_pay_equity.data: if self.job_pay_equity_min.data == 0: if self.job_pay_equity_max.data == 100: self.job_pay_equity_max.errors.append( u"Please select a range") success = False else: if self.job_pay_equity_min.data <= Decimal('1.0'): multiplier = 10 elif self.job_pay_equity_min.data <= Decimal('2.0'): multiplier = 8 elif self.job_pay_equity_min.data <= Decimal('3.0'): multiplier = 6 else: multiplier = 4 if self.job_pay_equity_max.data > self.job_pay_equity_min.data * multiplier: self.job_pay_equity_max.errors.append( u"Please select a narrower range, with maximum within %d× minimum" % multiplier) success = False return success