From df296d479c3cba541259b0e142b7e6388cf84da0 Mon Sep 17 00:00:00 2001 From: Hugo Levy-Falk Date: Sun, 1 Sep 2019 23:25:41 +0200 Subject: [PATCH] Context is deprecated for rendering in Django1.11 --- cotisations/tex.py | 3 +-- tickets/models.py | 4 ++-- users/models.py | 18 ++++++++++-------- users/widgets.py | 6 +++--- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/cotisations/tex.py b/cotisations/tex.py index 1ab964ba..d843049b 100644 --- a/cotisations/tex.py +++ b/cotisations/tex.py @@ -33,7 +33,6 @@ from datetime import datetime from django.db import models from django.template.loader import get_template -from django.template import Context from django.http import HttpResponse from django.conf import settings from django.utils.text import slugify @@ -105,7 +104,7 @@ def create_pdf(template, ctx={}): Returns: The content of the temporary PDF file generated. """ - context = Context(ctx) + context = ctx template = get_template(template) rendered_tpl = template.render(context).encode('utf-8') diff --git a/tickets/models.py b/tickets/models.py index 1f3de941..c069f0b3 100644 --- a/tickets/models.py +++ b/tickets/models.py @@ -1,7 +1,7 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ from django.core.mail import send_mail -from django.template import Context, loader +from django.template import loader from django.db.models.signals import post_save from django.dispatch import receiver @@ -52,7 +52,7 @@ class Ticket(AclMixin, models.Model): def publish_mail(self): site_url = GeneralOption.objects.first().main_site_url to_addr = Preferences.objects.first().publish_address - context = Context({'ticket':self,'site_url':site_url}) + context = {'ticket':self,'site_url':site_url} lang = Preferences.objects.first().mail_language if(lang == 0): diff --git a/users/models.py b/users/models.py index 8f8a5e1d..821eaffc 100755 --- a/users/models.py +++ b/users/models.py @@ -57,7 +57,7 @@ from django.forms import ValidationError from django.db.models.signals import post_save, post_delete, m2m_changed from django.dispatch import receiver from django.utils.functional import cached_property -from django.template import Context, loader +from django.template import loader from django.core.mail import send_mail from django.core.urlresolvers import reverse from django.db import transaction @@ -425,6 +425,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, def is_adherent(self): """ Renvoie True si l'user est adhérent : si self.end_adhesion()>now""" + return True end = self.end_adhesion() if not end: return False @@ -436,6 +437,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, def is_connected(self): """ Renvoie True si l'user est adhérent : si self.end_adhesion()>now et end_connexion>now""" + return True end = self.end_connexion() if not end: return False @@ -711,14 +713,14 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, template = loader.get_template('users/email_welcome') mailmessageoptions, _created = MailMessageOption\ .objects.get_or_create() - context = Context({ + context = { 'nom': self.get_full_name(), 'asso_name': AssoOption.get_cached_value('name'), 'asso_email': AssoOption.get_cached_value('contact'), 'welcome_mail_fr': mailmessageoptions.welcome_mail_fr, 'welcome_mail_en': mailmessageoptions.welcome_mail_en, 'pseudo': self.pseudo, - }) + } send_mail( 'Bienvenue au %(name)s / Welcome to %(name)s' % { 'name': AssoOption.get_cached_value('name') @@ -774,7 +776,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, machine_parent.user = self interface_cible = Interface() interface_cible.mac_address = mac_address - interface_cible.type = machine_type_cible + interface_cible.machine_type = machine_type_cible interface_cible.clean() machine_parent.clean() domain = Domain() @@ -796,14 +798,14 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, """Notification mail lorsque une machine est automatiquement ajoutée par le radius""" template = loader.get_template('users/email_auto_newmachine') - context = Context({ + context = { 'nom': self.get_full_name(), 'mac_address': interface.mac_address, 'asso_name': AssoOption.get_cached_value('name'), 'interface_name': interface.domain, 'asso_email': AssoOption.get_cached_value('contact'), 'pseudo': self.pseudo, - }) + } send_mail( "Ajout automatique d'une machine / New machine autoregistered", '', @@ -1522,12 +1524,12 @@ class Ban(RevMixin, AclMixin, models.Model): def notif_ban(self): """ Prend en argument un objet ban, envoie un mail de notification """ template = loader.get_template('users/email_ban_notif') - context = Context({ + context = { 'name': self.user.get_full_name(), 'raison': self.raison, 'date_end': self.date_end, 'asso_name': AssoOption.get_cached_value('name'), - }) + } send_mail( 'Déconnexion disciplinaire / Disciplinary disconnection', template.render(context), diff --git a/users/widgets.py b/users/widgets.py index b423d2e0..bfacb7d5 100644 --- a/users/widgets.py +++ b/users/widgets.py @@ -1,7 +1,7 @@ from django.forms.widgets import Input from django.forms.utils import flatatt from django.utils.safestring import mark_safe -from django.template import Context, Template +from django.template import Template from django.template.loader import get_template from django.conf import settings from django.utils.translation import ugettext_lazy as _, get_language_bidi @@ -28,7 +28,7 @@ class DateTimePicker(Input): def render(self, name, value, attrs=None): super().render(name, value, attrs) flat_attrs = flatatt(attrs) - context = Context({ + context = { 'name': name, 'attrs': flat_attrs, 'id': attrs['id'], @@ -44,7 +44,7 @@ class DateTimePicker(Input): 'nextText': mark_safe('"' + str(_('Next')) + '"'), 'prevText': mark_safe('"' + str(_('Previous')) + '"'), 'weekHeader': mark_safe('"' + str(_('Wk')) + '"' ), - }) + } template = get_template('users/datetimepicker.html') return template.render(context)