Пример #1
0
def revealjob(domain, hashid):
    """
    Reveal job application form
    """
    post = JobPost.query.filter_by(hashid=hashid).first_or_404()
    if post.status in POSTSTATUS.GONE:
        abort(410)
    jobview = UserJobView.query.get((post.id, g.user.id))
    if jobview is None:
        jobview = UserJobView(user=g.user, jobpost=post, applied=True)
        db.session.add(jobview)
        try:
            db.session.commit()
            post.uncache_viewcounts('opened')
            cache.delete_memoized(viewstats_by_id_qhour, post.id)
            cache.delete_memoized(viewstats_by_id_hour, post.id)
            cache.delete_memoized(viewstats_by_id_day, post.id)
            post.viewcounts  # Re-populate cache
        except IntegrityError:
            db.session.rollback()
            pass  # User double-clicked. Ignore.
    elif not jobview.applied:
        jobview.applied = True
        db.session.commit()
        post.uncache_viewcounts('opened')
        cache.delete_memoized(viewstats_by_id_qhour, post.id)
        cache.delete_memoized(viewstats_by_id_hour, post.id)
        cache.delete_memoized(viewstats_by_id_day, post.id)
        post.viewcounts  # Re-populate cache

    applyform = None
    job_application = JobApplication.query.filter_by(user=g.user, jobpost=post).first()
    if not job_application:
        applyform = forms.ApplicationForm()
        applyform.apply_phone.data = g.user.phone

    return render_template('jobpost_reveal.html',
        post=post,
        instructions=redactemail(post.how_to_apply),
        applyform=applyform,
        job_application=job_application)
Пример #2
0
def jobdetail(domain, hashid):
    post = JobPost.query.filter_by(hashid=hashid).first_or_404()

    # If we're on a board (that's now 'www') and this post isn't on this board,
    # redirect to (a) the first board it is on, or (b) on the root domain (which may
    # be the 'www' board, which is why we don't bother to redirect if we're currently
    # in the 'www' board)
    if g.board and g.board.not_root and post.link_to_board(g.board) is None:
        blink = post.postboards.first()
        if blink:
            return redirect(
                post.url_for(subdomain=blink.board.name, _external=True))
        else:
            return redirect(post.url_for(subdomain=None, _external=True))

    # If this post is past pending state and the domain doesn't match, redirect there
    if post.status not in POSTSTATUS.UNPUBLISHED and post.email_domain != domain:
        return redirect(post.url_for(), code=301)

    if post.status in [POSTSTATUS.DRAFT, POSTSTATUS.PENDING]:
        if not ((g.user and post.admin_is(g.user))):
            abort(403)
    if post.status in POSTSTATUS.GONE:
        abort(410)
    if g.user:
        jobview = UserJobView.get(post, g.user)
        if jobview is None:
            jobview = UserJobView(user=g.user, jobpost=post)
            post.uncache_viewcounts('viewed')
            cache.delete_memoized(viewstats_by_id_qhour, post.id)
            cache.delete_memoized(viewstats_by_id_hour, post.id)
            cache.delete_memoized(viewstats_by_id_day, post.id)
            db.session.add(jobview)
            try:
                db.session.commit()
            except IntegrityError:
                db.session.rollback()
            post.viewcounts  # Re-populate cache
    else:
        jobview = None

    if g.anon_user:
        anonview = AnonJobView.get(post, g.anon_user)
        if not anonview:
            anonview = AnonJobView(jobpost=post, anon_user=g.anon_user)
            db.session.add(anonview)
            try:
                db.session.commit()
            except IntegrityError:
                db.session.rollback()

    if g.user:
        report = JobPostReport.query.filter_by(post=post, user=g.user).first()
    else:
        report = None

    g.jobpost_viewed = (post, getbool(request.args.get('b')))

    reportform = forms.ReportForm(obj=report)
    reportform.report_code.choices = [
        (ob.id, ob.title)
        for ob in ReportCode.query.filter_by(public=True).order_by('seq')
    ]
    rejectform = forms.RejectForm()
    moderateform = forms.ModerateForm()
    if request.method == 'GET':
        moderateform.reason.data = post.review_comments
    if g.board:
        pinnedform = forms.PinnedForm(obj=post.link_to_board(g.board))
    else:
        pinnedform = forms.PinnedForm(obj=post)
    applyform = None  # User isn't allowed to apply unless non-None
    if g.user:
        job_application = JobApplication.query.filter_by(user=g.user,
                                                         jobpost=post).first()
        if not job_application:
            applyform = forms.ApplicationForm()
            applyform.apply_phone.data = g.user.phone
    elif g.kiosk and g.peopleflow_url:
        applyform = forms.KioskApplicationForm()
        job_application = None
    else:
        job_application = None
    if reportform.validate_on_submit():
        if g.user:
            if report is None:
                report = JobPostReport(post=post, user=g.user)
            report.reportcode_id = reportform.report_code.data
            report.ipaddr = request.environ['REMOTE_ADDR']
            report.useragent = request.user_agent.string
            db.session.add(report)
            db.session.commit()
            if request.is_xhr:
                return "<p>Thanks! This post has been flagged for review</p>"  # FIXME: Ugh!
            else:
                flash("Thanks! This post has been flagged for review",
                      "interactive")
        else:
            if request.is_xhr:
                return "<p>You need to be logged in to report a post</p>"  # FIXME: Ugh!
            else:
                flash("You need to be logged in to report a post",
                      "interactive")
    elif request.method == 'POST' and request.is_xhr:
        return render_template('inc/reportform.html', reportform=reportform)

    if post.company_url and post.status != POSTSTATUS.ANNOUNCEMENT:
        domain_mismatch = not base_domain_matches(post.company_url.lower(),
                                                  post.email_domain.lower())
    else:
        domain_mismatch = False

    if not g.kiosk:
        if g.preview_campaign:
            header_campaign = g.preview_campaign
        else:
            header_campaign = Campaign.for_context(
                CAMPAIGN_POSITION.HEADER,
                board=g.board,
                user=g.user,
                anon_user=g.anon_user,
                geonameids=g.user_geonameids + post.geonameids)
    else:
        header_campaign = None

    if g.user and not g.kiosk:
        g.starred_ids = set(g.user.starred_job_ids(agelimit))
    else:
        g.starred_ids = set()

    jobpost_ab = session_jobpost_ab()
    related_posts = post.related_posts()
    cache_viewcounts(related_posts)
    is_bgroup = getbool(request.args.get('b'))
    headline = post.headlineb if is_bgroup and post.headlineb else post.headline
    g.impressions = {
        rp.id: (False, rp.id, bgroup(jobpost_ab, rp))
        for rp in related_posts
    }

    return render_template('detail.html',
                           post=post,
                           headline=headline,
                           reportform=reportform,
                           rejectform=rejectform,
                           pinnedform=pinnedform,
                           applyform=applyform,
                           job_application=job_application,
                           jobview=jobview,
                           report=report,
                           moderateform=moderateform,
                           domain_mismatch=domain_mismatch,
                           header_campaign=header_campaign,
                           related_posts=related_posts,
                           is_bgroup=is_bgroup,
                           is_siteadmin=lastuser.has_permission('siteadmin'))
