def newjob(): form = forms.ListingForm() archived_post = None if not g.user: return redirect(url_for('login', next=url_for('newjob'), message=u"Hasjob now requires you to login before posting a job. Please login as yourself." u" We'll add details about your company later")) else: if g.user.blocked: flash("Your account has been blocked from posting jobs", category='info') return redirect(url_for('index'), code=303) if g.board: if 'new-job' not in g.board.permissions(g.user): abort(403) if g.board and not g.board.require_pay: form.job_pay_type.choices = [(-1, u'Confidential')] + PAY_TYPE.items() form.job_type.choices = JobType.choices(g.board) form.job_category.choices = JobCategory.choices(g.board) if request.method == 'GET': if g.user: # form.poster_name.data = g.user.fullname # Deprecated 2013-11-20 form.poster_email.data = g.user.email # Job Reposting if request.method == 'GET' and request.args.get('template'): archived_post = JobPost.get(request.args['template']) if not archived_post: abort(404) if not archived_post.admin_is(g.user): abort(403) if not archived_post.is_old(): flash("This post is currently active and cannot be posted again.") return redirect(archived_post.url_for(), code=303) form.populate_from(archived_post) if form.validate_on_submit(): # POST request from new job page, with successful validation # Move it to the editjob page for handling here forward newpost = { 'hashid': unique_hash(JobPost), 'ipaddr': request.environ['REMOTE_ADDR'], 'useragent': request.user_agent.string, 'user': g.user } return editjob(hashid=None, key=None, form=form, validated=True, newpost=newpost) elif form.errors: # POST request from new job page, with errors flash("Please review the indicated issues", category='interactive') # Render page. Execution reaches here under three conditions: # 1. GET request, page loaded for the first time # 2. POST request from this page, with errors return render_template('postjob.html', form=form, no_removelogo=True, archived_post=archived_post)
def close(domain, hashid, key): post = JobPost.get(hashid) if not post: abort(404) if not post.admin_is(g.user): abort(403) if request.method == 'GET' and post.is_closed(): return redirect(post.url_for('reopen'), code=303) if not post.is_public(): flash("Your job post can't be closed.", "info") return redirect(post.url_for(), code=303) form = Form() if form.validate_on_submit(): post.close() post.closed_datetime = datetime.utcnow() db.session.commit() return redirect(post.url_for(), code=303) return render_template("close.html", post=post, form=form)
def close(domain, hashid, key): post = JobPost.get(hashid) if not post: abort(404) if not post.admin_is(g.user): abort(403) if request.method == 'GET' and post.state.CLOSED: return redirect(post.url_for('reopen'), code=303) if not post.state.PUBLIC: flash("Your job post can't be closed.", "info") return redirect(post.url_for(), code=303) form = Form() if form.validate_on_submit(): post.close() db.session.commit() flash(post.close.data['message'], "success") # cache bust # dogpile.invalidate_region('hasjob_index') return redirect(post.url_for(), code=303) return render_template("close.html.jinja2", post=post, form=form)