forked from DGNum/gestioCOF
Supprime render_template
GestioCOF définit une fonction `render_template` qui permet de calculer l'interpolation d'un gabarit en une chaîne de caractères, par exemple pour l'envoi de mails. Ce patch supprime cette fonction et remplace son utilisation par la fonction `django.template.loader.render_to_string` au comportement identique.
This commit is contained in:
parent
a55d34380c
commit
1f1419c5f1
3 changed files with 29 additions and 36 deletions
|
@ -11,19 +11,13 @@ from datetime import timedelta
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.template import loader, Context
|
from django.template import loader
|
||||||
from django.core import mail
|
from django.core import mail
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
|
||||||
|
|
||||||
def render_template(template_name, data):
|
|
||||||
tmpl = loader.get_template(template_name)
|
|
||||||
ctxt = Context(data)
|
|
||||||
return tmpl.render(ctxt)
|
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Tirage(models.Model):
|
class Tirage(models.Model):
|
||||||
title = models.CharField("Titre", max_length=300)
|
title = models.CharField("Titre", max_length=300)
|
||||||
|
@ -117,7 +111,7 @@ class Spectacle(models.Model):
|
||||||
mail_object = "%s - %s - %s" % (self.title, self.date_no_seconds(),
|
mail_object = "%s - %s - %s" % (self.title, self.date_no_seconds(),
|
||||||
self.location)
|
self.location)
|
||||||
for member in members.values():
|
for member in members.values():
|
||||||
mail_body = render_template('mail-rappel.txt', {
|
mail_body = loader.render_to_string('mail-rappel.txt', {
|
||||||
'name': member[0],
|
'name': member[0],
|
||||||
'nb_attr': member[1],
|
'nb_attr': member[1],
|
||||||
'show': self})
|
'show': self})
|
||||||
|
@ -277,7 +271,7 @@ class SpectacleRevente(models.Model):
|
||||||
mails_to_send = []
|
mails_to_send = []
|
||||||
mail_object = "%s" % (self.attribution.spectacle)
|
mail_object = "%s" % (self.attribution.spectacle)
|
||||||
for participant in inscrits:
|
for participant in inscrits:
|
||||||
mail_body = render_template('mail-revente.txt', {
|
mail_body = loader.render_to_string('mail-revente.txt', {
|
||||||
'user': participant.user,
|
'user': participant.user,
|
||||||
'spectacle': self.attribution.spectacle,
|
'spectacle': self.attribution.spectacle,
|
||||||
'revente': self,
|
'revente': self,
|
||||||
|
@ -301,7 +295,7 @@ class SpectacleRevente(models.Model):
|
||||||
mails_to_send = []
|
mails_to_send = []
|
||||||
mail_object = "%s" % (self.attribution.spectacle)
|
mail_object = "%s" % (self.attribution.spectacle)
|
||||||
for participant in inscrits:
|
for participant in inscrits:
|
||||||
mail_body = render_template('mail-shotgun.txt', {
|
mail_body = loader.render_to_string('mail-shotgun.txt', {
|
||||||
'user': participant.user,
|
'user': participant.user,
|
||||||
'spectacle': self.attribution.spectacle,
|
'spectacle': self.attribution.spectacle,
|
||||||
'domain': Site.objects.get_current(),
|
'domain': Site.objects.get_current(),
|
||||||
|
@ -337,13 +331,15 @@ class SpectacleRevente(models.Model):
|
||||||
'spectacle': spectacle,
|
'spectacle': spectacle,
|
||||||
}
|
}
|
||||||
mails.append(mail.EmailMessage(
|
mails.append(mail.EmailMessage(
|
||||||
mail_subject, loader.render_to_string('mail-revente-winner.txt', context),
|
mail_subject,
|
||||||
|
loader.render_to_string('mail-revente-winner.txt', context),
|
||||||
from_email=settings.MAIL_DATA['revente']['FROM'],
|
from_email=settings.MAIL_DATA['revente']['FROM'],
|
||||||
to=[winner.user.email],
|
to=[winner.user.email],
|
||||||
reply_to=[seller.user.email],
|
reply_to=[seller.user.email],
|
||||||
))
|
))
|
||||||
mails.append(mail.EmailMessage(
|
mails.append(mail.EmailMessage(
|
||||||
mail_subject, loader.render_to_string('mail-revente-seller.txt', context),
|
mail_subject,
|
||||||
|
loader.render_to_string('mail-revente-seller.txt', context),
|
||||||
from_email=settings.MAIL_DATA['revente']['FROM'],
|
from_email=settings.MAIL_DATA['revente']['FROM'],
|
||||||
to=[seller.user.email],
|
to=[seller.user.email],
|
||||||
reply_to=[winner.user.email],
|
reply_to=[winner.user.email],
|
||||||
|
|
|
@ -27,7 +27,7 @@ from datetime import timedelta
|
||||||
|
|
||||||
from gestioncof.decorators import cof_required, buro_required
|
from gestioncof.decorators import cof_required, buro_required
|
||||||
from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\
|
from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\
|
||||||
Tirage, render_template, SpectacleRevente
|
Tirage, SpectacleRevente
|
||||||
from bda.algorithm import Algorithm
|
from bda.algorithm import Algorithm
|
||||||
|
|
||||||
from bda.forms import BaseBdaFormSet, TokenForm, ResellForm, AnnulForm,\
|
from bda.forms import BaseBdaFormSet, TokenForm, ResellForm, AnnulForm,\
|
||||||
|
@ -571,11 +571,11 @@ def send_rappel(request, spectacle_id):
|
||||||
# Mails d'exemples
|
# Mails d'exemples
|
||||||
fake_member = request.user
|
fake_member = request.user
|
||||||
fake_member.nb_attr = 1
|
fake_member.nb_attr = 1
|
||||||
exemple_mail_1place = render_template('mail-rappel.txt', {
|
exemple_mail_1place = loader.render_to_string('mail-rappel.txt', {
|
||||||
'member': fake_member,
|
'member': fake_member,
|
||||||
'show': show})
|
'show': show})
|
||||||
fake_member.nb_attr = 2
|
fake_member.nb_attr = 2
|
||||||
exemple_mail_2places = render_template('mail-rappel.txt', {
|
exemple_mail_2places = loader.render_to_string('mail-rappel.txt', {
|
||||||
'member': fake_member,
|
'member': fake_member,
|
||||||
'show': show})
|
'show': show})
|
||||||
# Contexte
|
# Contexte
|
||||||
|
|
|
@ -14,7 +14,7 @@ from django.contrib.auth.models import User
|
||||||
from django.views.generic import ListView
|
from django.views.generic import ListView
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.template import loader, Context
|
from django.template import loader
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.db.models import Min
|
from django.db.models import Min
|
||||||
|
@ -33,12 +33,6 @@ import base64
|
||||||
import simplejson
|
import simplejson
|
||||||
|
|
||||||
|
|
||||||
def render_template(template_path, data):
|
|
||||||
tmpl = loader.get_template(template_path)
|
|
||||||
context = Context(data)
|
|
||||||
return tmpl.render(context)
|
|
||||||
|
|
||||||
|
|
||||||
class DemandeListView(ListView):
|
class DemandeListView(ListView):
|
||||||
model = PetitCoursDemande
|
model = PetitCoursDemande
|
||||||
template_name = "petits_cours_demandes_list.html"
|
template_name = "petits_cours_demandes_list.html"
|
||||||
|
@ -137,14 +131,14 @@ def _finalize_traitement(request, demande, proposals, proposed_for,
|
||||||
proposed_for = proposed_for.items()
|
proposed_for = proposed_for.items()
|
||||||
attribdata = list(attribdata.items())
|
attribdata = list(attribdata.items())
|
||||||
proposed_mails = _generate_eleve_email(demande, proposed_for)
|
proposed_mails = _generate_eleve_email(demande, proposed_for)
|
||||||
mainmail = render_template("petits-cours-mail-demandeur.txt",
|
mainmail = loader.render_to_string("petits-cours-mail-demandeur.txt", {
|
||||||
{"proposals": proposals,
|
"proposals": proposals,
|
||||||
"unsatisfied": unsatisfied,
|
"unsatisfied": unsatisfied,
|
||||||
"extra":
|
"extra":
|
||||||
'<textarea name="extra" '
|
'<textarea name="extra" '
|
||||||
'style="width:99%; height: 90px;">'
|
'style="width:99%; height: 90px;">'
|
||||||
'</textarea>'
|
'</textarea>'
|
||||||
})
|
})
|
||||||
return render(request, "traitement_demande_petit_cours.html",
|
return render(request, "traitement_demande_petit_cours.html",
|
||||||
{"demande": demande,
|
{"demande": demande,
|
||||||
"unsatisfied": unsatisfied,
|
"unsatisfied": unsatisfied,
|
||||||
|
@ -163,8 +157,10 @@ def _finalize_traitement(request, demande, proposals, proposed_for,
|
||||||
def _generate_eleve_email(demande, proposed_for):
|
def _generate_eleve_email(demande, proposed_for):
|
||||||
proposed_mails = []
|
proposed_mails = []
|
||||||
for user, matieres in proposed_for:
|
for user, matieres in proposed_for:
|
||||||
msg = render_template("petits-cours-mail-eleve.txt",
|
msg = loader.render_to_string("petits-cours-mail-eleve.txt", {
|
||||||
{"demande": demande, "matieres": matieres})
|
"demande": demande,
|
||||||
|
"matieres": matieres
|
||||||
|
})
|
||||||
proposed_mails.append((user, msg))
|
proposed_mails.append((user, msg))
|
||||||
return proposed_mails
|
return proposed_mails
|
||||||
|
|
||||||
|
@ -278,10 +274,11 @@ def _traitement_post(request, demande):
|
||||||
proposals_list = proposals.items()
|
proposals_list = proposals.items()
|
||||||
proposed_for = proposed_for.items()
|
proposed_for = proposed_for.items()
|
||||||
proposed_mails = _generate_eleve_email(demande, proposed_for)
|
proposed_mails = _generate_eleve_email(demande, proposed_for)
|
||||||
mainmail = render_template("petits-cours-mail-demandeur.txt",
|
mainmail = loader.render_to_string("petits-cours-mail-demandeur.txt", {
|
||||||
{"proposals": proposals_list,
|
"proposals": proposals_list,
|
||||||
"unsatisfied": unsatisfied,
|
"unsatisfied": unsatisfied,
|
||||||
"extra": extra})
|
"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']
|
||||||
replyto = settings.MAIL_DATA['petits_cours']['REPLYTO']
|
replyto = settings.MAIL_DATA['petits_cours']['REPLYTO']
|
||||||
|
|
Loading…
Reference in a new issue