From 8e403443b522dbc760de24fd3f1c8ccfffa61528 Mon Sep 17 00:00:00 2001 From: Grizzly Date: Mon, 5 Aug 2019 14:38:53 +0000 Subject: [PATCH] =?UTF-8?q?Affichage=20des=20pr=C3=A9f=C3=A9rences=20des?= =?UTF-8?q?=20tickets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../preferences/display_preferences.html | 4 ++++ preferences/views.py | 7 ++++++ tickets/models.py | 22 +++++++++++++++++++ tickets/templates/tickets/preferences.html | 12 ++++++++++ tickets/views.py | 13 ++++++++++- 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tickets/templates/tickets/preferences.html diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index a7d15679..3e71c817 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -503,5 +503,9 @@ with this program; if not, write to the Free Software Foundation, Inc., +{% for template in optionnal_templates_list %} + {{ template }} +{% endfor %} + {% endblock %} diff --git a/preferences/views.py b/preferences/views.py index ecb3826e..680fcac0 100644 --- a/preferences/views.py +++ b/preferences/views.py @@ -40,6 +40,8 @@ from django.utils.translation import ugettext as _ from reversion import revisions as reversion +from importlib import import_module +from re2o.settings_local import OPTIONNAL_APPS from re2o.views import form from re2o.acl import can_create, can_edit, can_delete_set, can_view_all, can_delete @@ -94,6 +96,10 @@ def display_options(request): radiusoptions, _ = RadiusOption.objects.get_or_create() cotisationsoptions, _created = CotisationsOption.objects.get_or_create() document_template_list = DocumentTemplate.objects.order_by('name') + + optionnal_apps = [import_module(app) for app in OPTIONNAL_APPS] + optionnal_templates_list = [app.views.preferences(request) for app in optionnal_apps] + return form({ 'useroptions': useroptions, 'machineoptions': machineoptions, @@ -109,6 +115,7 @@ def display_options(request): 'switchmanagementcred_list': switchmanagementcred_list, 'radiusoptions' : radiusoptions, 'cotisationsoptions': cotisationsoptions, + 'optionnal_templates_list': optionnal_templates_list, 'document_template_list': document_template_list, }, 'preferences/display_preferences.html', request) diff --git a/tickets/models.py b/tickets/models.py index 01a4d77b..df1cd8ac 100644 --- a/tickets/models.py +++ b/tickets/models.py @@ -1,5 +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 import users.models @@ -42,3 +44,23 @@ class Ticket(models.Model): def __str__(self): return "Ticket de {} date: {}".format(self.user.surname,self.date) + + def publish_mail(self): + template = loader.get_template('ticket/mail_publish_ticket') + context = Context({'ticket':self}) + send_mail( + 'Nouvelle ouverture de ticket', + '', + 'ticket_app_re2o@crans.org', + '', + html_message=template.render(context)) + +class Preferences(models.Model): + """ Class cannonique définissants les préférences des tickets """ + + publish_address = models.EmailField( + help_text = _("Adresse mail pour annoncer les nouveau tickets (laisser vide pour ne rien annoncer)"), + max_length = 1000, + null = True) + class Meta: + verbose_name = _("Préférences des tickets") diff --git a/tickets/templates/tickets/preferences.html b/tickets/templates/tickets/preferences.html new file mode 100644 index 00000000..c27c0a99 --- /dev/null +++ b/tickets/templates/tickets/preferences.html @@ -0,0 +1,12 @@ +{% load i18n %} + +
+ +
+ preferences des tickets +
+
diff --git a/tickets/views.py b/tickets/views.py index 9c6b42e6..ef268f9f 100644 --- a/tickets/views.py +++ b/tickets/views.py @@ -6,13 +6,15 @@ from django.forms import modelformset_factory from re2o.views import form from .models import( - Ticket + Ticket, + Preferences, ) from .forms import ( NewTicketForm ) + def new_ticket(request): """ Vue de création d'un ticket """ ticketform = NewTicketForm(request.POST or None)#, user=request.user) @@ -51,8 +53,17 @@ def aff_tickets(request): tickets = Ticket.objects.all().order_by('-date') return render(request,'tickets/index.html', {'tickets_list':tickets}) + + +# views cannoniques des apps optionnels def profil(request,user): """ Vue cannonique d'affichage des tickets dans l'accordeon du profil""" tickets = Ticket.objects.filter(user=user).all().order_by('-date') context = {'tickets_list':tickets} return render_to_string('tickets/profil.html', context=context, request=request, using=None) + +def preferences(request): + """ Vue cannonique d'affichage des tickets dans l'affichage du profil""" + preferences = Preferences.objects.first() + context = {'preferences':preferences} + return render_to_string('tickets/preferences.html', context=context, request=request, using=None)