From 30f5ac60913934c64b18e8e75e96ac1e31fbb248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Fri, 8 Sep 2017 20:53:13 +0000 Subject: [PATCH] =?UTF-8?q?Ajoute=20un=20message=20personalis=C3=A9=20dans?= =?UTF-8?q?=20le=20mail=20d'acceuil=20via=20les=20pr=C3=A9f=C3=A9rences=20?= =?UTF-8?q?Attention=20migration=20=C3=A0=20faire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- preferences/admin.py | 7 ++++-- preferences/forms.py | 12 +++++++++- .../migrations/0017_mailmessageoption.py | 23 +++++++++++++++++++ preferences/models.py | 7 ++++++ .../preferences/display_preferences.html | 19 +++++++++++++++ preferences/urls.py | 1 + preferences/views.py | 7 +++--- users/models.py | 13 +++++++---- users/templates/users/email_welcome | 4 ++-- 9 files changed, 80 insertions(+), 13 deletions(-) create mode 100644 preferences/migrations/0017_mailmessageoption.py diff --git a/preferences/admin.py b/preferences/admin.py index d4c41e62..867596fe 100644 --- a/preferences/admin.py +++ b/preferences/admin.py @@ -23,7 +23,7 @@ from django.contrib import admin from reversion.admin import VersionAdmin -from .models import OptionalUser, OptionalMachine, OptionalTopologie, GeneralOption, Service, AssoOption +from .models import OptionalUser, OptionalMachine, OptionalTopologie, GeneralOption, Service, AssoOption, MailMessageOption class OptionalUserAdmin(VersionAdmin): pass @@ -31,7 +31,6 @@ class OptionalUserAdmin(VersionAdmin): class OptionalTopologieAdmin(VersionAdmin): pass - class OptionalMachineAdmin(VersionAdmin): pass @@ -44,9 +43,13 @@ class ServiceAdmin(VersionAdmin): class AssoOptionAdmin(VersionAdmin): pass +class MailMessageOptionAdmin(VersionAdmin): + pass + admin.site.register(OptionalUser, OptionalUserAdmin) admin.site.register(OptionalMachine, OptionalMachineAdmin) admin.site.register(OptionalTopologie, OptionalTopologieAdmin) admin.site.register(GeneralOption, GeneralOptionAdmin) admin.site.register(Service, ServiceAdmin) admin.site.register(AssoOption, AssoOptionAdmin) +admin.site.register(MailMessageOption, MailMessageOptionAdmin) diff --git a/preferences/forms.py b/preferences/forms.py index 37e9c7ea..1c1188c7 100644 --- a/preferences/forms.py +++ b/preferences/forms.py @@ -22,7 +22,7 @@ from django.forms import ModelForm, Form, ValidationError from django import forms -from .models import OptionalUser, OptionalMachine, OptionalTopologie, GeneralOption, AssoOption, Service +from .models import OptionalUser, OptionalMachine, OptionalTopologie, GeneralOption, AssoOption, MailMessageOption, Service from django.db.models import Q class EditOptionalUserForm(ModelForm): @@ -72,6 +72,16 @@ class EditAssoOptionForm(ModelForm): model = AssoOption fields = '__all__' +class EditMailMessageOptionForm(ModelForm): + class Meta: + model = MailMessageOption + fields = '__all__' + + def __init__(slef, *args, **kwargs): + super(EditMailMessageOptionForm, self).__init__(*args, **kwargs) + self.fields['welcome_mail_fr'].label = 'Message dans le mail d\'acceuil en français' + self.fields['welcome_mail_en'].label = 'Message dans le mail d\'acceuil en anglais' + class ServiceForm(ModelForm): class Meta: model = Service diff --git a/preferences/migrations/0017_mailmessageoption.py b/preferences/migrations/0017_mailmessageoption.py new file mode 100644 index 00000000..31fb145c --- /dev/null +++ b/preferences/migrations/0017_mailmessageoption.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-09-08 20:17 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0016_auto_20170902_1520'), + ] + + operations = [ + migrations.CreateModel( + name='MailMessageOption', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('welcome_mail_fr', models.TextField(default='')), + ('welcome_mail_en', models.TextField(default='')), + ], + ), + ] diff --git a/preferences/models.py b/preferences/models.py index 92822190..b56faf3d 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -87,3 +87,10 @@ class AssoOption(models.Model): telephone = models.CharField(max_length=15, default="0000000000") pseudo = models.CharField(default="Asso", max_length=32) utilisateur_asso = models.OneToOneField('users.User', on_delete=models.PROTECT, blank=True, null=True) + +class MailMessageOption(models.Model): + PRETTY_NAME = "Options de corps de mail" + + welcome_mail_fr = models.TextField(default="") + welcome_mail_en = models.TextField(default="") + diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index 394a4714..515404e7 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -155,6 +155,25 @@ with this program; if not, write to the Free Software Foundation, Inc., {{ assooptions.utilisateur_asso }} +