Пример #3
0
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)
Пример #4
0
def jobdetail(hashid):
    post = JobPost.query.filter_by(hashid=hashid).first_or_404()

    if g.board and post.link_to_board(g.board) is None:
        blink = post.postboards.first()
        if blink:
            return redirect(
                url_for('jobdetail',
                        hashid=post.hashid,
                        subdomain=blink.board.name,
                        _external=True))
        else:
            return redirect(
                url_for('jobdetail',
                        hashid=post.hashid,
                        subdomain=None,
                        _external=True))

    if post.status in [POSTSTATUS.DRAFT, POSTSTATUS.PENDING]:
        if not ((g.user and post.admin_is(g.user))
                or post.edit_key in session.get('userkeys', [])):
            abort(403)
    if post.status in POSTSTATUS.GONE:
        abort(410)
    if g.user:
        jobview = UserJobView.query.get((g.user.id, post.id))
        if jobview is None:
            jobview = UserJobView(user=g.user, jobpost=post)
            cache.delete_memoized(viewcounts_by_id, post.id)
            cache.delete_memoized(viewstats_by_id_qhour, post.id)
            cache.delete_memoized(viewstats_by_id_hour, post.id)
            cache.delete_memoized(viewstats_by_id_day, post.id)
            db.session.add(jobview)
            try:
                db.session.commit()
            except IntegrityError:
                db.session.rollback()
                pass  # User opened two tabs at once? We don't really know
            viewcounts_by_id(post.id)  # Re-populate cache
    else:
        jobview = None

    if g.user:
        report = JobPostReport.query.filter_by(post=post, user=g.user).first()
    else:
        report = None

    reportform = forms.ReportForm(obj=report)
    reportform.report_code.choices = [
        (ob.id, ob.title)
        for ob in ReportCode.query.filter_by(public=True).order_by('seq')
    ]
    rejectform = forms.RejectForm()
    moderateform = forms.ModerateForm()
    if request.method == 'GET':
        moderateform.reason.data = post.review_comments
    if g.board:
        pinnedform = forms.PinnedForm(obj=post.link_to_board(g.board))
    else:
        pinnedform = forms.PinnedForm(obj=post)
    applyform = None  # User isn't allowed to apply unless non-None
    if g.user:
        job_application = JobApplication.query.filter_by(user=g.user,
                                                         jobpost=post).first()
        if not job_application:
            applyform = forms.ApplicationForm()
            applyform.apply_phone.data = g.user.phone
    elif g.kiosk and g.peopleflow_url:
        applyform = forms.KioskApplicationForm()
        job_application = None
    else:
        job_application = None
    if reportform.validate_on_submit():
        if g.user:
            if report is None:
                report = JobPostReport(post=post, user=g.user)
            report.reportcode_id = reportform.report_code.data
            report.ipaddr = request.environ['REMOTE_ADDR']
            report.useragent = request.user_agent.string
            db.session.add(report)
            db.session.commit()
            if request.is_xhr:
                return "<p>Thanks! This listing has been flagged for review</p>"  # FIXME: Ugh!
            else:
                flash("Thanks! This listing has been flagged for review",
                      "interactive")
        else:
            if request.is_xhr:
                return "<p>You need to be logged in to report a listing</p>"  # FIXME: Ugh!
            else:
                flash("You need to be logged in to report a listing",
                      "interactive")
    elif request.method == 'POST' and request.is_xhr:
        return render_template('inc/reportform.html', reportform=reportform)

    if post.company_url and post.status != POSTSTATUS.ANNOUNCEMENT:
        domain_mismatch = not base_domain_matches(post.company_url.lower(),
                                                  post.email_domain.lower())
    else:
        domain_mismatch = False

    return render_template('detail.html',
                           post=post,
                           reportform=reportform,
                           rejectform=rejectform,
                           pinnedform=pinnedform,
                           applyform=applyform,
                           job_application=job_application,
                           jobview=jobview,
                           report=report,
                           moderateform=moderateform,
                           domain_mismatch=domain_mismatch,
                           siteadmin=lastuser.has_permission('siteadmin'))
