From 648eb223ee05431cb45242292c36eabf287b9726 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 22 Apr 2020 18:55:33 +0200 Subject: [PATCH] New organisation for local apps and all settings in folder preferences --- tickets/admin.py | 36 ++++++++++- tickets/forms.py | 26 ++++++++ tickets/locale/fr/LC_MESSAGES/django.po | 63 +++++++++++-------- tickets/migrations/0003_auto_20200422_1839.py | 23 +++++++ tickets/models.py | 36 +++++++++-- tickets/preferences/forms.py | 38 ++++++++++- tickets/preferences/models.py | 33 +++++++++- tickets/preferences/views.py | 60 ++++++++++++++++++ tickets/templates/tickets/preferences.html | 2 +- tickets/urls.py | 34 ++++++++-- tickets/views.py | 46 +------------- 11 files changed, 311 insertions(+), 86 deletions(-) create mode 100644 tickets/migrations/0003_auto_20200422_1839.py create mode 100644 tickets/preferences/views.py diff --git a/tickets/admin.py b/tickets/admin.py index 6a20b775..69f84d0d 100644 --- a/tickets/admin.py +++ b/tickets/admin.py @@ -1,5 +1,37 @@ +# -*- mode: python; coding: utf-8 -*- +# 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 © 2019 Arthur Grisel-Davy +# Copyright © 2020 Gabriel Détraz +# +# 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. +""" +Ticket preferences model +""" + + from django.contrib import admin from .models import Ticket -admin.site.register(Ticket) -# Register your models here. +from reversion.admin import VersionAdmin + +class TicketAdmin(VersionAdmin): + """Gestion des ticket""" + + pass + +admin.site.register(Ticket, TicketAdmin) diff --git a/tickets/forms.py b/tickets/forms.py index 00edb0ec..4f62db84 100644 --- a/tickets/forms.py +++ b/tickets/forms.py @@ -1,3 +1,29 @@ +# -*- mode: python; coding: utf-8 -*- +# 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 © 2019 Arthur Grisel-Davy +# Copyright © 2020 Gabriel Détraz +# +# 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. +""" +Ticket form +""" + + from django import forms from django.forms import ModelForm, Form from re2o.field_permissions import FieldPermissionFormMixin diff --git a/tickets/locale/fr/LC_MESSAGES/django.po b/tickets/locale/fr/LC_MESSAGES/django.po index fbb7cbc2..528bf611 100644 --- a/tickets/locale/fr/LC_MESSAGES/django.po +++ b/tickets/locale/fr/LC_MESSAGES/django.po @@ -30,66 +30,78 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: tickets/models.py:28 +#: tickets/models.py:54 msgid "Title of the ticket." msgstr "Titre du ticket." -#: tickets/models.py:32 +#: tickets/models.py:58 msgid "Description of the ticket." msgstr "Description du ticket." -#: tickets/models.py:38 +#: tickets/models.py:64 msgid "An email address to get back to you." msgstr "Une adresse mail pour vous recontacter." -#: tickets/models.py:44 +#: tickets/models.py:70 msgid "Can view a ticket object" msgstr "Peut voir un objet ticket" -#: tickets/models.py:45 +#: tickets/models.py:71 msgid "ticket" msgstr "ticket" -#: tickets/models.py:46 +#: tickets/models.py:72 msgid "tickets" msgstr "tickets" -#: tickets/models.py:50 +#: tickets/models.py:76 #, python-format msgid "Ticket from %(name)s. Date: %(date)s." msgstr "Ticket de %(name)s. Date : %(date)s." -#: tickets/models.py:52 +#: tickets/models.py:78 #, python-format msgid "Anonymous ticket. Date: %s." msgstr "Ticket anonyme. Date : %s." -#: tickets/models.py:85 +#: tickets/models.py:111 msgid "You don't have the right to view other tickets than yours." msgstr "Vous n'avez pas le droit de voir d'autres tickets que les vôtres." -#: tickets/models.py:97 +#: tickets/models.py:123 msgid "You don't have the right to view the list of tickets." msgstr "Vous n'avez pas le droit de voir la liste des tickets." -#: tickets/preferences/models.py:10 +#: tickets/preferences/forms.py:44 +msgid "Publish address" +msgstr "Adresse mail de publication" + +#: tickets/preferences/forms.py:45 +msgid "Mail language" +msgstr "Langue du mail" + +#: tickets/preferences/models.py:38 msgid "" "Email address to publish the new tickets (leave empty for no publication)." msgstr "" "Adresse mail où publier les nouveaux tickets (laissez vide pour ne pas " "publier)." -#: tickets/preferences/models.py:17 +#: tickets/preferences/models.py:45 msgid "French" msgstr "Français" -#: tickets/preferences/models.py:17 +#: tickets/preferences/models.py:45 msgid "English" msgstr "Anglais" -#: tickets/preferences/models.py:21 -msgid "tickets preferences" -msgstr "préférences de tickets" +#: tickets/preferences/models.py:49 +msgid "tickets options" +msgstr "Options des tickets" + +#: tickets/preferences/models.py:50 +msgid "Can view tickets options" +msgstr "Peut voir les options des tickets" #: tickets/templates/tickets/aff_ticket.html:30 #: tickets/templates/tickets/contact.html:4 @@ -214,7 +226,7 @@ msgstr "Modifier" msgid "Ticket opening" msgstr "Ouverture de ticket" -#: tickets/templates/tickets/form_ticket.html:39 tickets/views.py:90 +#: tickets/templates/tickets/form_ticket.html:39 tickets/views.py:85 msgid "" "You are not authenticated. Please log in or provide an email address so we " "can get back to you." @@ -280,21 +292,22 @@ msgstr "Langue du mail" msgid "No tickets" msgstr "Pas de tickets" -#: tickets/views.py:71 tickets/views.py:82 +#: tickets/views.py:66 tickets/views.py:77 msgid "" "Your ticket has been succesfully opened. We will take care of it as soon as " "possible." msgstr "" "Votre ticket a bien été ouvert. Nous nous en occuperons dès que possible." -#: tickets/views.py:127 tickets/views.py:177 +#: tickets/views.py:122 tickets/views.py:147 msgid "Never" msgstr "Jamais" -#: tickets/views.py:154 -msgid "The tickets preferences were edited." -msgstr "Les préférences de tickets ont été modifiées." +#~ msgid "The tickets preferences were edited." +#~ msgstr "Les préférences de tickets ont été modifiées." -#: tickets/views.py:157 -msgid "Invalid form." -msgstr "Formulaire invalide." +#~ msgid "Invalid form." +#~ msgstr "Formulaire invalide." + +#~ msgid "tickets preferences" +#~ msgstr "préférences de tickets" diff --git a/tickets/migrations/0003_auto_20200422_1839.py b/tickets/migrations/0003_auto_20200422_1839.py new file mode 100644 index 00000000..daa29e42 --- /dev/null +++ b/tickets/migrations/0003_auto_20200422_1839.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.28 on 2020-04-22 16:39 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tickets', '0002_auto_20191120_0159'), + ] + + operations = [ + migrations.RenameModel( + old_name='Preferences', + new_name='TicketOption', + ), + migrations.AlterModelOptions( + name='ticketoption', + options={'permissions': (('view_ticketoption', 'Can view tickets options'),), 'verbose_name': 'tickets options'}, + ), + ] diff --git a/tickets/models.py b/tickets/models.py index a8adbe87..bf0a3794 100644 --- a/tickets/models.py +++ b/tickets/models.py @@ -1,3 +1,29 @@ +# -*- mode: python; coding: utf-8 -*- +# 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 © 2019 Arthur Grisel-Davy +# Copyright © 2020 Gabriel Détraz +# +# 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. +""" +Ticket model +""" + + from django.db import models from django.utils.translation import ugettext_lazy as _ from django.template import loader @@ -11,7 +37,7 @@ from preferences.models import GeneralOption import users.models -from .preferences.models import Preferences +from .preferences.models import TicketOption class Ticket(AclMixin, models.Model): @@ -52,11 +78,11 @@ class Ticket(AclMixin, models.Model): return _("Anonymous ticket. Date: %s.") % (self.date) def publish_mail(self, request=None): - site_url = GeneralOption.objects.first().main_site_url - to_addr = Preferences.objects.first().publish_address + site_url = GeneralOption.get_cached_value("main_site_url") + to_addr = TicketOption.get_cached_value("publish_address") context = {"ticket": self, "site_url": site_url} - lang = Preferences.objects.first().mail_language + lang = TicketOption.get_cached_value("mail_language") if lang == 0: obj = "Nouveau ticket ouvert" template = loader.get_template("tickets/publication_mail_fr") @@ -109,6 +135,6 @@ class Ticket(AclMixin, models.Model): def ticket_post_save(**kwargs): """ Send the mail to publish the new ticket """ if kwargs["created"]: - if Preferences.objects.first().publish_address: + if TicketOption.get_cached_value("publish_address"): ticket = kwargs["instance"] ticket.publish_mail(ticket.request) diff --git a/tickets/preferences/forms.py b/tickets/preferences/forms.py index b12bde67..05b40ec3 100644 --- a/tickets/preferences/forms.py +++ b/tickets/preferences/forms.py @@ -1,13 +1,45 @@ +# -*- mode: python; coding: utf-8 -*- +# 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 © 2019 Arthur Grisel-Davy +# Copyright © 2020 Gabriel Détraz +# +# 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. +""" +Ticket preferences form +""" + from django import forms from django.forms import ModelForm, Form from django.utils.translation import ugettext_lazy as _ -from .models import Preferences +from re2o.mixins import FormRevMixin +from .models import TicketOption -class EditPreferencesForm(ModelForm): +class EditTicketOptionForm(FormRevMixin, ModelForm): """ Edit the ticket's settings""" class Meta: - model = Preferences + model = TicketOption fields = "__all__" + + def __init__(self, *args, **kwargs): + prefix = kwargs.pop("prefix", self.Meta.model.__name__) + super(EditTicketOptionForm, self).__init__(*args, prefix=prefix, **kwargs) + self.fields["publish_address"].label = _("Publish address") + self.fields["mail_language"].label = _("Mail language") diff --git a/tickets/preferences/models.py b/tickets/preferences/models.py index 27922303..8b41c5eb 100644 --- a/tickets/preferences/models.py +++ b/tickets/preferences/models.py @@ -1,8 +1,36 @@ +# -*- mode: python; coding: utf-8 -*- +# 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 © 2019 Arthur Grisel-Davy +# Copyright © 2020 Gabriel Détraz +# +# 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. +""" +Ticket preferences model +""" + + from django.db import models from django.utils.translation import ugettext_lazy as _ +from re2o.mixins import AclMixin, RevMixin +from preferences.utils.models import PreferencesModel -class Preferences(models.Model): +class TicketOption(AclMixin, PreferencesModel): """ Definition of the ticket's settings""" publish_address = models.EmailField( @@ -18,4 +46,5 @@ class Preferences(models.Model): mail_language = models.IntegerField(choices=LANGUES, default=LANG_FR) class Meta: - verbose_name = _("tickets preferences") + verbose_name = _("tickets options") + permissions = (("view_ticketoption", _("Can view tickets options")),) diff --git a/tickets/preferences/views.py b/tickets/preferences/views.py new file mode 100644 index 00000000..cfc6a0f2 --- /dev/null +++ b/tickets/preferences/views.py @@ -0,0 +1,60 @@ +# -*- mode: python; coding: utf-8 -*- +# 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 © 2020 Gabriel Détraz +# Copyright © 2019 Arthur Grisel-Davy +# +# 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. + +# App de gestion des users pour re2o +# Lara Kermarec, Gabriel Détraz, Lemesle Augustin +# Gplv2 + +from django.contrib import messages +from django.contrib.auth.decorators import login_required +from django.shortcuts import render, redirect +from django.template.loader import render_to_string +from django.views.decorators.cache import cache_page +from django.utils.translation import ugettext as _ +from django.urls import reverse +from django.forms import modelformset_factory +from re2o.views import form + +from re2o.base import re2o_paginator + +from re2o.acl import can_view, can_view_all, can_edit, can_create + +from preferences.utils.views import edit_options_template_function + +from . import forms +from . import models + +def aff_preferences(request): + """ View to display the settings of the tickets in the preferences page""" + pref, created = models.TicketOption.objects.get_or_create() + context = { + "preferences": pref, + "language": str(pref.LANGUES[pref.mail_language][1]), + } + return render_to_string( + "tickets/preferences.html", context=context, request=request, using=None + ) + +@login_required +def edit_options(request, section): + return edit_options_template_function(request, section, forms, models) + diff --git a/tickets/templates/tickets/preferences.html b/tickets/templates/tickets/preferences.html index df51f3e1..5952a496 100644 --- a/tickets/templates/tickets/preferences.html +++ b/tickets/templates/tickets/preferences.html @@ -9,7 +9,7 @@
- + {% trans "Edit" %} diff --git a/tickets/urls.py b/tickets/urls.py index 1dfda475..c6eaefde 100644 --- a/tickets/urls.py +++ b/tickets/urls.py @@ -1,14 +1,40 @@ +# -*- mode: python; coding: utf-8 -*- +# 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 © 2019 Arthur Grisel-Davy +# Copyright © 2020 Gabriel Détraz +# +# 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. +""" +Tickets url +""" + from django.conf.urls import url from . import views +from .preferences.views import edit_options urlpatterns = [ url(r"^$", views.aff_tickets, name="aff-tickets"), - url(r"^ticket/(?P[0-9]+)$", views.aff_ticket, name="aff-ticket"), + url(r"^(?P[0-9]+)$", views.aff_ticket, name="aff-ticket"), url( - r"^ticket/edit-preferences-tickets$", - views.edit_preferences, - name="edit-preferences-tickets", + r"^edit_options/(?P
TicketOption)$", + edit_options, + name="edit-options", ), url(r"^new_ticket/$", views.new_ticket, name="new-ticket"), ] diff --git a/tickets/views.py b/tickets/views.py index 03cc535c..f5186cdf 100644 --- a/tickets/views.py +++ b/tickets/views.py @@ -3,9 +3,8 @@ # se veut agnostique au réseau considéré, de manière à être installable en # quelques clics. # -# Copyright © 2017 Gabriel Détraz -# Copyright © 2017 Lara Kermarec -# Copyright © 2017 Augustin Lemesle +# Copyright © 2019 Arthur Grisel-Davy +# Copyright © 2020 Gabriel Détraz # # 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 @@ -43,12 +42,8 @@ from preferences.models import GeneralOption from .models import Ticket -from .preferences.models import Preferences - from .forms import NewTicketForm, ChangeStatusTicketForm -from .preferences.forms import EditPreferencesForm - def new_ticket(request): """ Ticket creation view""" @@ -140,31 +135,6 @@ def aff_tickets(request): return render(request, "tickets/index.html", context=context) -def edit_preferences(request): - """ View to edit the settings of the 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, _("The tickets preferences were edited.")) - return redirect(reverse("preferences:display-options")) - else: - messages.error(request, _("Invalid form.")) - 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): """ View to display the ticket's module on the profil""" @@ -191,18 +161,6 @@ def profil(request, user): ) -def preferences(request): - """ View to display the settings of the tickets in the preferences page""" - pref, created = Preferences.objects.get_or_create(id=1) - context = { - "preferences": pref, - "language": str(pref.LANGUES[pref.mail_language][1]), - } - return render_to_string( - "tickets/preferences.html", context=context, request=request, using=None - ) - - def contact(request): """View to display a contact address on the contact page used here to display a link to open a ticket"""