Phase out custommail in petitscours

This commit is contained in:
Ludovic Stephan 2020-09-15 11:47:28 +02:00
parent eb3cba31a7
commit edf6a03bc4

View file

@ -1,6 +1,5 @@
import json import json
from custommail.shortcuts import render_custom_mail
from django.conf import settings from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
@ -8,6 +7,7 @@ from django.contrib.auth.models import User
from django.core import mail from django.core import mail
from django.db import transaction from django.db import transaction
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from django.template import loader
from django.utils import timezone from django.utils import timezone
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.generic import DetailView, ListView from django.views.generic import DetailView, ListView
@ -70,15 +70,18 @@ def _finalize_traitement(
proposed_for.setdefault(user, []).append(matiere) proposed_for.setdefault(user, []).append(matiere)
proposed_mails = _generate_eleve_email(demande, proposed_for) proposed_mails = _generate_eleve_email(demande, proposed_for)
mainmail = render_custom_mail( mainmail = (
"petits-cours-mail-demandeur", "Cours particuliers ENS",
{ loader.render_to_string(
"proposals": proposals.items(), "petitscours/mails/demandeur.txt",
"unsatisfied": unsatisfied, context={
"extra": '<textarea name="extra" ' "proposals": proposals.items(),
'style="width:99%; height: 90px;">' "unsatisfied": unsatisfied,
"</textarea>", "extra": '<textarea name="extra" '
}, 'style="width:99%; height: 90px;">'
"</textarea>",
},
),
) )
if errors is not None: if errors is not None:
for error in errors: for error in errors:
@ -100,11 +103,16 @@ def _finalize_traitement(
def _generate_eleve_email(demande, proposed_for): def _generate_eleve_email(demande, proposed_for):
subject = "Petits cours ENS par le COF"
return [ return [
( (
user, user,
render_custom_mail( (
"petit-cours-mail-eleve", {"demande": demande, "matieres": matieres} subject,
loader.render_to_string(
"petitscours/mails/eleve.txt",
context={"demande": demande, "matieres": matieres},
),
), ),
) )
for user, matieres in proposed_for.items() for user, matieres in proposed_for.items()
@ -197,9 +205,14 @@ def _traitement_post(request, demande):
else: else:
proposed_for[user].append(matiere) proposed_for[user].append(matiere)
proposed_mails = _generate_eleve_email(demande, proposed_for) proposed_mails = _generate_eleve_email(demande, proposed_for)
mainmail_object, mainmail_body = render_custom_mail( mainmail_object = "Cours particuliers ENS"
"petits-cours-mail-demandeur", mainmail_body = loader.render_to_string(
{"proposals": proposals.items(), "unsatisfied": unsatisfied, "extra": extra}, "petitscours/mails/demandeur.txt",
context={
"proposals": proposals.items(),
"unsatisfied": unsatisfied,
"extra": extra,
},
) )
frommail = settings.MAIL_DATA["petits_cours"]["FROM"] frommail = settings.MAIL_DATA["petits_cours"]["FROM"]
bccaddress = settings.MAIL_DATA["petits_cours"]["BCC"] bccaddress = settings.MAIL_DATA["petits_cours"]["BCC"]