예제 #1
0
def send_email_report(user, now=None):    
    status = "started"
    if not now:
        now = datetime.datetime.utcnow()
    template_filler_dict = notification_report.make(user)
    db.session.merge(user)

    if template_filler_dict["cards"]:
        if os.getenv("ENVIRONMENT", "testing") == "production":
            email = user.email
        else:
            email = "*****@*****.**"
        user.last_email_sent = now

        try:
            db.session.commit()
            logger.info(u"updated user object in send_email_report for {url_slug}".format(url_slug=user.url_slug))
        except InvalidRequestError:
            logger.info(u"rollback, trying again to update user object in send_email_report for {url_slug}".format(url_slug=user.url_slug))
            db.session.rollback()
            db.session.commit()
            logger.info(u"after rollback updated user object in send_email_report for {url_slug}".format(url_slug=user.url_slug))

        msg = emailer.send(email, "Your latest research impacts", "report", template_filler_dict)
        status = "emailed"
        logger.info(u"SENT EMAIL to {url_slug}!!".format(url_slug=user.url_slug))
    else:
        status = "not emailed, no cards made"
        logger.info(u"not sending email, no cards made for {url_slug}".format(url_slug=user.url_slug))

    return status
예제 #2
0
def render_notification_report(profile_id, format="html"):
    user = get_user_for_response(
        profile_id,
        request
    )
    report_context = notification_report.make(user)
    return render_template("report.html", **report_context)
예제 #3
0
def send_email_report(profile, now=None):
    status = "started"
    if not now:
        now = datetime.datetime.utcnow()
    db.session.merge(profile)
    report = notification_report.make(profile)

    if report["cards"]:
        if os.getenv("ENVIRONMENT", "testing") == "production":
            email = profile.email
        else:
            email = "*****@*****.**"
        profile.last_email_sent = now

        try:
            db.session.commit()
        except InvalidRequestError:
            logger.info(u"rollback, trying again to update profile object in send_email_report for {url_slug}".format(url_slug=profile.url_slug))
            db.session.rollback()
            db.session.commit()

        msg = emailer.send(email, "Your latest research impacts", "report", report)
        status = "email sent"
        logger.info(u"SENT EMAIL to {url_slug}!!".format(url_slug=profile.url_slug))
    else:
        status = "not emailed, no cards made"
        # logger.info(u"not sending email, no cards made for {url_slug}".format(url_slug=profile.url_slug))

    return status