diff --git a/bda/models.py b/bda/models.py
index 6fb22189..41550507 100644
--- a/bda/models.py
+++ b/bda/models.py
@@ -11,19 +11,13 @@ from datetime import timedelta
from django.contrib.sites.models import Site
from django.db import models
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.conf import settings
from django.utils import timezone
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
class Tirage(models.Model):
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(),
self.location)
for member in members.values():
- mail_body = render_template('mail-rappel.txt', {
+ mail_body = loader.render_to_string('mail-rappel.txt', {
'name': member[0],
'nb_attr': member[1],
'show': self})
@@ -277,7 +271,7 @@ class SpectacleRevente(models.Model):
mails_to_send = []
mail_object = "%s" % (self.attribution.spectacle)
for participant in inscrits:
- mail_body = render_template('mail-revente.txt', {
+ mail_body = loader.render_to_string('mail-revente.txt', {
'user': participant.user,
'spectacle': self.attribution.spectacle,
'revente': self,
@@ -301,7 +295,7 @@ class SpectacleRevente(models.Model):
mails_to_send = []
mail_object = "%s" % (self.attribution.spectacle)
for participant in inscrits:
- mail_body = render_template('mail-shotgun.txt', {
+ mail_body = loader.render_to_string('mail-shotgun.txt', {
'user': participant.user,
'spectacle': self.attribution.spectacle,
'domain': Site.objects.get_current(),
@@ -337,13 +331,15 @@ class SpectacleRevente(models.Model):
'spectacle': spectacle,
}
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'],
to=[winner.user.email],
reply_to=[seller.user.email],
))
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'],
to=[seller.user.email],
reply_to=[winner.user.email],
diff --git a/bda/views.py b/bda/views.py
index 8beeb84b..ddc0596e 100644
--- a/bda/views.py
+++ b/bda/views.py
@@ -27,7 +27,7 @@ from datetime import timedelta
from gestioncof.decorators import cof_required, buro_required
from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\
- Tirage, render_template, SpectacleRevente
+ Tirage, SpectacleRevente
from bda.algorithm import Algorithm
from bda.forms import BaseBdaFormSet, TokenForm, ResellForm, AnnulForm,\
@@ -571,11 +571,11 @@ def send_rappel(request, spectacle_id):
# Mails d'exemples
fake_member = request.user
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,
'show': show})
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,
'show': show})
# Contexte
diff --git a/gestioncof/petits_cours_views.py b/gestioncof/petits_cours_views.py
index e9fe511e..d49e942f 100644
--- a/gestioncof/petits_cours_views.py
+++ b/gestioncof/petits_cours_views.py
@@ -14,7 +14,7 @@ from django.contrib.auth.models import User
from django.views.generic import ListView
from django.utils.decorators import method_decorator
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.contrib.auth.decorators import login_required
from django.db.models import Min
@@ -33,12 +33,6 @@ import base64
import simplejson
-def render_template(template_path, data):
- tmpl = loader.get_template(template_path)
- context = Context(data)
- return tmpl.render(context)
-
-
class DemandeListView(ListView):
model = PetitCoursDemande
template_name = "petits_cours_demandes_list.html"
@@ -137,14 +131,14 @@ def _finalize_traitement(request, demande, proposals, proposed_for,
proposed_for = proposed_for.items()
attribdata = list(attribdata.items())
proposed_mails = _generate_eleve_email(demande, proposed_for)
- mainmail = render_template("petits-cours-mail-demandeur.txt",
- {"proposals": proposals,
- "unsatisfied": unsatisfied,
- "extra":
- ''
- })
+ mainmail = loader.render_to_string("petits-cours-mail-demandeur.txt", {
+ "proposals": proposals,
+ "unsatisfied": unsatisfied,
+ "extra":
+ ''
+ })
return render(request, "traitement_demande_petit_cours.html",
{"demande": demande,
"unsatisfied": unsatisfied,
@@ -163,8 +157,10 @@ def _finalize_traitement(request, demande, proposals, proposed_for,
def _generate_eleve_email(demande, proposed_for):
proposed_mails = []
for user, matieres in proposed_for:
- msg = render_template("petits-cours-mail-eleve.txt",
- {"demande": demande, "matieres": matieres})
+ msg = loader.render_to_string("petits-cours-mail-eleve.txt", {
+ "demande": demande,
+ "matieres": matieres
+ })
proposed_mails.append((user, msg))
return proposed_mails
@@ -278,10 +274,11 @@ def _traitement_post(request, demande):
proposals_list = proposals.items()
proposed_for = proposed_for.items()
proposed_mails = _generate_eleve_email(demande, proposed_for)
- mainmail = render_template("petits-cours-mail-demandeur.txt",
- {"proposals": proposals_list,
- "unsatisfied": unsatisfied,
- "extra": extra})
+ mainmail = loader.render_to_string("petits-cours-mail-demandeur.txt", {
+ "proposals": proposals_list,
+ "unsatisfied": unsatisfied,
+ "extra": extra,
+ })
frommail = settings.MAIL_DATA['petits_cours']['FROM']
bccaddress = settings.MAIL_DATA['petits_cours']['BCC']
replyto = settings.MAIL_DATA['petits_cours']['REPLYTO']