diff --git a/tickets/forms.py b/tickets/forms.py index d914d022..1b4fa4ce 100644 --- a/tickets/forms.py +++ b/tickets/forms.py @@ -5,19 +5,12 @@ from re2o.mixins import FormRevMixin from django.utils.translation import ugettext_lazy as _ from .models import( - Ticket + Ticket, + Preferences, ) class EditTicketForm(FormRevMixin, ModelForm): """Formulaire d'edition d'un Ticket""" - - #def __init__(self,*args, **kwargs): - #prefix = kwargs.pop('prefix',self.Meta.model.__name__) - #super(EditTicketForm, self).__init__(*args, prefix=prefix, **kwargs) - #self.fields['title'].label = _("Titre du ticket") - #self.fields['decription'].label = _("Description du ticket") - #self.fields['solved'].label = _("Problème réglé ?") - class Meta: model = Ticket exclude = ['user','assigned_staff','date'] @@ -25,13 +18,13 @@ class EditTicketForm(FormRevMixin, ModelForm): class NewTicketForm(ModelForm): """ Creation d'une machine""" - email = forms.EmailField(required=False) - class Meta: model = Ticket fields = ['title', 'description', 'email'] - #def __init(self,*args, **kwargs): - #prefix = kwargs.pop('prefix', self.Meta.model.__name__) - #super(NewTicketForm, self).__init__(*args, prefix=prefix, **kwargs) +class EditPreferencesForm(ModelForm): + """ Edition des préférences des tickets """ + class Meta: + model = Preferences + fields = '__all__' diff --git a/tickets/templates/tickets/form_preferences.html b/tickets/templates/tickets/form_preferences.html new file mode 100644 index 00000000..83339484 --- /dev/null +++ b/tickets/templates/tickets/form_preferences.html @@ -0,0 +1,48 @@ +{% extends 'machines/sidebar.html' %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle +Copyright © 2017 Maël Kervella + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} +{% load massive_bootstrap_form %} +{% load i18n %} + +{% block title %}{% trans "Ticket" %}{% endblock %} + +{% block content %} +

Edition des préférences des Tickets

+ +{% for message in messages %} +
+ + {{ message | safe }} +
+{% endfor %} + +
+ {% csrf_token %} + {% bootstrap_field preferencesform.publish_address %} + {% bootstrap_button "Editer" button_type="submit" icon='ok' button_class='btn-success' %} +
+{% endblock %} diff --git a/tickets/templates/tickets/preferences.html b/tickets/templates/tickets/preferences.html index c27c0a99..8f9fe490 100644 --- a/tickets/templates/tickets/preferences.html +++ b/tickets/templates/tickets/preferences.html @@ -6,7 +6,28 @@ {% trans "Tickets" %} -
- preferences des tickets + +
+ + + + {% trans "Edit" %} + +

+ +
+ + + + + {% if preferences.publish_address %} + + {% else %} + + {% endif %} + +

Email de publication

{{ preferences.publish_address }}

{% trans "Pas d'adresse, les tickets ne sont pas annoncés" %}

+
+
diff --git a/tickets/urls.py b/tickets/urls.py index d270aa4c..98556a7a 100644 --- a/tickets/urls.py +++ b/tickets/urls.py @@ -5,5 +5,6 @@ from . import views urlpatterns = [ url(r'^$', views.aff_tickets, name='aff-tickets'), url(r'^ticket/(?P[0-9]+)$', views.aff_ticket, name='aff-ticket'), + url(r'^ticket/edit-preferences-tickets$', views.edit_preferences, name='edit-preferences-tickets'), url(r'^new_ticket/$',views.new_ticket,name='new-ticket'), ] diff --git a/tickets/views.py b/tickets/views.py index ef268f9f..13b6ad23 100644 --- a/tickets/views.py +++ b/tickets/views.py @@ -11,13 +11,14 @@ from .models import( ) from .forms import ( - NewTicketForm + NewTicketForm, + EditPreferencesForm, ) def new_ticket(request): """ Vue de création d'un ticket """ - ticketform = NewTicketForm(request.POST or None)#, user=request.user) + ticketform = NewTicketForm(request.POST or None) if request.method == 'POST': ticketform = NewTicketForm(request.POST) @@ -54,6 +55,23 @@ def aff_tickets(request): return render(request,'tickets/index.html', {'tickets_list':tickets}) +def edit_preferences(request): + """ Vue d'édition des préférences des tickets """ + + preferences_instance, created = Preferences.objects.get_or_create(id=1) + preferencesform = EditPreferencesForm( + request.POST or None, + instance = preferences_instance,) + + if preferencesform.is_valid(): + if preferencesform.changed_data: + preferencesform.save() + messages.success(request,'Préférences des Tickets mises à jour') + return redirect(reverse('preferences:display-options',)) + else: + messages.error(request,'Formulaire Invalide') + return form({'preferencesform':preferencesform,},'tickets/form_preferences.html',request) + return form({'preferencesform':preferencesform,},'tickets/form_preferences.html',request) # views cannoniques des apps optionnels def profil(request,user):