Exemple #1
0
def send_publication_email(aid_id):
    """
    Sends an email when an aid gets published.
    """
    if not settings.SIB_PUBLICATION_EMAIL_ENABLED:
        return

    Aid = apps.get_model('aids.Aid')
    aid = Aid.objects.get(pk=aid_id)
    author = aid.author
    site = Site.objects.get_current()
    base_url = 'https://{}'.format(site.domain)
    data = {
        'PRENOM': author.first_name,
        'NOM': author.last_name,
        'AIDE_NOM': aid.name,
        'AIDE_URL': aid.get_absolute_url(),
        'BASE_URL': base_url,
    }
    send_email_with_template(
        recipient_list=[author.email],
        template_id=settings.SIB_PUBLICATION_EMAIL_TEMPLATE_ID,
        data=data,
        tags=['publication', settings.ENV_NAME],
        fail_silently=True)
Exemple #2
0
def send_alert_confirmation_email(user_email, alert_token):
    """Send an alert confirmation link to the user.

    The email contains a token that can be used to validate the
    email ownership.
    """
    try:
        alert = Alert.objects.get(token=alert_token)
    except (Alert.DoesNotExist):
        # In case we could not find any valid user with the given email
        # we don't raise any exception, because we can't give any hints
        # about whether or not any particular email has an account
        # on our site.
        return

    # Use the search form to parse the search querydict and
    # extract the perimeter
    querydict = QueryDict(alert.querystring)
    search_form = AidSearchForm(querydict)
    perimeter = ''
    if search_form.is_valid():
        perimeter = search_form.cleaned_data.get('perimeter') or ''
        perimeter = str(perimeter)

    base_url = get_base_url()
    alert_validation_link = reverse('alert_validate_view', args=[alert_token])
    alert_date = '{:%d/%m/%Y %H:%M:%S}'.format(alert.date_created)

    if alert.alert_frequency == Alert.FREQUENCIES.daily:
        frequency = 'quotidien'
    else:
        frequency = 'hebdomadaire'

    data = {
        'URL_SITE': base_url,
        'FREQUENCE': frequency,
        'PERIMETRE': perimeter,
        'DATE_ALERTE': alert_date,
        'LIEN_VALIDATION': '{}{}'.format(base_url, alert_validation_link)
    }

    send_email_with_template(
        recipient_list=[user_email],
        template_id=settings.SIB_ALERT_CONFIRMATION_EMAIL_TEMPLATE_ID,
        data=data,
        tags=['alerte_confirmation', settings.ENV_NAME],
        fail_silently=False)
Exemple #3
0
def send_welcome_email(user_email):
    """Send a welcome email to the user.

    This email is actually stored as a template in the ESP's dashboard,
    and can be modified by the bizdev team.

    Hence we don't define any email body ourselves.
    """
    if not settings.SIB_WELCOME_EMAIL_ENABLED:
        return

    user = User.objects.get(email=user_email)
    data = {
        'PRENOM': user.first_name,
        'NOM': user.last_name,
    }
    send_email_with_template(
        recipient_list=[user_email],
        template_id=settings.SIB_WELCOME_EMAIL_TEMPLATE_ID,
        data=data,
        tags=['bienvenue', settings.ENV_NAME],
        fail_silently=True)