Пример #5
0
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)
Пример #6
0
def jobdetail(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', []) or (g.user and not post.admin_is(g.user)):
            abort(403)
    if post.status in [
            POSTSTATUS.REJECTED, POSTSTATUS.WITHDRAWN, POSTSTATUS.SPAM
    ]:
        abort(410)
    if g.user:
        jobview = UserJobView.query.get((g.user.id, post.id))
        if jobview is None:
            jobview = UserJobView(user=g.user, jobpost=post)
            cache.delete_memoized(viewcounts_by_id, post.id)
            cache.delete_memoized(viewstats_by_id_qhour, post.id)
            cache.delete_memoized(viewstats_by_id_hour, post.id)
            cache.delete_memoized(viewstats_by_id_day, post.id)
            db.session.add(jobview)
            try:
                db.session.commit()
            except IntegrityError:
                db.session.rollback()
                pass  # User opened two tabs at once? We don't really know
            viewcounts_by_id(post.id)  # Re-populate cache
    else:
        jobview = None

    if g.user:
        report = JobPostReport.query.filter_by(post=post, user=g.user).first()
    else:
        report = None

    reportform = forms.ReportForm(obj=report)
    reportform.report_code.choices = [
        (ob.id, ob.title)
        for ob in ReportCode.query.filter_by(public=True).order_by('seq')
    ]
    rejectform = forms.RejectForm()
    stickyform = forms.StickyForm(obj=post)
    applyform = None  # User isn't allowed to apply unless non-None
    if g.user:
        job_application = JobApplication.query.filter_by(user=g.user,
                                                         jobpost=post).first()
        if not job_application:
            applyform = forms.ApplicationForm()
            applyform.apply_phone.data = g.user.phone
    else:
        job_application = None
    if reportform.validate_on_submit():
        if g.user:
            if report is None:
                report = JobPostReport(post=post, user=g.user)
            report.reportcode_id = reportform.report_code.data
            report.ipaddr = request.environ['REMOTE_ADDR']
            report.useragent = request.user_agent.string
            db.session.add(report)
            db.session.commit()
            if request.is_xhr:
                return "<p>Thanks! This listing has been flagged for review</p>"  # FIXME: Ugh!
            else:
                flash("Thanks! This listing has been flagged for review",
                      "interactive")
        else:
            if request.is_xhr:
                return "<p>You need to be logged in to report a listing</p>"  # FIXME: Ugh!
            else:
                flash("You need to be logged in to report a listing",
                      "interactive")
    elif request.method == 'POST' and request.is_xhr:
        return render_template('inc/reportform.html',
                               reportform=reportform,
                               ajaxreg=True)
    return render_template('detail.html',
                           post=post,
                           reportform=reportform,
                           rejectform=rejectform,
                           stickyform=stickyform,
                           applyform=applyform,
                           job_application=job_application,
                           webmail_domains=webmail_domains,
                           jobview=jobview,
                           report=report,
                           siteadmin=lastuser.has_permission('siteadmin'))