8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 07:23:46 +00:00

Ajoute un message personalisé dans le mail d'acceuil via les préférences

Attention migration à faire
This commit is contained in:
Maël Kervella 2017-09-08 20:53:13 +00:00
parent c3f569f10e
commit 30f5ac6091
9 changed files with 80 additions and 13 deletions

View file

@ -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)

View file

@ -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

View file

@ -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='')),
],
),
]

View file

@ -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="")

View file

@ -155,6 +155,25 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>{{ assooptions.utilisateur_asso }}</td>
</tr>
</table>
<h4>Messages personalisé dans les mails</h4>
{% if is_bureau %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'MailMessageOption' %}">
<i class="glyphicon glyphicon-edit"></i>
Editer
</a>
{% endif %}
<p>
</p>
<table class="table table-striped">
<tr>
<th>Message Français</th>
<td>{{ mailmessageoptions.welcome_mail_fr }}</td>
</tr>
<tr>
<th>Message Anglais</th>
<td>{{ mailmessageoptions.welcome_mail_en }}</td>
</tr>
</table>
<h2>Liste des services page d'accueil</h2>
{% if is_infra %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:add-services' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un service</a>

View file

@ -31,6 +31,7 @@ urlpatterns = [
url(r'^edit_options/(?P<section>OptionalTopologie)$', views.edit_options, name='edit-options'),
url(r'^edit_options/(?P<section>GeneralOption)$', views.edit_options, name='edit-options'),
url(r'^edit_options/(?P<section>AssoOption)$', views.edit_options, name='edit-options'),
url(r'^edit_options/(?P<section>MailMessageOption)$', views.edit_options, name='edit-options'),
url(r'^add_services/$', views.add_services, name='add-services'),
url(r'^edit_services/(?P<servicesid>[0-9]+)$', views.edit_services, name='edit-services'),
url(r'^del_services/$', views.del_services, name='del-services'),

View file

@ -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')

View file

@ -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

View file

@ -4,7 +4,7 @@
<p>Votre pseudo est : {{pseudo}}</p>
{{personalized_message_fr}}
{{welcome_mail_fr|safe}}
<p>Pour nous faire part de toute remarque, suggestion ou problème vous pouvez nous envoyer un mail à {{asso_email}}.</p>
@ -17,7 +17,7 @@ L'équipe de {{asso_name}}.</p>
<p>Your username is : {{pseudo}}<p>
{{personalized_message_en}}
{{welcome_mail_en|safe}}
<p>For any information, suggestion or problem, you can contact us via email at<br>
{{asso_email}}.</p>