示例#1
0
文件: utils.py 项目: lDDii/ecommerce
def send_assigned_offer_email(
        template,
        offer_assignment_id,
        learner_email,
        code,
        redemptions_remaining,
        code_expiration_date):
    """
    Arguments:
        *template*
            The email template with placeholders that will receive the following tokens
        *offer_assignment_id*
            Primary key of the entry in the offer_assignment model.
        *learner_email*
            Email of the customer who will receive the code.
        *code*
            Code for the user.
        *redemptions_remaining*
            Number of times the code can be redeemed.
        *code_expiration_date*
            Date till code is valid.
    """

    email_subject = settings.OFFER_ASSIGNMENT_EMAIL_DEFAULT_SUBJECT
    email_body = template.format(
        REDEMPTIONS_REMAINING=redemptions_remaining,
        USER_EMAIL=learner_email,
        CODE=code,
        EXPIRATION_DATE=code_expiration_date
    )
    send_offer_assignment_email.delay(learner_email, offer_assignment_id, email_subject, email_body)
示例#2
0
def send_assigned_offer_email(greeting, closing, offer_assignment_id,
                              learner_email, code, redemptions_remaining,
                              code_expiration_date):
    """
    Arguments:
        *email_greeting*
            The email greeting (prefix)
        *email_closing*
            The email closing (suffix)
        *offer_assignment_id*
            Primary key of the entry in the offer_assignment model.
        *learner_email*
            Email of the customer who will receive the code.
        *code*
            Code for the user.
        *redemptions_remaining*
            Number of times the code can be redeemed.
        *code_expiration_date*
            Date till code is valid.
    """

    email_subject = settings.OFFER_ASSIGNMENT_EMAIL_SUBJECT
    email_template = settings.OFFER_ASSIGNMENT_EMAIL_TEMPLATE
    placeholder_dict = SafeDict(REDEMPTIONS_REMAINING=redemptions_remaining,
                                USER_EMAIL=learner_email,
                                CODE=code,
                                EXPIRATION_DATE=code_expiration_date)
    email_body = format_email(email_template, placeholder_dict, greeting,
                              closing)
    send_offer_assignment_email.delay(learner_email, offer_assignment_id,
                                      email_subject, email_body)
示例#3
0
def send_assigned_offer_email(subject,
                              greeting,
                              closing,
                              offer_assignment_id,
                              learner_email,
                              code,
                              redemptions_remaining,
                              code_expiration_date,
                              base_enterprise_url=''):
    """
    Arguments:
        *subject*
            The email subject
        *email_greeting*
            The email greeting (prefix)
        *email_closing*
            The email closing (suffix)
        *offer_assignment_id*
            Primary key of the entry in the offer_assignment model.
        *learner_email*
            Email of the customer who will receive the code.
        *code*
            Code for the user.
        *redemptions_remaining*
            Number of times the code can be redeemed.
        *code_expiration_date*
            Date till code is valid.
    """
    email_body = format_assigned_offer_email(greeting, closing, learner_email,
                                             code, redemptions_remaining,
                                             code_expiration_date)
    send_offer_assignment_email.delay(learner_email, offer_assignment_id,
                                      subject, email_body, None,
                                      base_enterprise_url)
示例#4
0
def send_assigned_offer_email(
        subject,
        greeting,
        closing,
        offer_assignment_id,
        learner_email,
        code,
        redemptions_remaining,
        code_expiration_date,
        sender_alias,
        base_enterprise_url=''):
    """
    Arguments:
        *subject*
            The email subject
        *email_greeting*
            The email greeting (prefix)
        *email_closing*
            The email closing (suffix)
        *offer_assignment_id*
            Primary key of the entry in the offer_assignment model.
        *learner_email*
            Email of the customer who will receive the code.
        *code*
            Code for the user.
        *redemptions_remaining*
            Number of times the code can be redeemed.
        *code_expiration_date*
            Date till code is valid.
    """
    email_body = format_assigned_offer_email(
        greeting,
        closing,
        learner_email,
        code,
        redemptions_remaining,
        code_expiration_date,
        base_enterprise_url
    )

    if settings.DEBUG:  # pragma: no cover
        # Avoid breaking devstack when no such service is available.
        logger.warning("Skipping Sailthru task 'send_offer_assignment_email' because DEBUG=true.")  # pragma: no cover
        return  # pragma: no cover

    send_offer_assignment_email.delay(learner_email, offer_assignment_id, subject, email_body, sender_alias, None,
                                      base_enterprise_url)
示例#5
0
def send_assigned_offer_email(template, offer_assignment_id, learner_email,
                              code, enrollment_url, redemptions_remaining,
                              code_expiration_date):
    """
    Arguments:
        *template*
            The email template with placeholders that will receive the following tokens
        *offer_assignment_id*
            Primary key of the entry in the offer_assignment model.
        *learner_email*
            Email of the customer who will receive the code.
        *code*
            Code for the user.
        *enrollment_url*
            URL for the user.
        *redemptions_remaining*
            Number of times the code can be redeemed.
        *code_expiration_date*
            Date till code is valid.

    Returns:
         True when successful or False in case of any exception
    """

    email_subject = settings.OFFER_ASSIGNMENT_EMAIL_DEFAULT_SUBJECT
    try:
        email_body = template.format(
            REDEMPTIONS_REMAINING=redemptions_remaining,
            USER_EMAIL=learner_email,
            ENROLLMENT_URL=enrollment_url,
            CODE=code,
            EXPIRATION_DATE=code_expiration_date)
        send_offer_assignment_email.delay(learner_email, offer_assignment_id,
                                          email_subject, email_body)
    except Exception as exc:  # pylint: disable=broad-except
        logger.exception(
            '[Offer Assignment] send_offer_assignment_email celery task raised: %r',
            exc)
        return False
    return True