Ejemplo n.º 1
0
def view_application(domain, hashid, application):
    post = JobPost.query.filter_by(hashid=hashid).first_or_404()
    # Transition code until we force all employers to login before posting
    if post.user and not (post.admin_is(g.user) or lastuser.has_permission('siteadmin')):
        if not g.user:
            return redirect(url_for('login', message=u"You need to be logged in to view candidate applications on Hasjob."))
        else:
            abort(403)
    job_application = JobApplication.query.filter_by(hashid=application, jobpost=post).first_or_404()

    # If this domain doesn't match, redirect to correct URL
    if post.email_domain != domain:
        return redirect(job_application.url_for(), code=301)

    if job_application.response.NEW:
        # If the application is pending, mark it as opened.
        # However, don't do this if the user is a siteadmin, unless they also own the post.
        if job_application.mark_read.is_available:
            job_application.mark_read()
            db.session.commit()
    response_form = forms.ApplicationResponseForm()

    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

    return render_template('application.html.jinja2', post=post, job_application=job_application,
        header_campaign=header_campaign,
        response_form=response_form, is_siteadmin=lastuser.has_permission('siteadmin'))
Ejemplo n.º 2
0
def view_application(hashid, application):
    post = JobPost.query.filter_by(hashid=hashid).first_or_404()
    # Transition code until we force all employers to login before posting
    if post.user and not (post.admin_is(g.user)
                          or lastuser.has_permission('siteadmin')):
        if not g.user:
            return redirect(
                url_for(
                    'login',
                    message=
                    u"You need to be logged in to view candidate applications on Hasjob."
                ))
        else:
            abort(403)
    job_application = JobApplication.query.filter_by(
        hashid=application, jobpost=post).first_or_404()
    if job_application.response == EMPLOYER_RESPONSE.NEW:
        # If the application is pending, mark it as opened.
        # However, don't do this if the user is a siteadmin, unless they also own the post.
        if post.admin_is(g.user) or not lastuser.has_permission('siteadmin'):
            job_application.response = EMPLOYER_RESPONSE.PENDING
            db.session.commit()
    response_form = forms.ApplicationResponseForm()

    statuses = set([app.status for app in post.applications])

    return render_template('application.html',
                           post=post,
                           job_application=job_application,
                           response_form=response_form,
                           statuses=statuses)
Ejemplo n.º 3
0
def view_application(domain, hashid, application):
    post = JobPost.query.filter_by(hashid=hashid).first_or_404()
    # Transition code until we force all employers to login before posting
    if post.user and not (post.admin_is(g.user)
                          or lastuser.has_permission('siteadmin')):
        if not g.user:
            return redirect(
                url_for(
                    'login',
                    message=
                    u"You need to be logged in to view candidate applications on Hasjob."
                ))
        else:
            abort(403)
    job_application = JobApplication.query.filter_by(
        hashid=application, jobpost=post).first_or_404()

    # If this domain doesn't match, redirect to correct URL
    if post.email_domain != domain:
        return redirect(job_application.url_for(), code=301)

    if job_application.response == EMPLOYER_RESPONSE.NEW:
        # If the application is pending, mark it as opened.
        # However, don't do this if the user is a siteadmin, unless they also own the post.
        if post.admin_is(g.user) or not lastuser.has_permission('siteadmin'):
            job_application.response = EMPLOYER_RESPONSE.PENDING
            db.session.commit()
    response_form = forms.ApplicationResponseForm()

    statuses = set([app.status for app in post.applications])

    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

    return render_template('application.html',
                           post=post,
                           job_application=job_application,
                           header_campaign=header_campaign,
                           response_form=response_form,
                           statuses=statuses,
                           is_siteadmin=lastuser.has_permission('siteadmin'))
Ejemplo n.º 4
0
def index(basequery=None, type=None, category=None, md5sum=None, domain=None, title=None):
    now = datetime.utcnow()
    posts = list(getposts(basequery, sticky=True))
    if posts:
        employer_name = posts[0].company_name
    else:
        employer_name = u'a single employer'

    if basequery is None and posts and not g.kiosk:
        # Group posts by email_domain on index page only, when not in kiosk mode
        grouped = OrderedDict()
        for post in posts:
            if post.sticky:
                # Make sticky posts appear in a group of one
                grouped.setdefault(('s', post.hashid), []).append(post)
                # if post.email_domain in webmail_domains:
                #     grouped.setdefault(('se', post.md5sum), []).append(post)
                # else:
                #     grouped.setdefault(('sd', post.email_domain), []).append(post)
            elif post.email_domain in webmail_domains:
                grouped.setdefault(('ne', post.md5sum), []).append(post)
            else:
                grouped.setdefault(('nd', post.email_domain), []).append(post)
    else:
        grouped = None

    return render_template('index.html', posts=posts, grouped=grouped, now=now,
                           newlimit=newlimit, jobtype=type, jobcategory=category, title=title,
                           md5sum=md5sum, domain=domain, employer_name=employer_name,
                           siteadmin=lastuser.has_permission('siteadmin'))
