Example #1
0
def send_receipt_mail(
    order_id,
    subject="Thank you for your order!",
    template='order_confirmation_mail.html.jinja2',
):
    """Send buyer a link to fill attendee details and get cash receipt."""
    with app.test_request_context():
        order = Order.query.get(order_id)
        msg = Message(
            subject=subject,
            recipients=[order.buyer_email],
            bcc=[order.organization.contact_email],
        )
        line_items = (LineItem.query.filter(
            LineItem.order == order,
            LineItem.status == LINE_ITEM_STATUS.CONFIRMED).order_by(
                LineItem.line_item_seq.asc()).all())
        html = email_transform(
            render_template(
                template,
                order=order,
                org=order.organization,
                line_items=line_items,
                base_url=app.config['BASE_URL'],
                currency_symbol=CURRENCY_SYMBOL['INR'],
            ))
        msg.html = html
        msg.body = html2text(html)
        mail.send(msg)
Example #2
0
def send_ticket_reassignment_mail(line_item_id, old_assignee_id,
                                  new_assignee_id):
    """Send notice of reassignment of ticket."""
    with app.test_request_context():
        line_item = LineItem.query.get(line_item_id)
        order = line_item.order
        old_assignee = Assignee.query.get(old_assignee_id)
        new_assignee = Assignee.query.get(new_assignee_id)

        subject = (order.item_collection.title +
                   ": Your ticket has been transfered to someone else")
        msg = Message(subject=subject,
                      recipients=[old_assignee.email],
                      bcc=[order.buyer_email])
        html = email_transform(
            render_template(
                'ticket_reassignment_mail.html.jinja2',
                old_assignee=old_assignee,
                new_assignee=new_assignee,
                order=order,
                org=order.organization,
                line_item=line_item,
                base_url=app.config['BASE_URL'],
            ))
        msg.html = html
        msg.body = html2text(html)
        mail.send(msg)
Example #3
0
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)
Example #4
0
def send_order_refund_mail(order_id, refund_amount, note_to_user):
    with app.test_request_context():
        order = Order.query.get(order_id)
        subject = __(
            "{item_collection_title}: Refund for receipt no. {invoice_no}".
            format(
                item_collection_title=order.item_collection.title,
                invoice_no=order.invoice_no,
            ))
        msg = Message(
            subject=subject,
            recipients=[order.buyer_email],
            bcc=[order.organization.contact_email],
        )
        # Only INR is supported as of now
        html = email_transform(
            render_template(
                'order_refund_mail.html.jinja2',
                base_url=app.config['BASE_URL'],
                order=order,
                org=order.organization,
                note_to_user=note_to_user.html,
                refund_amount=refund_amount,
                currency_symbol=CURRENCY_SYMBOL['INR'],
            ))
        msg.html = html
        msg.body = html2text(html)
        mail.send(msg)
Example #5
0
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)
Example #6
0
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()
        # 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', post=post, moderateform=moderateform)
    return redirect(post.url_for(), code=303)
Example #7
0
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)
Example #8
0
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)
Example #9
0
def send_line_item_cancellation_mail(line_item_id,
                                     refund_amount,
                                     subject="Ticket Cancellation"):
    with app.test_request_context():
        line_item = LineItem.query.get(line_item_id)
        item_title = line_item.item.title
        order = line_item.order
        is_paid = line_item.final_amount > Decimal('0')
        msg = Message(
            subject=subject,
            recipients=[order.buyer_email],
            bcc=[order.organization.contact_email],
        )
        # Only INR is supported as of now
        html = email_transform(
            render_template(
                'line_item_cancellation_mail.html.jinja2',
                base_url=app.config['BASE_URL'],
                order=order,
                line_item=line_item,
                item_title=item_title,
                org=order.organization,
                is_paid=is_paid,
                refund_amount=refund_amount,
                currency_symbol=CURRENCY_SYMBOL['INR'],
            ))
        msg.html = html
        msg.body = html2text(html)
        mail.send(msg)
Example #10
0
def send_participant_assignment_mail(order_id, item_collection_title, team_member, subject="Please tell us who's coming!"):
    with app.test_request_context():
        order = Order.query.get(order_id)
        msg = Message(subject=subject, recipients=[order.buyer_email], bcc=[order.organization.contact_email])
        html = email_transform(render_template('participant_assignment_mail.html', base_url=app.config['BASE_URL'], order=order, org=order.organization, item_collection_title=item_collection_title, team_member=team_member))
        msg.html = html
        msg.body = html2text(html)
        mail.send(msg)
Example #11
0
def send_participant_assignment_mail(order_id, item_collection_title, team_member, subject="Please tell us who's coming!"):
    with app.test_request_context():
        order = Order.query.get(order_id)
        msg = Message(subject=subject, recipients=[order.buyer_email], bcc=[order.organization.contact_email])
        html = email_transform(render_template('participant_assignment_mail.html.jinja2', base_url=app.config['BASE_URL'], order=order, org=order.organization, item_collection_title=item_collection_title, team_member=team_member))
        msg.html = html
        msg.body = html2text(html)
        mail.send(msg)
