Beispiel #1
0
def send(objects,
         language_code,
         body_input,
         subject,
         with_localization=True,
         body_is_filename=True,
         override_dict={},
         attachment=None):
    """
    Sends an email
    Args:
        objects: a Candidate object or a list of Candidates. has fields 'name', 'email' and campaign
        language_code: eg: 'es' or 'en'
        body_input: the filename of the body content or the body itself
        subject: string with the email subject
        with_localization: Boolean indicating whether emails are translated according to browser configuration.
        body_is_filename: Boolean indicating whether the body_input is a filename or a string with content.
        override_dict: Dictionary where keys are fields and values to override the keyword behavior.
        attachment: optional param for adding attached file.
    Returns: Sends email
    """

    body_input, objects = common_senders.process_inputs(
        with_localization, language_code, body_input, objects)

    for an_object in objects:

        if isinstance(an_object, Candidate):
            params = common_senders.get_params_with_candidate(
                an_object, language_code, override_dict)
            recipients = an_object.user.email
        elif isinstance(an_object, User):
            params = common_senders.get_params_with_user(
                an_object, override_dict)
            recipients = an_object.email
        elif isinstance(an_object, BusinessUser):
            params = common_senders.get_params_with_business_user(
                an_object, override_dict)
            recipients = an_object.email
        elif isinstance(an_object, Campaign):
            params = common_senders.get_params_with_campaign(an_object)
            business_user = common.get_business_user_with_campaign(an_object)
            recipients = business_user.email
        else:
            raise NotImplementedError(
                'Unimplemented email params for class: {}'.format(
                    type(an_object)))

        body = common_senders.get_body(body_input,
                                       body_is_filename=body_is_filename)

        send_with_mailgun(recipients=recipients,
                          subject=subject.format(**params),
                          body=body.format(**params),
                          attachment=attachment)
Beispiel #2
0
def save_candidate_messages(candidates, body_input, body_is_filename,
                            language_code, override_dict, original_body_input):
    # More obscurity for very needed speed... sorry
    messages = Message.objects.bulk_create([
        Message(candidate=c,
                text=common_senders.get_body(
                    body_input, body_is_filename=body_is_filename).format(
                        **common_senders.get_params_with_candidate(
                            c, language_code, override_dict)),
                filename=original_body_input if body_is_filename else None)
        for c in candidates
    ])

    common.bulk_save(messages)
Beispiel #3
0
def save_campaign_messages(campaigns, body_input, body_is_filename,
                           language_code, override_dict):
    # More obscurity for very needed speed... sorry
    messages = CampaignMessage.objects.bulk_create([
        CampaignMessage(campaign=c,
                        text=common_senders.get_body(
                            body_input,
                            body_is_filename=body_is_filename).format(
                                **common_senders.get_params_with_campaign(
                                    c, language_code, override_dict)))
        for c in campaigns
    ])

    common.bulk_save(messages)
Beispiel #4
0
def send_report(language_code, body_filename, subject, recipients, candidates):
    """
    Sends an email
    Args:
        language_code: eg: 'es' or 'en'
        body_filename: the filename of the body content
        subject: string with the email subject
        recipients: email send to.
        candidates: QuerySet of candidates
    Returns: Sends email
    """

    if language_code != 'en':
        body_filename += '_{}'.format(language_code)

    resumes = create_nice_resumes_message(candidates)

    body = common_senders.get_body(body_filename)
    d = common_senders.get_basic_params()
    d['new_resumes'] = resumes
    body = body.format(**d)

    send_with_mailgun(recipients=recipients, subject=subject, body=body)
Beispiel #5
0
def send_internal(contact,
                  language_code,
                  body_filename,
                  subject,
                  campaign=None):
    """
    Sends an email to the internal team.
    Args:
        contact: Any object that has fields 'name' and 'email'
        language_code: eg: 'es' or 'en'
        body_filename: the filename of the body content
        subject: string with the email subject
        campaign: campaign object for mail with campaign link

    Returns: Sends email
    """

    if language_code != 'en':
        body_filename += '_{}'.format(language_code)

    try:
        message = contact.message
    except AttributeError:  # missing field
        message = ''

    body = common_senders.get_body(body_filename)
    d = common_senders.get_basic_params()
    d['message'] = message
    d['name'] = contact.name
    d['email'] = contact.email,
    d['phone'] = contact.phone,
    d['message'] = message,
    d['business_campaign_url'] = common_senders.get_business_campaign_url(
        campaign)
    body = body.format(**d)

    send_with_mailgun(recipients=INTERNAL_TEAM, subject=subject, body=body)