def confirm(hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() form = forms.ConfirmForm() if post.status in [POSTSTATUS.REJECTED, POSTSTATUS.SPAM]: abort(410) elif post.status == POSTSTATUS.DRAFT: if post.edit_key not in session.get('userkeys', []): abort(403) else: # Any other status: no confirmation required (via this handler) return redirect(url_for('jobdetail', hashid=post.hashid), code=302) if 'form.id' in request.form and form.validate_on_submit(): # User has accepted terms of service. Now send email and/or wait for payment if not post.email_sent: msg = Message(subject="Confirmation of your job listing at Hasjob", recipients=[post.email]) msg.body = render_template("confirm_email.md", post=post) msg.html = markdown(msg.body) mail.send(msg) post.email_sent = True post.status = POSTSTATUS.PENDING db.session.commit() session.get('userkeys', []).remove(post.edit_key) session.modified = True # Since it won't detect changes to lists session.permanent = True return render_template('mailsent.html', post=post) return render_template('confirm.html', post=post, form=form)
def confirm(domain, hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() form = forms.ConfirmForm() if post.status in POSTSTATUS.GONE: abort(410) elif post.status in POSTSTATUS.UNPUBLISHED and not post.admin_is(g.user): abort(403) elif post.status not in POSTSTATUS.UNPUBLISHED: # Any other status: no confirmation required (via this handler) return redirect(post.url_for(), code=302) # We get here if it's (a) POSTSTATUS.UNPUBLISHED and (b) the user is confirmed authorised if 'form.id' in request.form and form.validate_on_submit(): # User has accepted terms of service. Now send email and/or wait for payment # Also (re-)set the verify key, just in case they changed their email # address and are re-verifying post.email_verify_key = random_long_key() msg = Message(subject="Confirmation of your job post at Hasjob", recipients=[post.email]) msg.body = render_template("confirm_email.md", post=post) msg.html = markdown(msg.body) mail.send(msg) post.email_sent = True post.status = POSTSTATUS.PENDING db.session.commit() return render_template('mailsent.html', post=post) return render_template('confirm.html', post=post, form=form)
def confirm(hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() form = forms.ConfirmForm() if post.status in [POSTSTATUS.REJECTED, POSTSTATUS.SPAM]: abort(410) elif post.status in [POSTSTATUS.DRAFT, POSTSTATUS.PENDING]: if not (post.edit_key in session.get('userkeys', []) or post.admin_is(g.user)): abort(403) else: # Any other status: no confirmation required (via this handler) return redirect(url_for('jobdetail', hashid=post.hashid), code=302) if 'form.id' in request.form and form.validate_on_submit(): # User has accepted terms of service. Now send email and/or wait for payment # Also (re-)set the verify key, just in case they changed their email # address and are re-verifying post.email_verify_key = random_long_key() msg = Message(subject="Confirmation of your job listing at Hasjob", recipients=[post.email]) msg.body = render_template("confirm_email.md", post=post) msg.html = markdown(msg.body) mail.send(msg) post.email_sent = True post.status = POSTSTATUS.PENDING db.session.commit() try: session.get('userkeys', []).remove(post.edit_key) session.modified = True # Since it won't detect changes to lists except ValueError: pass return render_template('mailsent.html', post=post) return render_template('confirm.html', post=post, form=form)
def confirm(hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() form = forms.ConfirmForm() if post.status == POSTSTATUS.REJECTED: abort(410) elif post.status == POSTSTATUS.DRAFT: if post.edit_key not in session.get('userkeys', []): abort(403) else: # Any other status: no confirmation required (via this handler) return redirect(url_for('jobdetail', hashid=post.hashid), code=302) if 'form.id' in request.form and form.validate_on_submit(): # User has accepted terms of service. Now send email and/or wait for payment if not post.email_sent: msg = Message( subject= "Confirmation of your job listing at the HasGeek Job Board", recipients=[post.email]) msg.body = render_template("confirm_email.md", post=post) msg.html = markdown(msg.body) mail.send(msg) post.email_sent = True post.status = POSTSTATUS.PENDING db.session.commit() session.get('userkeys', []).remove(post.edit_key) session.modified = True # Since it won't detect changes to lists session.permanent = True return render_template('mailsent.html', post=post) return render_template('confirm.html', post=post, form=form)
def confirm(domain, hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() form = forms.ConfirmForm() if post.status in POSTSTATUS.GONE: abort(410) elif post.status in POSTSTATUS.UNPUBLISHED and not post.admin_is(g.user): abort(403) elif post.status not in POSTSTATUS.UNPUBLISHED: # Any other status: no confirmation required (via this handler) return redirect(post.url_for(), code=302) # We get here if it's (a) POSTSTATUS.UNPUBLISHED and (b) the user is confirmed authorised if 'form.id' in request.form and form.validate_on_submit(): # User has accepted terms of service. Now send email and/or wait for payment msg = Message(subject="Confirmation of your job post at Hasjob", recipients=[post.email]) msg.html = email_transform(render_template('confirm_email.html', post=post), base_url=request.url_root) msg.body = html2text(msg.html) mail.send(msg) post.email_sent = True post.status = POSTSTATUS.PENDING db.session.commit() return render_template('mailsent.html', post=post) return render_template('confirm.html', post=post, form=form)
def rejectjob(hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() if post.status in [POSTSTATUS.DRAFT, POSTSTATUS.PENDING]: if post.edit_key not in session.get('userkeys', []): abort(403) if post.status in [POSTSTATUS.REJECTED, POSTSTATUS.WITHDRAWN]: abort(410) rejectform = forms.RejectForm() if rejectform.validate_on_submit(): post.closed_datetime = datetime.utcnow() post.review_comments = rejectform.reason.data post.review_datetime = datetime.utcnow() post.status = POSTSTATUS.REJECTED post.reviewer = g.user msg = Message( subject="Rejection of your job listing at the HasGeek Job Board", recipients=[post.email]) msg.body = render_template("reject_email.md", post=post) msg.html = markdown(msg.body) mail.send(msg) db.session.commit() if request.is_xhr: return "<p>This job listing has been rejected.</p>" else: flash("This job listing has been rejected", "interactive") elif request.method == 'POST' and request.is_xhr: return render_template('inc/rejectform.html', post=post, rejectform=rejectform, ajaxreg=True) return redirect(url_for('jobdetail', hashid=post.hashid))
def confirm(domain, hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() form = forms.ConfirmForm() if post.status in POSTSTATUS.GONE: abort(410) elif post.status in POSTSTATUS.UNPUBLISHED and not post.admin_is(g.user): abort(403) elif post.status not in POSTSTATUS.UNPUBLISHED: # Any other status: no confirmation required (via this handler) return redirect(post.url_for(), code=302) # We get here if it's (a) POSTSTATUS.UNPUBLISHED and (b) the user is confirmed authorised if 'form.id' in request.form and form.validate_on_submit(): # User has accepted terms of service. Now send email and/or wait for payment msg = Message(subject="Confirmation of your job post at Hasjob", recipients=[post.email]) msg.html = email_transform(render_template('confirm_email.html', post=post), base_url=request.url_root) msg.body = html2text(msg.html) mail.send(msg) post.email_sent = True post.status = POSTSTATUS.PENDING db.session.commit() footer_campaign = Campaign.for_context(CAMPAIGN_POSITION.AFTERPOST, board=g.board, user=g.user, anon_user=g.anon_user, geonameids=g.user_geonameids) return render_template('mailsent.html', footer_campaign=footer_campaign) return render_template('confirm.html', post=post, form=form)
def confirm(domain, hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() form = forms.ConfirmForm() if post.state.GONE: abort(410) elif not post.state.CONFIRMABLE: abort(403) elif not post.state.UNPUBLISHED: # Any other status: no confirmation required (via this handler) return redirect(post.url_for(), code=302) # We get here if it's (a) POST_STATE.UNPUBLISHED and (b) the user is confirmed authorised if 'form.id' in request.form and form.validate_on_submit(): # User has accepted terms of service. Now send email and/or wait for payment msg = Message(subject="Confirm your job post: {headline}".format(headline=post.headline), recipients=[post.email]) msg.html = email_transform(render_template('confirm_email.html.jinja2', post=post), base_url=request.url_root) msg.body = html2text(msg.html) mail.send(msg) post.email_sent = True if post.state.DRAFT: post.mark_pending() db.session.commit() footer_campaign = Campaign.for_context(CAMPAIGN_POSITION.AFTERPOST, board=g.board, user=g.user, anon_user=g.anon_user, geonameids=g.user_geonameids) return render_template('mailsent.html.jinja2', footer_campaign=footer_campaign) return render_template('confirm.html.jinja2', post=post, form=form)
def rejectjob(hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() if post.status in [POSTSTATUS.DRAFT, POSTSTATUS.PENDING]: if post.edit_key not in session.get('userkeys', []): abort(403) if post.status in [POSTSTATUS.REJECTED, POSTSTATUS.WITHDRAWN, POSTSTATUS.SPAM]: abort(410) rejectform = forms.RejectForm() if rejectform.validate_on_submit(): post.closed_datetime = datetime.utcnow() post.review_comments = rejectform.reason.data post.review_datetime = datetime.utcnow() post.reviewer = g.user if request.form.get('submit') == 'spam': flashmsg = "This job listing has been marked as spam." post.status = POSTSTATUS.SPAM else: flashmsg = "This job listing has been rejected." post.status = POSTSTATUS.REJECTED msg = Message(subject="About your job listing on Hasjob", recipients=[post.email]) msg.body = render_template("reject_email.md", post=post) msg.html = markdown(msg.body) mail.send(msg) db.session.commit() if request.is_xhr: return "<p>%s</p>" % flashmsg else: flash(flashmsg, "interactive") elif request.method == 'POST' and request.is_xhr: return render_template('inc/rejectform.html', post=post, rejectform=rejectform, ajaxreg=True) return redirect(url_for('jobdetail', hashid=post.hashid))
def moderatejob(domain, hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() if post.status in [POSTSTATUS.DRAFT, POSTSTATUS.PENDING]: abort(403) if post.status in [POSTSTATUS.REJECTED, POSTSTATUS.WITHDRAWN, POSTSTATUS.SPAM]: abort(410) moderateform = forms.ModerateForm() if moderateform.validate_on_submit(): post.closed_datetime = datetime.utcnow() post.review_comments = moderateform.reason.data post.review_datetime = datetime.utcnow() post.reviewer = g.user flashmsg = "This job post has been moderated." post.status = POSTSTATUS.MODERATED msg = Message(subject="About your job post on Hasjob", recipients=[post.email]) msg.html = email_transform(render_template('moderate_email.html', post=post), base_url=request.url_root) msg.body = html2text(msg.html) mail.send(msg) db.session.commit() if request.is_xhr: return "<p>%s</p>" % flashmsg elif request.method == 'POST' and request.is_xhr: return render_template('inc/moderateform.html', post=post, moderateform=moderateform) return redirect(post.url_for(), code=303)
def moderatejob(domain, hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() if post.status in [POSTSTATUS.DRAFT, POSTSTATUS.PENDING]: abort(403) if post.status in [ POSTSTATUS.REJECTED, POSTSTATUS.WITHDRAWN, POSTSTATUS.SPAM ]: abort(410) moderateform = forms.ModerateForm() if moderateform.validate_on_submit(): post.closed_datetime = datetime.utcnow() post.review_comments = moderateform.reason.data post.review_datetime = datetime.utcnow() post.reviewer = g.user flashmsg = "This job post has been moderated." post.status = POSTSTATUS.MODERATED msg = Message(subject="About your job post on Hasjob", recipients=[post.email]) msg.body = render_template("moderate_email.md", post=post) msg.html = markdown(msg.body) mail.send(msg) db.session.commit() if request.is_xhr: return "<p>%s</p>" % flashmsg elif request.method == 'POST' and request.is_xhr: return render_template('inc/moderateform.html', post=post, moderateform=moderateform) return redirect(post.url_for(), code=303)
def applyjob(hashid): """ Apply to a job """ post = JobPost.query.filter_by(hashid=hashid).first_or_404() job_application = JobApplication.query.filter_by(user=g.user, jobpost=post).first() if job_application: flashmsg = "You have already applied to this job. You may not apply again" if request.is_xhr: return u'<p><strong>{}</strong></p>'.format(flashmsg) else: flash(flashmsg, 'interactive') return redirect(url_for('jobdetail', hashid=post.hashid), 303) else: applyform = forms.ApplicationForm() if applyform.validate_on_submit(): if g.user.blocked: flashmsg = "Your account has been blocked from applying to jobs" else: job_application = JobApplication(user=g.user, jobpost=post, email=applyform.apply_email.data, phone=applyform.apply_phone.data, message=applyform.apply_message.data, words=applyform.words) db.session.add(job_application) db.session.commit() email_html = email_transform( render_template('apply_email.html', post=post, job_application=job_application, archive_url=url_for('view_application', hashid=post.hashid, application=job_application.hashid, _external=True)), base_url=request.url_root) email_text = html2text(email_html) flashmsg = "Your application has been sent to the employer" msg = Message(subject=u"Job application: {fullname}".format(fullname=job_application.user.fullname), recipients=[post.email]) msg.body = email_text msg.html = email_html mail.send(msg) if request.is_xhr: return u'<p><strong>{}</strong></p>'.format(flashmsg) else: flash(flashmsg, 'interactive') return redirect(url_for('jobdetail', hashid=post.hashid), 303) if request.is_xhr: return render_template('inc/applyform.html', post=post, applyform=applyform, ajaxreg=True) else: return redirect(url_for('jobdetail', hashid=post.hashid), 303)
def process_application(hashid, application): post = JobPost.query.filter_by(hashid=hashid).first_or_404() if post.user and post.user != g.user: if not g.user: return redirect(url_for('login')) else: abort(403) job_application = JobApplication.query.filter_by(hashid=application, jobpost=post).first_or_404() process_application_form = forms.ProcessApplicationForm() flashmsg = '' if process_application_form.validate_on_submit(): if request.form.get('action') == 'connect' and job_application.can_connect(): email_html = email_transform( render_template('connect_email.html', post=post, job_application=job_application, archive_url=url_for('view_application', hashid=post.hashid, application=job_application.hashid, _external=True)), base_url=request.url_root) email_text = html2text(email_html) flashmsg = "We emailed the candidate on your behalf to make a connection" msg = Message(subject="Job Connection: {name}".format(name=post.company_name), sender=(post.fullname or post.company_name, post.email), recipients=[job_application.email], cc=[post.email], reply_to=(post.fullname, post.email)) msg.body = email_text msg.html = email_html mail.send(msg) job_application.response = EMPLOYER_RESPONSE.CONNECTED db.session.commit() elif request.form.get('action') == 'ignore' and job_application.can_ignore(): job_application.response = EMPLOYER_RESPONSE.IGNORED db.session.commit() elif request.form.get('action') == 'flag' and job_application.can_report(): job_application.response = EMPLOYER_RESPONSE.FLAGGED db.session.commit() elif request.form.get('action') == 'unflag' and job_application.is_flagged(): job_application.response = EMPLOYER_RESPONSE.PENDING db.session.commit() if flashmsg: if request.is_xhr: return u'<p><strong>{}</strong></p>'.format(flashmsg) else: flash(flashmsg, 'interactive') return redirect(url_for('view_application', hashid=post.hashid, application=job_application.hashid), 303)
def send_reject_mail(reject_type, post, banned_posts=[]): if reject_type not in ['reject', 'ban']: return mail_meta = { 'reject': { 'subject': "About your job post on Hasjob", 'template': "reject_email.html.jinja2" }, 'ban': { 'subject': "About your account and job posts on Hasjob", 'template': "reject_domain_email.html.jinja2" } } msg = Message(subject=mail_meta[reject_type]['subject'], recipients=[post.email]) msg.html = email_transform(render_template(mail_meta[reject_type]['template'], post=post, banned_posts=banned_posts), base_url=request.url_root) msg.body = html2text(msg.html) mail.send(msg)
def send_reject_mail(reject_type, post, banned_posts=[]): if reject_type not in ['reject', 'ban']: return mail_meta = { 'reject': { 'subject': "About your job post on Hasjob", 'template': "reject_email.html" }, 'ban': { 'subject': "About your account and job posts on Hasjob", 'template': "reject_domain_email.html" } } msg = Message(subject=mail_meta[reject_type]['subject'], recipients=[post.email]) msg.html = email_transform(render_template(mail_meta[reject_type]['template'], post=post, banned_posts=banned_posts), base_url=request.url_root) msg.body = html2text(msg.html) mail.send(msg)
def rejectjob(domain, hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() if post.status in [POSTSTATUS.DRAFT, POSTSTATUS.PENDING ] and not post.admin_is(g.user): abort(403) if post.status in [ POSTSTATUS.REJECTED, POSTSTATUS.WITHDRAWN, POSTSTATUS.SPAM ]: abort(410) rejectform = forms.RejectForm() if rejectform.validate_on_submit(): post.closed_datetime = datetime.utcnow() post.review_comments = rejectform.reason.data post.review_datetime = datetime.utcnow() post.reviewer = g.user if request.form.get('submit') == 'spam': flashmsg = "This job post has been marked as spam." post.status = POSTSTATUS.SPAM else: if request.form.get('submit') == 'ban': flashmsg = "This job post has been rejected and the user and domain banned." post.domain.is_banned = True post.domain.banned_by = g.user post.domain.banned_reason = rejectform.reason.data if post.user: post.user.blocked = True else: flashmsg = "This job post has been rejected." post.status = POSTSTATUS.REJECTED msg = Message(subject="About your job post on Hasjob", recipients=[post.email]) msg.body = render_template("reject_email.md", post=post) msg.html = markdown(msg.body) mail.send(msg) db.session.commit() if request.is_xhr: return "<p>%s</p>" % flashmsg else: flash(flashmsg, "interactive") elif request.method == 'POST' and request.is_xhr: return render_template('inc/rejectform.html', post=post, rejectform=rejectform) return redirect(post.url_for(), code=303)
def rejectjob(domain, hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() if post.status in [POSTSTATUS.DRAFT, POSTSTATUS.PENDING] and not post.admin_is(g.user): abort(403) if post.status in [POSTSTATUS.REJECTED, POSTSTATUS.WITHDRAWN, POSTSTATUS.SPAM]: abort(410) rejectform = forms.RejectForm() if rejectform.validate_on_submit(): post.closed_datetime = datetime.utcnow() post.review_comments = rejectform.reason.data post.review_datetime = datetime.utcnow() post.reviewer = g.user if request.form.get('submit') == 'spam': flashmsg = "This job post has been marked as spam." post.status = POSTSTATUS.SPAM else: if request.form.get('submit') == 'ban': flashmsg = "This job post has been rejected and the user and domain banned." post.domain.is_banned = True post.domain.banned_by = g.user post.domain.banned_reason = rejectform.reason.data if post.user: post.user.blocked = True else: flashmsg = "This job post has been rejected." post.status = POSTSTATUS.REJECTED msg = Message(subject="About your job post on Hasjob", recipients=[post.email]) msg.html = email_transform(render_template('reject_email.html', post=post), base_url=request.url_root) msg.body = html2text(msg.html) mail.send(msg) db.session.commit() if request.is_xhr: return "<p>%s</p>" % flashmsg else: flash(flashmsg, "interactive") elif request.method == 'POST' and request.is_xhr: return render_template('inc/rejectform.html', post=post, rejectform=rejectform) return redirect(post.url_for(), code=303)
def moderatejob(domain, hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() if post.state.UNPUBLISHED: abort(403) if post.state.GONE: abort(410) moderateform = forms.ModerateForm() if moderateform.validate_on_submit(): post.moderate(moderateform.reason.data, g.user) flashmsg = post.moderate.data['message'] msg = Message(subject="About your job post on Hasjob", recipients=[post.email]) msg.html = email_transform(render_template('moderate_email.html.jinja2', post=post), base_url=request.url_root) msg.body = html2text(msg.html) mail.send(msg) db.session.commit() # cache bust # dogpile.invalidate_region('hasjob_index') if request.is_xhr: return "<p>%s</p>" % flashmsg elif request.method == 'POST' and request.is_xhr: return render_template('inc/moderateform.html.jinja2', post=post, moderateform=moderateform) return redirect(post.url_for(), code=303)
def rejectjob(hashid): post = JobPost.query.filter_by(hashid=hashid).first_or_404() if post.status in [POSTSTATUS.DRAFT, POSTSTATUS.PENDING]: if post.edit_key not in session.get('userkeys', []): abort(403) if post.status in [ POSTSTATUS.REJECTED, POSTSTATUS.WITHDRAWN, POSTSTATUS.SPAM ]: abort(410) rejectform = forms.RejectForm() if rejectform.validate_on_submit(): post.closed_datetime = datetime.utcnow() post.review_comments = rejectform.reason.data post.review_datetime = datetime.utcnow() post.reviewer = g.user if request.form.get('submit') == 'spam': flashmsg = "This job listing has been marked as spam." post.status = POSTSTATUS.SPAM else: flashmsg = "This job listing has been rejected." post.status = POSTSTATUS.REJECTED msg = Message(subject="About your job listing on Hasjob", recipients=[post.email]) msg.body = render_template("reject_email.md", post=post) msg.html = markdown(msg.body) mail.send(msg) db.session.commit() if request.is_xhr: return "<p>%s</p>" % flashmsg else: flash(flashmsg, "interactive") elif request.method == 'POST' and request.is_xhr: return render_template('inc/rejectform.html', post=post, rejectform=rejectform) return redirect(url_for('jobdetail', hashid=post.hashid))
def process_application(domain, hashid, application): post = JobPost.query.filter_by(hashid=hashid).first_or_404() if post.user and not post.admin_is(g.user): if not g.user: return redirect(url_for('login')) else: abort(403) job_application = JobApplication.query.filter_by(hashid=application, jobpost=post).first_or_404() response_form = forms.ApplicationResponseForm() flashmsg = '' if response_form.validate_on_submit(): if (request.form.get('action') == 'reply' and job_application.response.CAN_REPLY) or ( request.form.get('action') == 'reject' and job_application.response.CAN_REJECT): if not response_form.response_message.data: flashmsg = "You need to write a message to the candidate." else: if request.form.get('action') == 'reply': job_application.reply( message=response_form.response_message.data, user=g.user ) else: job_application.reject( message=response_form.response_message.data, user=g.user ) email_html = email_transform( render_template('respond_email.html.jinja2', post=post, job_application=job_application, archive_url=job_application.url_for(_external=True)), base_url=request.url_root) email_text = html2text(email_html) sender_name = g.user.fullname if post.admin_is(g.user) else post.fullname or post.company_name sender_formatted = u'{sender} (via {site})'.format( sender=sender_name, site=app.config['SITE_TITLE']) if job_application.response.REPLIED: msg = Message( subject=u"{candidate}: {headline}".format( candidate=job_application.user.fullname, headline=post.headline), sender=(sender_formatted, app.config['MAIL_SENDER']), reply_to=(sender_name, post.email), recipients=[job_application.email], bcc=[post.email]) flashmsg = "We sent your message to the candidate and copied you. Their email and phone number are below" else: msg = Message(subject=u"Job declined: {headline}".format(headline=post.headline), sender=(sender_formatted, app.config['MAIL_SENDER']), bcc=[job_application.email, post.email]) flashmsg = "We sent your message to the candidate and copied you" msg.body = email_text msg.html = email_html mail.send(msg) db.session.commit() elif request.form.get('action') == 'ignore' and job_application.response.CAN_IGNORE: job_application.ignore() db.session.commit() elif request.form.get('action') == 'flag' and job_application.response.CAN_REPORT: job_application.flag() db.session.commit() elif request.form.get('action') == 'unflag' and job_application.response.FLAGGED: job_application.unflag() db.session.commit() if flashmsg: if request.is_xhr: return u'<p><strong>{}</strong></p>'.format(flashmsg) else: flash(flashmsg, 'interactive') return redirect(job_application.url_for(), 303)
def process_application(hashid, application): post = JobPost.query.filter_by(hashid=hashid).first_or_404() if post.user and not post.admin_is(g.user): if not g.user: return redirect(url_for('login')) else: abort(403) job_application = JobApplication.query.filter_by(hashid=application, jobpost=post).first_or_404() response_form = forms.ApplicationResponseForm() flashmsg = '' if response_form.validate_on_submit(): if (request.form.get('action') == 'reply' and job_application.can_reply()) or ( request.form.get('action') == 'reject' and job_application.can_reject()): if not response_form.response_message.data: flashmsg = "You need to write a message to the candidate." else: if request.form.get('action') == 'reply': job_application.response = EMPLOYER_RESPONSE.REPLIED else: job_application.response = EMPLOYER_RESPONSE.REJECTED job_application.response_message = response_form.response_message.data email_html = email_transform( render_template('respond_email.html', post=post, job_application=job_application, archive_url=url_for('view_application', hashid=post.hashid, application=job_application.hashid, _external=True)), base_url=request.url_root) email_text = html2text(email_html) if job_application.is_replied(): msg = Message(subject=u"Regarding your job application for {headline}".format(headline=post.headline), sender=(u'{sender} (via {site})'.format( sender=post.fullname or post.company_name, site=app.config['SITE_TITLE']), post.email), recipients=[job_application.email], bcc=[post.email]) else: msg = Message(subject=u"Regarding your job application for {headline}".format(headline=post.headline), sender=(u'{sender} (via {site})'.format( sender=post.fullname or post.company_name, site=app.config['SITE_TITLE']), app.config['MAIL_SENDER']), bcc=[job_application.email, post.email]) msg.body = email_text msg.html = email_html mail.send(msg) flashmsg = "We sent your message to the candidate and copied you." db.session.commit() elif request.form.get('action') == 'ignore' and job_application.can_ignore(): job_application.response = EMPLOYER_RESPONSE.IGNORED db.session.commit() elif request.form.get('action') == 'flag' and job_application.can_report(): job_application.response = EMPLOYER_RESPONSE.FLAGGED db.session.commit() elif request.form.get('action') == 'unflag' and job_application.is_flagged(): job_application.response = EMPLOYER_RESPONSE.NEW db.session.commit() if flashmsg: if request.is_xhr: return u'<p><strong>{}</strong></p>'.format(flashmsg) else: flash(flashmsg, 'interactive') return redirect(url_for('view_application', hashid=post.hashid, application=job_application.hashid), 303)
def applyjob(hashid): """ Apply to a job (including in kiosk mode) """ post = JobPost.query.filter_by(hashid=hashid).first_or_404() if g.user: job_application = JobApplication.query.filter_by(user=g.user, jobpost=post).first() else: job_application = None if job_application: flashmsg = "You have already applied to this job. You may not apply again" if request.is_xhr: return u'<p><strong>{}</strong></p>'.format(flashmsg) else: flash(flashmsg, 'interactive') return redirect(url_for('jobdetail', hashid=post.hashid), 303) else: if g.kiosk: applyform = forms.KioskApplicationForm() else: applyform = forms.ApplicationForm() applyform.post = post if applyform.validate_on_submit(): if g.user and g.user.blocked: flashmsg = "Your account has been blocked from applying to jobs" else: if g.kiosk: job_application = JobApplication( user=None, jobpost=post, fullname=applyform.apply_fullname.data, email=applyform.apply_email.data, phone=applyform.apply_phone.data, message=applyform.apply_message.data, words=None) else: job_application = JobApplication( user=g.user, jobpost=post, fullname=g.user.fullname, email=applyform.apply_email.data, phone=applyform.apply_phone.data, message=applyform.apply_message.data, words=applyform.words) db.session.add(job_application) db.session.commit() email_html = email_transform(render_template( 'apply_email.html', post=post, job_application=job_application, archive_url=url_for('view_application', hashid=post.hashid, application=job_application.hashid, _external=True)), base_url=request.url_root) email_text = html2text(email_html) flashmsg = "Your application has been sent to the employer" msg = Message(subject=u"Job application: {fullname}".format( fullname=job_application.fullname), recipients=[post.email]) if not job_application.user: # Also BCC the candidate msg.bcc = [job_application.email] msg.body = email_text msg.html = email_html mail.send(msg) if request.is_xhr: return u'<p><strong>{}</strong></p>'.format(flashmsg) else: flash(flashmsg, 'interactive') return redirect(url_for('jobdetail', hashid=post.hashid), 303) if request.is_xhr: return render_template('inc/applyform.html', post=post, applyform=applyform) else: return redirect(url_for('jobdetail', hashid=post.hashid), 303)
def applyjob(domain, hashid): """ Apply to a job (including in kiosk mode) """ post = JobPost.query.filter_by(hashid=hashid).first_or_404() # If the domain doesn't match, redirect to correct URL if post.email_domain != domain: return redirect(post.url_for('apply'), code=301) if g.user: job_application = JobApplication.query.filter_by(user=g.user, jobpost=post).first() else: job_application = None if job_application: flashmsg = "You have already applied to this job. You may not apply again" if request.is_xhr: return u'<p><strong>{}</strong></p>'.format(flashmsg) else: flash(flashmsg, 'interactive') return redirect(post.url_for(), 303) else: if g.kiosk: applyform = forms.KioskApplicationForm() else: applyform = forms.ApplicationForm() applyform.post = post if applyform.validate_on_submit(): if g.user and g.user.blocked: flashmsg = "Your account has been blocked from applying to jobs" else: if g.kiosk: job_application = JobApplication( user=None, jobpost=post, fullname=applyform.apply_fullname.data, email=applyform.apply_email.data, phone=applyform.apply_phone.data, message=applyform.apply_message.data, words=None) else: job_application = JobApplication( user=g.user, jobpost=post, fullname=g.user.fullname, email=applyform.apply_email.data, phone=applyform.apply_phone.data, message=applyform.apply_message.data, optin=applyform.apply_optin.data, words=applyform.words) db.session.add(job_application) db.session.commit() post.uncache_viewcounts('applied') email_html = email_transform(render_template( 'apply_email.html', post=post, job_application=job_application, archive_url=job_application.url_for(_external=True)), base_url=request.url_root) email_text = html2text(email_html) flashmsg = "Your application has been sent to the employer" msg = Message(subject=u"Job application: {fullname}".format( fullname=job_application.fullname), recipients=[post.email]) if not job_application.user: # Also BCC the candidate (for kiosk mode) # FIXME: This should be a separate copy of the email as the tracking gif is now shared # between both employer and candidate msg.bcc = [job_application.email] msg.body = email_text msg.html = email_html mail.send(msg) if request.is_xhr: return u'<p><strong>{}</strong></p>'.format(flashmsg) else: flash(flashmsg, 'interactive') return redirect(post.url_for(), 303) if request.is_xhr: return render_template('inc/applyform.html', post=post, applyform=applyform) else: return redirect(post.url_for(), 303)
def process_application(domain, hashid, application): post = JobPost.query.filter_by(hashid=hashid).first_or_404() if post.user and not post.admin_is(g.user): if not g.user: return redirect(url_for('login')) else: abort(403) job_application = JobApplication.query.filter_by( hashid=application, jobpost=post).first_or_404() response_form = forms.ApplicationResponseForm() flashmsg = '' if response_form.validate_on_submit(): if (request.form.get('action') == 'reply' and job_application.can_reply()) or ( request.form.get('action') == 'reject' and job_application.can_reject()): if not response_form.response_message.data: flashmsg = "You need to write a message to the candidate." else: if request.form.get('action') == 'reply': job_application.response = EMPLOYER_RESPONSE.REPLIED else: job_application.response = EMPLOYER_RESPONSE.REJECTED job_application.response_message = response_form.response_message.data job_application.replied_by = g.user job_application.replied_at = datetime.utcnow() email_html = email_transform(render_template( 'respond_email.html', post=post, job_application=job_application, archive_url=job_application.url_for(_external=True)), base_url=request.url_root) email_text = html2text(email_html) sender_name = g.user.fullname if post.admin_is( g.user) else post.fullname or post.company_name sender_formatted = u'{sender} (via {site})'.format( sender=sender_name, site=app.config['SITE_TITLE']) if job_application.is_replied(): msg = Message(subject=u"Job response: {headline}".format( headline=post.headline), sender=(sender_formatted, app.config['MAIL_SENDER']), reply_to=(sender_name, post.email), recipients=[job_application.email], bcc=[post.email]) flashmsg = "We sent your message to the candidate and copied you. Their email and phone number are below" else: msg = Message(subject=u"Job declined: {headline}".format( headline=post.headline), sender=(sender_formatted, app.config['MAIL_SENDER']), bcc=[job_application.email, post.email]) flashmsg = "We sent your message to the candidate and copied you" msg.body = email_text msg.html = email_html mail.send(msg) db.session.commit() elif request.form.get( 'action') == 'ignore' and job_application.can_ignore(): job_application.response = EMPLOYER_RESPONSE.IGNORED db.session.commit() elif request.form.get( 'action') == 'flag' and job_application.can_report(): job_application.response = EMPLOYER_RESPONSE.FLAGGED db.session.commit() elif request.form.get( 'action') == 'unflag' and job_application.is_flagged(): job_application.response = EMPLOYER_RESPONSE.NEW db.session.commit() if flashmsg: if request.is_xhr: return u'<p><strong>{}</strong></p>'.format(flashmsg) else: flash(flashmsg, 'interactive') return redirect(job_application.url_for(), 303)
def applyjob(domain, hashid): """ Apply to a job (including in kiosk mode) """ post = JobPost.query.filter_by(hashid=hashid).first_or_404() # If the domain doesn't match, redirect to correct URL if post.email_domain != domain: return redirect(post.url_for('apply'), code=301) if g.user: job_application = JobApplication.query.filter_by(user=g.user, jobpost=post).first() else: job_application = None if job_application: flashmsg = "You have already applied to this job. You may not apply again" if request.is_xhr: return u'<p><strong>{}</strong></p>'.format(flashmsg) else: flash(flashmsg, 'interactive') return redirect(post.url_for(), 303) else: if g.kiosk: applyform = forms.KioskApplicationForm() else: applyform = forms.ApplicationForm() applyform.post = post if applyform.validate_on_submit(): if g.user and g.user.blocked: flashmsg = "Your account has been blocked from applying to jobs" else: if g.kiosk: job_application = JobApplication(user=None, jobpost=post, fullname=applyform.apply_fullname.data, email=applyform.apply_email.data, phone=applyform.apply_phone.data, message=applyform.apply_message.data, words=None) else: job_application = JobApplication(user=g.user, jobpost=post, fullname=g.user.fullname, email=applyform.apply_email.data, phone=applyform.apply_phone.data, message=applyform.apply_message.data, optin=applyform.apply_optin.data, words=applyform.words) db.session.add(job_application) db.session.commit() post.uncache_viewcounts('applied') email_html = email_transform( render_template('apply_email.html', post=post, job_application=job_application, archive_url=job_application.url_for(_external=True)), base_url=request.url_root) email_text = html2text(email_html) flashmsg = "Your application has been sent to the employer" msg = Message(subject=u"Job application: {fullname}".format(fullname=job_application.fullname), recipients=[post.email]) if not job_application.user: # Also BCC the candidate (for kiosk mode) # FIXME: This should be a separate copy of the email as the tracking gif is now shared # between both employer and candidate msg.bcc = [job_application.email] msg.body = email_text msg.html = email_html mail.send(msg) if request.is_xhr: return u'<p><strong>{}</strong></p>'.format(flashmsg) else: flash(flashmsg, 'interactive') return redirect(post.url_for(), 303) if request.is_xhr: return render_template('inc/applyform.html', post=post, applyform=applyform) else: return redirect(post.url_for(), 303)