Example #12
0
def send_confirmation_mail(order_id, subject="Thank you for your order!"):
    """Sends a order confirmation email to the buyer, and CC's it to the organization's contact email."""
    with app.test_request_context():
        order = Order.query.get(order_id)
        msg = Message(subject=subject, recipients=[order.buyer_email], bcc=[order.organization.contact_email])
        html = email_transform(render_template('order_confirmation_mail.html.jinja2', order=order, org=order.organization, line_items=order.line_items, base_url=app.config['BASE_URL']))
        msg.html = html
        msg.body = html2text(html)
        mail.send(msg)
def send_receipt_email(order_id, subject="Thank you for your order!"):
    """
    Sends an link to fill attendee details and cash receipt to the order's buyer
    """
    with app.test_request_context():
        order = Order.query.get(order_id)
        msg = Message(subject=subject, recipients=[order.buyer_email], bcc=[order.organization.contact_email])
        line_items = LineItem.query.filter(LineItem.order == order, LineItem.status == LINE_ITEM_STATUS.CONFIRMED).order_by("line_item_seq asc").all()
        html = email_transform(render_template('attendee_assigment.html', order=order, org=order.organization, line_items=line_items, base_url=app.config['BASE_URL']))
        msg.html = html
        msg.body = html2text(html)
        mail.send(msg)
Example #14
0
def render_preview(campaign, text):
    if campaign.stylesheet is not None and campaign.stylesheet.strip():
        stylesheet = u'<style type="text/css">%s</style>\n' % escape(campaign.stylesheet)
    else:
        stylesheet = u''
    if text:
        # email_transform uses LXML, which does not like empty strings
        return email_transform(
            Markup(stylesheet) + markdown(text, html=True, valid_tags=EMAIL_TAGS),
            base_url=request.url_root)
    else:
        return u''
Example #15
0
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)
Example #16
0
def send_ticket_assignment_mail(line_item_id):
    """
    Sends a confirmation email once details are filled and ticket has been assigned.
    """
    with app.test_request_context():
        line_item = LineItem.query.get(line_item_id)
        order = line_item.order
        subject = order.item_collection.title + ": Here's your ticket"
        msg = Message(subject=subject, recipients=[line_item.current_assignee.email], bcc=[order.buyer_email])
        html = email_transform(render_template('ticket_assignment_mail.html', order=order, org=order.organization, line_item=line_item, base_url=app.config['BASE_URL']))
        msg.html = html
        msg.body = html2text(html)
        mail.send(msg)
Example #17
0
def send_ticket_assignment_mail(line_item_id):
    """
    Sends a confirmation email once details are filled and ticket has been assigned.
    """
    with app.test_request_context():
        line_item = LineItem.query.get(line_item_id)
        order = line_item.order
        subject = order.item_collection.title + ": Here's your ticket"
        msg = Message(subject=subject, recipients=[line_item.current_assignee.email], bcc=[order.buyer_email])
        html = email_transform(render_template('ticket_assignment_mail.html.jinja2', order=order, org=order.organization, line_item=line_item, base_url=app.config['BASE_URL']))
        msg.html = html
        msg.body = html2text(html)
        mail.send(msg)
Example #18
0
def send_receipt_mail(order_id, subject="Thank you for your order!", template='order_confirmation_mail.html.jinja2'):
    """
    Sends an link to fill attendee details and cash receipt to the order's buyer
    """
    with app.test_request_context():
        order = Order.query.get(order_id)
        msg = Message(subject=subject, recipients=[order.buyer_email], bcc=[order.organization.contact_email])
        line_items = LineItem.query.filter(LineItem.order == order, LineItem.status == LINE_ITEM_STATUS.CONFIRMED).order_by("line_item_seq asc").all()
        html = email_transform(render_template(template, order=order, org=order.organization,
            line_items=line_items, base_url=app.config['BASE_URL']))
        msg.html = html
        msg.body = html2text(html)
        mail.send(msg)
Example #19
0
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)
Example #20
0
def send_line_item_cancellation_mail(line_item_id, refund_amount, subject="Ticket Cancellation"):
    with app.test_request_context():
        line_item = LineItem.query.get(line_item_id)
        item_title = line_item.item.title
        order = line_item.order
        is_paid = line_item.final_amount > Decimal('0')
        msg = Message(subject=subject, recipients=[order.buyer_email], bcc=[order.organization.contact_email])
        # Only INR is supported as of now
        html = email_transform(render_template('line_item_cancellation_mail.html',
            base_url=app.config['BASE_URL'],
            order=order, line_item=line_item, item_title=item_title, org=order.organization, is_paid=is_paid,
            refund_amount=refund_amount, currency_symbol=CURRENCY_SYMBOL['INR']))
        msg.html = html
        msg.body = html2text(html)
        mail.send(msg)
Example #21
0
 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)
Example #22
0
 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)
Example #23
0
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)
Example #24
0
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)
Example #25
0
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)
Example #26
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)
Example #27
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)
Example #28
0
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)
Example #29
0
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)
Example #30
0
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)
Example #31
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)