Ejemplo n.º 5
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', []):
            abort(403)
    if post.status in [POSTSTATUS.REJECTED, POSTSTATUS.WITHDRAWN]:
        abort(410)
    reportform = forms.ReportForm()
    reportform.report_code.choices = [
        (ob.id, ob.title)
        for ob in ReportCode.query.filter_by(public=True).order_by('seq')
    ]
    rejectform = forms.RejectForm()
    if reportform.validate_on_submit():
        report = JobPostReport(post=post,
                               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 job listing has been flagged for review.</p>"  # FIXME: Ugh!
        else:
            flash("Thanks! This job listing has been flagged for review.",
                  "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,
                           siteadmin=lastuser.has_permission('siteadmin'),
                           webmail_domains=webmail_domains)
Ejemplo n.º 6
0
def job_related_posts(domain, hashid):
    is_siteadmin = lastuser.has_permission('siteadmin')
    post = JobPost.query.filter_by(hashid=hashid).options(*JobPost._defercols).first_or_404()
    jobpost_ab = session_jobpost_ab()
    related_posts = post.related_posts().all()
    if is_siteadmin or (g.user and g.user.flags.get('is_employer_month')):
        load_viewcounts(related_posts)
    g.impressions = {rp.id: (False, rp.id, bgroup(jobpost_ab, rp)) for rp in related_posts}
    return render_template('related_posts.html', post=post,
        related_posts=related_posts, is_siteadmin=is_siteadmin)
Ejemplo n.º 7
0
def view_application(hashid, application):
    post = JobPost.query.filter_by(hashid=hashid).first_or_404()
    # Transition code until we force all employers to login before posting
    if post.user and not (post.admin_is(g.user) or lastuser.has_permission('siteadmin')):
        if not g.user:
            return redirect(url_for('login', message=u"You need to be logged in to view candidate applications on Hasjob."))
        else:
            abort(403)
    job_application = JobApplication.query.filter_by(hashid=application, jobpost=post).first_or_404()
    if job_application.response == EMPLOYER_RESPONSE.NEW:
        # If the application is pending, mark it as opened.
        # However, don't do this if the user is a siteadmin, unless they also own the post.
        if post.admin_is(g.user) or not lastuser.has_permission('siteadmin'):
            job_application.response = EMPLOYER_RESPONSE.PENDING
            db.session.commit()
    response_form = forms.ApplicationResponseForm()

    return render_template('application.html', post=post, job_application=job_application,
        response_form=response_form)
Ejemplo n.º 8
0
def job_viewstats(domain, hashid):
    is_siteadmin = lastuser.has_permission('siteadmin')
    post = JobPost.query.filter_by(hashid=hashid).options(db.load_only('id', 'datetime')).first_or_404()
    if is_siteadmin or post.admin_is(g.user) or (g.user and g.user.flags.get('is_employer_month')):
        return jsonify({
            "unittype": post.viewstats[0],
            "stats": post.viewstats[1],
            "counts": get_post_viewcounts(post.id)
            })
    else:
        return abort(403)
Ejemplo n.º 9
0
def job_related_posts(domain, hashid):
    is_siteadmin = lastuser.has_permission('siteadmin')
    post = JobPost.query.filter_by(hashid=hashid).options(*JobPost._defercols).first_or_404()

    jobpost_ab = session_jobpost_ab()
    related_posts = post.related_posts().all()
    if is_siteadmin or (g.user and g.user.flags.get('is_employer_month')):
        cache_viewcounts(related_posts)
    g.impressions = {rp.id: (False, rp.id, bgroup(jobpost_ab, rp)) for rp in related_posts}

    return render_template('related_posts.html', post=post,
        related_posts=related_posts, is_siteadmin=is_siteadmin)
Ejemplo n.º 10
0
def index(basequery=None, type=None, category=None, md5sum=None, domain=None,
        location=None, title=None, showall=False, statuses=None):
    now = datetime.utcnow()
    if g.user or g.kiosk or (g.board and not g.board.require_login):
        showall = True
    posts = list(getposts(basequery, pinned=True, showall=showall, statuses=statuses))
    if posts:
        employer_name = posts[0].company_name
    else:
        employer_name = u'a single employer'

    # Make lookup slightly faster in the loop below since 'g' is a proxy
    board = g.board

    if basequery is None and posts and not g.kiosk:
        # Group posts by email_domain on index page only, when not in kiosk mode
        grouped = OrderedDict()
        for post in posts:
            pinned = post.pinned
            if board is not None:
                blink = post.link_to_board(board)
                if blink is not None:
                    pinned = blink.pinned
            if pinned:
                # Make pinned posts appear in a group of one
                grouped.setdefault(('s', post.hashid), []).append((pinned, post))
            elif post.status == POSTSTATUS.ANNOUNCEMENT:
                # Make announcements also appear in a group of one
                grouped.setdefault(('a', post.hashid), []).append((pinned, post))
            elif post.email_domain in webmail_domains:
                grouped.setdefault(('ne', post.md5sum), []).append((pinned, post))
            else:
                grouped.setdefault(('nd', post.email_domain), []).append((pinned, post))
        pinsandposts = None
    else:
        grouped = None
        if g.board:
            pinsandposts = []
            for post in posts:
                pinned = post.pinned
                if board is not None:
                    blink = post.link_to_board(board)
                    if blink is not None:
                        pinned = blink.pinned
                pinsandposts.append((pinned, post))
        else:
            pinsandposts = [(post.pinned, post) for post in posts]

    return render_template('index.html', pinsandposts=pinsandposts, grouped=grouped, now=now,
                           newlimit=newlimit, jobtype=type, jobcategory=category, title=title,
                           md5sum=md5sum, domain=domain, employer_name=employer_name,
                           location=location, showall=showall,
                           siteadmin=lastuser.has_permission('siteadmin'))
Ejemplo n.º 11
0
def view_application(hashid, application):
    post = JobPost.query.filter_by(hashid=hashid).first_or_404()
    # Transition code until we force all employers to login before posting
    if post.user and (post.user != g.user and not lastuser.has_permission('siteadmin')):
        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()

    return render_template('application.html', post=post, job_application=job_application,
        process_application_form=process_application_form,
        ajaxreg=True)
Ejemplo n.º 12
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', []):
            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)
            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
    else:
        jobview = None
    reportform = forms.ReportForm()
    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():
        report = JobPostReport(post=post, 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 job listing has been flagged for review.</p>"  # FIXME: Ugh!
        else:
            flash("Thanks! This job listing has been flagged for review.", "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,
        siteadmin=lastuser.has_permission('siteadmin')
        )
Ejemplo n.º 13
0
def job_related_posts(domain, hashid):
    is_siteadmin = lastuser.has_permission('siteadmin')
    post = JobPost.query.filter_by(hashid=hashid).options(*JobPost._defercols).first_or_404()
    jobpost_ab = session_jobpost_ab()
    related_posts = post.related_posts().all()
    if is_siteadmin or (g.user and g.user.flags.get('is_employer_month')):
        load_viewcounts(related_posts)
    g.impressions = {rp.id: (False, rp.id, bgroup(jobpost_ab, rp)) for rp in related_posts}
    max_counts = get_max_counts()
    return jsonify(template=render_template('related_posts.html.jinja2', post=post,
            related_posts=related_posts,
            is_siteadmin=is_siteadmin
            ),
        max_impressions=max_counts['max_impressions'],
        max_views=max_counts['max_views'],
        max_opens=max_counts['max_opens'],
        max_applied=max_counts['max_applied']
        )
Ejemplo n.º 14
0
def index(basequery=None,
          type=None,
          category=None,
          md5sum=None,
          domain=None,
          title=None):
    now = datetime.utcnow()
    posts = list(getposts(basequery, sticky=True))
    if posts:
        employer_name = posts[0].company_name
    else:
        employer_name = u'a single employer'

    if basequery is None and posts and not g.kiosk:
        # Group posts by email_domain on index page only, when not in kiosk mode
        grouped = OrderedDict()
        for post in posts:
            if post.sticky:
                # Make sticky posts appear in a group of one
                grouped.setdefault(('s', post.hashid), []).append(post)
                # if post.email_domain in webmail_domains:
                #     grouped.setdefault(('se', post.md5sum), []).append(post)
                # else:
                #     grouped.setdefault(('sd', post.email_domain), []).append(post)
            elif post.email_domain in webmail_domains:
                grouped.setdefault(('ne', post.md5sum), []).append(post)
            else:
                grouped.setdefault(('nd', post.email_domain), []).append(post)
    else:
        grouped = None

    return render_template('index.html',
                           posts=posts,
                           grouped=grouped,
                           now=now,
                           newlimit=newlimit,
                           jobtype=type,
                           jobcategory=category,
                           title=title,
                           md5sum=md5sum,
                           domain=domain,
                           employer_name=employer_name,
                           siteadmin=lastuser.has_permission('siteadmin'))
Ejemplo n.º 15
0
def index(basequery=None, type=None, category=None, md5sum=None, domain=None,
        location=None, title=None, showall=False, statuses=None):
    now = datetime.utcnow()
    if g.user or g.kiosk or g.board:
        showall = True
    posts = list(getposts(basequery, pinned=True, showall=showall, statuses=statuses))
    if posts:
        employer_name = posts[0].company_name
    else:
        employer_name = u'a single employer'

    if basequery is None and posts and not g.kiosk:
        # Group posts by email_domain on index page only, when not in kiosk mode
        grouped = OrderedDict()
        for post in posts:
            if post.pinned:
                # Make pinned posts appear in a group of one
                grouped.setdefault(('s', post.hashid), []).append(post)
                # if post.email_domain in webmail_domains:
                #     grouped.setdefault(('se', post.md5sum), []).append(post)
                # else:
                #     grouped.setdefault(('sd', post.email_domain), []).append(post)
            elif post.status == POSTSTATUS.ANNOUNCEMENT:
                # Make announcements also appear in a group of one
                grouped.setdefault(('a', post.hashid), []).append(post)
            elif post.email_domain in webmail_domains:
                grouped.setdefault(('ne', post.md5sum), []).append(post)
            else:
                grouped.setdefault(('nd', post.email_domain), []).append(post)
    else:
        grouped = None

    return render_template('index.html', posts=posts, grouped=grouped, now=now,
                           newlimit=newlimit, jobtype=type, jobcategory=category, title=title,
                           md5sum=md5sum, domain=domain, employer_name=employer_name,
                           location=location, showall=showall,
                           siteadmin=lastuser.has_permission('siteadmin'))
Ejemplo n.º 16
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'))
Ejemplo n.º 17
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'))
Ejemplo n.º 18
0
def index(basequery=None,
          type=None,
          category=None,
          md5sum=None,
          domain=None,
          location=None,
          title=None,
          showall=False,
          statuses=None):
    now = datetime.utcnow()
    if g.user or g.kiosk or (g.board and not g.board.require_login):
        showall = True
    posts = list(
        getposts(basequery, pinned=True, showall=showall, statuses=statuses))
    if posts:
        employer_name = posts[0].company_name
    else:
        employer_name = u'a single employer'

    # Make lookup slightly faster in the loop below since 'g' is a proxy
    board = g.board

    if basequery is None and posts and not g.kiosk:
        # Group posts by email_domain on index page only, when not in kiosk mode
        grouped = OrderedDict()
        for post in posts:
            pinned = post.pinned
            if board is not None:
                blink = post.link_to_board(board)
                if blink is not None:
                    pinned = blink.pinned
            if pinned:
                # Make pinned posts appear in a group of one
                grouped.setdefault(('s', post.hashid), []).append(
                    (pinned, post))
            elif post.status == POSTSTATUS.ANNOUNCEMENT:
                # Make announcements also appear in a group of one
                grouped.setdefault(('a', post.hashid), []).append(
                    (pinned, post))
            elif post.email_domain in webmail_domains:
                grouped.setdefault(('ne', post.md5sum), []).append(
                    (pinned, post))
            else:
                grouped.setdefault(('nd', post.email_domain), []).append(
                    (pinned, post))
        pinsandposts = None
    else:
        grouped = None
        if g.board:
            pinsandposts = []
            for post in posts:
                pinned = post.pinned
                if board is not None:
                    blink = post.link_to_board(board)
                    if blink is not None:
                        pinned = blink.pinned
                pinsandposts.append((pinned, post))
        else:
            pinsandposts = [(post.pinned, post) for post in posts]

    return render_template('index.html',
                           pinsandposts=pinsandposts,
                           grouped=grouped,
                           now=now,
                           newlimit=newlimit,
                           jobtype=type,
                           jobcategory=category,
                           title=title,
                           md5sum=md5sum,
                           domain=domain,
                           employer_name=employer_name,
                           location=location,
                           showall=showall,
                           siteadmin=lastuser.has_permission('siteadmin'))
Ejemplo n.º 19
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'))
Ejemplo n.º 20
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')
        )
Ejemplo n.º 21
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')
        )
Ejemplo n.º 22
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', []):
            abort(403)
    if post.status in [POSTSTATUS.REJECTED, POSTSTATUS.WITHDRAWN]:
        abort(410)
    reportform = forms.ReportForm()
    reportform.report_code.choices = [(ob.id, ob.title) for ob in ReportCode.query.filter_by(public=True).order_by('seq')]
    rejectform = forms.RejectForm()
    if reportform.validate_on_submit():
        report = JobPostReport(post=post, 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 job listing has been flagged for review.</p>"  # FIXME: Ugh!
        else:
            flash("Thanks! This job listing has been flagged for review.", "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, siteadmin=lastuser.has_permission('siteadmin'), webmail_domains=webmail_domains)