Messages personalisé dans les mails

+ {% if is_bureau %} + + + Editer + + {% endif %} +

+

+ + + + + + + + + +
Message Français{{ mailmessageoptions.welcome_mail_fr }}
Message Anglais{{ mailmessageoptions.welcome_mail_en }}

Liste des services page d'accueil

{% if is_infra %} Ajouter un service diff --git a/preferences/urls.py b/preferences/urls.py index dd9ccd8b..624971d8 100644 --- a/preferences/urls.py +++ b/preferences/urls.py @@ -31,6 +31,7 @@ urlpatterns = [ url(r'^edit_options/(?P
OptionalTopologie)$', views.edit_options, name='edit-options'), url(r'^edit_options/(?P
GeneralOption)$', views.edit_options, name='edit-options'), url(r'^edit_options/(?P
AssoOption)$', views.edit_options, name='edit-options'), + url(r'^edit_options/(?P
MailMessageOption)$', views.edit_options, name='edit-options'), url(r'^add_services/$', views.add_services, name='add-services'), url(r'^edit_services/(?P[0-9]+)$', views.edit_services, name='edit-services'), url(r'^del_services/$', views.del_services, name='del-services'), diff --git a/preferences/views.py b/preferences/views.py index dc29aee2..66ecd101 100644 --- a/preferences/views.py +++ b/preferences/views.py @@ -43,7 +43,7 @@ from reversion.models import Version from reversion import revisions as reversion from .forms import ServiceForm, DelServiceForm -from .models import Service, OptionalUser, OptionalMachine, AssoOption, GeneralOption, OptionalTopologie +from .models import Service, OptionalUser, OptionalMachine, AssoOption, MailMessageOption, GeneralOption, OptionalTopologie from . import models from . import forms @@ -60,9 +60,10 @@ def display_options(request): machineoptions, created = OptionalMachine.objects.get_or_create() topologieoptions, created = OptionalTopologie.objects.get_or_create() generaloptions, created = GeneralOption.objects.get_or_create() - assooptions, crated = AssoOption.objects.get_or_create() + assooptions, created = AssoOption.objects.get_or_create() + mailmessageoptions, created = MailMessageOption.objects.get_or_create() service_list = Service.objects.all() - return form({'useroptions': useroptions, 'machineoptions': machineoptions, 'topologieoptions': topologieoptions, 'generaloptions': generaloptions, 'assooptions' : assooptions, 'service_list':service_list}, 'preferences/display_preferences.html', request) + return form({'useroptions': useroptions, 'machineoptions': machineoptions, 'topologieoptions': topologieoptions, 'generaloptions': generaloptions, 'assooptions' : assooptions, 'mailmessageoptions' : mailmessageoptions, 'service_list':service_list}, 'preferences/display_preferences.html', request) @login_required @permission_required('admin') diff --git a/users/models.py b/users/models.py index 34f20fdc..4034a2f3 100644 --- a/users/models.py +++ b/users/models.py @@ -47,7 +47,7 @@ from django.core.validators import MinLengthValidator from topologie.models import Room from cotisations.models import Cotisation, Facture, Paiement, Vente from machines.models import Interface, Machine, regen -from preferences.models import GeneralOption, AssoOption, OptionalUser +from preferences.models import GeneralOption, AssoOption, OptionalUser, MailMessageOption now = timezone.now() @@ -415,15 +415,18 @@ class User(AbstractBaseUser): def notif_inscription(self): """ Prend en argument un objet user, envoie un mail de bienvenue """ t = loader.get_template('users/email_welcome') - options, created = AssoOption.objects.get_or_create() + assooptions, created = AssoOption.objects.get_or_create() + mailmessageoptions, created = MailMessageOption.objects.get_or_create() general_options, created = GeneralOption.objects.get_or_create() c = Context({ 'nom': str(self.name) + ' ' + str(self.surname), - 'asso_name': options.name, - 'asso_email': options.contact, + 'asso_name': assooptions.name, + 'asso_email': assooptions.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': options.name }, '', + send_mail('Bienvenue au %(name)s / Welcome to %(name)s' % {'name': assooptions.name }, '', general_options.email_from, [self.email], html_message=t.render(c)) return diff --git a/users/templates/users/email_welcome b/users/templates/users/email_welcome index f88ec1a5..690f69d1 100644 --- a/users/templates/users/email_welcome +++ b/users/templates/users/email_welcome @@ -4,7 +4,7 @@

Votre pseudo est : {{pseudo}}

-{{personalized_message_fr}} +{{welcome_mail_fr|safe}}

Pour nous faire part de toute remarque, suggestion ou problème vous pouvez nous envoyer un mail à {{asso_email}}.

@@ -17,7 +17,7 @@ L'équipe de {{asso_name}}.

Your username is : {{pseudo}}

-{{personalized_message_en}} +{{welcome_mail_en|safe}}

For any information, suggestion or problem, you can contact us via email at
{{asso_email}}.