feat(organisations): notifie par email à la création

pull/22/head
Antoine Barlet 2019-02-27 12:20:26 +01:00 commité par Jérôme Lebleu
Parent 543ee88e90
révision 16fb311a96
4 fichiers modifiés avec 39 ajouts et 0 suppressions

Voir le fichier

@ -60,6 +60,9 @@
# /!\ Required in production.
#DEFAULT_FROM_EMAIL=webmaster@example.org
# Email used for notifications (eg. new organisation created).
#NOTIFICATION_EMAIL=webmaster@example.org
# URL prefix on which the application is served.
#
# This is used to generate the static and media URLs, but also links to the

Voir le fichier

@ -1,4 +1,7 @@
from django.views.generic import DetailView, ListView, CreateView
from django.conf import settings
from django.template.loader import render_to_string
from django.core.mail import send_mail
from .forms import OrganisationForm, OrganisationFilterForm
from .models import Organisation
@ -30,3 +33,24 @@ class OrganisationListView(ListView):
class OrganisationCreateView(CreateView):
form_class = OrganisationForm
model = Organisation
def form_valid(self, form):
redirect_url = super().form_valid(form)
self.send_mail_organisation_created()
return redirect_url
def send_mail_organisation_created(self):
organisation = self.object
context = {
'organisation': organisation,
'created_from': "depuis le formulaire en ligne",
'organisation_link': self.request.build_absolute_uri(
organisation.get_absolute_url()),
}
subject = "Nouvelle organisation sur la plateforme CDESS62"
message = render_to_string(
'organisations/email_organisation_created.txt', context)
send_mail(
subject, message, settings.DEFAULT_FROM_EMAIL,
[settings.NOTIFICATIONS_EMAIL],
)

Voir le fichier

@ -271,3 +271,5 @@ LOCATION_FIELD = {
'map.provider': 'openstreetmap',
'search.provider': 'nominatim',
}
NOTIFICATIONS_EMAIL = env('NOTIFICATIONS_EMAIL', default='tech@cliss21.com')

Voir le fichier

@ -0,0 +1,10 @@
Une nouvelle organisation sur la plateforme CDESS62 a été créée {{ created_from }} :
Nom : {{ organisation.nom }}
adresse : {{ organisation.rue }}, {{ organisation.code_postal }} {{ organisation.ville }}
activité principale : {{ organisation.activite_principale }}
Vous pouvez visualiser la fiche de cette organisation à l'adresse suivante (vous pouvez la copier/coller dans votre navigateur web) :
{{ organisation_link }}
----------------------------------
Ce courriel a été envoyé automatiquement. Vous le recevez car vous êtes inscrit-e-s en tant que destinataire des alertes de la plateforme CDESS62.