8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

New organisation for local apps and all settings in folder preferences

This commit is contained in:
Gabriel Detraz 2020-04-22 18:55:33 +02:00
parent 502d9606ca
commit 648eb223ee
11 changed files with 311 additions and 86 deletions

View file

@ -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 django.contrib import admin
from .models import Ticket from .models import Ticket
admin.site.register(Ticket) from reversion.admin import VersionAdmin
# Register your models here.
class TicketAdmin(VersionAdmin):
"""Gestion des ticket"""
pass
admin.site.register(Ticket, TicketAdmin)

View file

@ -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 import forms
from django.forms import ModelForm, Form from django.forms import ModelForm, Form
from re2o.field_permissions import FieldPermissionFormMixin from re2o.field_permissions import FieldPermissionFormMixin

View file

@ -30,66 +30,78 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: tickets/models.py:28 #: tickets/models.py:54
msgid "Title of the ticket." msgid "Title of the ticket."
msgstr "Titre du ticket." msgstr "Titre du ticket."
#: tickets/models.py:32 #: tickets/models.py:58
msgid "Description of the ticket." msgid "Description of the ticket."
msgstr "Description du ticket." msgstr "Description du ticket."
#: tickets/models.py:38 #: tickets/models.py:64
msgid "An email address to get back to you." msgid "An email address to get back to you."
msgstr "Une adresse mail pour vous recontacter." msgstr "Une adresse mail pour vous recontacter."
#: tickets/models.py:44 #: tickets/models.py:70
msgid "Can view a ticket object" msgid "Can view a ticket object"
msgstr "Peut voir un objet ticket" msgstr "Peut voir un objet ticket"
#: tickets/models.py:45 #: tickets/models.py:71
msgid "ticket" msgid "ticket"
msgstr "ticket" msgstr "ticket"
#: tickets/models.py:46 #: tickets/models.py:72
msgid "tickets" msgid "tickets"
msgstr "tickets" msgstr "tickets"
#: tickets/models.py:50 #: tickets/models.py:76
#, python-format #, python-format
msgid "Ticket from %(name)s. Date: %(date)s." msgid "Ticket from %(name)s. Date: %(date)s."
msgstr "Ticket de %(name)s. Date : %(date)s." msgstr "Ticket de %(name)s. Date : %(date)s."
#: tickets/models.py:52 #: tickets/models.py:78
#, python-format #, python-format
msgid "Anonymous ticket. Date: %s." msgid "Anonymous ticket. Date: %s."
msgstr "Ticket anonyme. 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." 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." 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." 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." 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 "" msgid ""
"Email address to publish the new tickets (leave empty for no publication)." "Email address to publish the new tickets (leave empty for no publication)."
msgstr "" msgstr ""
"Adresse mail où publier les nouveaux tickets (laissez vide pour ne pas " "Adresse mail où publier les nouveaux tickets (laissez vide pour ne pas "
"publier)." "publier)."
#: tickets/preferences/models.py:17 #: tickets/preferences/models.py:45
msgid "French" msgid "French"
msgstr "Français" msgstr "Français"
#: tickets/preferences/models.py:17 #: tickets/preferences/models.py:45
msgid "English" msgid "English"
msgstr "Anglais" msgstr "Anglais"
#: tickets/preferences/models.py:21 #: tickets/preferences/models.py:49
msgid "tickets preferences" msgid "tickets options"
msgstr "préférences de tickets" 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/aff_ticket.html:30
#: tickets/templates/tickets/contact.html:4 #: tickets/templates/tickets/contact.html:4
@ -214,7 +226,7 @@ msgstr "Modifier"
msgid "Ticket opening" msgid "Ticket opening"
msgstr "Ouverture de ticket" 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 "" msgid ""
"You are not authenticated. Please log in or provide an email address so we " "You are not authenticated. Please log in or provide an email address so we "
"can get back to you." "can get back to you."
@ -280,21 +292,22 @@ msgstr "Langue du mail"
msgid "No tickets" msgid "No tickets"
msgstr "Pas de tickets" msgstr "Pas de tickets"
#: tickets/views.py:71 tickets/views.py:82 #: tickets/views.py:66 tickets/views.py:77
msgid "" msgid ""
"Your ticket has been succesfully opened. We will take care of it as soon as " "Your ticket has been succesfully opened. We will take care of it as soon as "
"possible." "possible."
msgstr "" msgstr ""
"Votre ticket a bien été ouvert. Nous nous en occuperons dès que possible." "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" msgid "Never"
msgstr "Jamais" msgstr "Jamais"
#: tickets/views.py:154 #~ msgid "The tickets preferences were edited."
msgid "The tickets preferences were edited." #~ msgstr "Les préférences de tickets ont été modifiées."
msgstr "Les préférences de tickets ont été modifiées."
#: tickets/views.py:157 #~ msgid "Invalid form."
msgid "Invalid form." #~ msgstr "Formulaire invalide."
msgstr "Formulaire invalide."
#~ msgid "tickets preferences"
#~ msgstr "préférences de tickets"

View file

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

View file

@ -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.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.template import loader from django.template import loader
@ -11,7 +37,7 @@ from preferences.models import GeneralOption
import users.models import users.models
from .preferences.models import Preferences from .preferences.models import TicketOption
class Ticket(AclMixin, models.Model): class Ticket(AclMixin, models.Model):
@ -52,11 +78,11 @@ class Ticket(AclMixin, models.Model):
return _("Anonymous ticket. Date: %s.") % (self.date) return _("Anonymous ticket. Date: %s.") % (self.date)
def publish_mail(self, request=None): def publish_mail(self, request=None):
site_url = GeneralOption.objects.first().main_site_url site_url = GeneralOption.get_cached_value("main_site_url")
to_addr = Preferences.objects.first().publish_address to_addr = TicketOption.get_cached_value("publish_address")
context = {"ticket": self, "site_url": site_url} context = {"ticket": self, "site_url": site_url}
lang = Preferences.objects.first().mail_language lang = TicketOption.get_cached_value("mail_language")
if lang == 0: if lang == 0:
obj = "Nouveau ticket ouvert" obj = "Nouveau ticket ouvert"
template = loader.get_template("tickets/publication_mail_fr") template = loader.get_template("tickets/publication_mail_fr")
@ -109,6 +135,6 @@ class Ticket(AclMixin, models.Model):
def ticket_post_save(**kwargs): def ticket_post_save(**kwargs):
""" Send the mail to publish the new ticket """ """ Send the mail to publish the new ticket """
if kwargs["created"]: if kwargs["created"]:
if Preferences.objects.first().publish_address: if TicketOption.get_cached_value("publish_address"):
ticket = kwargs["instance"] ticket = kwargs["instance"]
ticket.publish_mail(ticket.request) ticket.publish_mail(ticket.request)

View file

@ -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 import forms
from django.forms import ModelForm, Form from django.forms import ModelForm, Form
from django.utils.translation import ugettext_lazy as _ 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""" """ Edit the ticket's settings"""
class Meta: class Meta:
model = Preferences model = TicketOption
fields = "__all__" 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")

View file

@ -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.db import models
from django.utils.translation import ugettext_lazy as _ 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""" """ Definition of the ticket's settings"""
publish_address = models.EmailField( publish_address = models.EmailField(
@ -18,4 +46,5 @@ class Preferences(models.Model):
mail_language = models.IntegerField(choices=LANGUES, default=LANG_FR) mail_language = models.IntegerField(choices=LANGUES, default=LANG_FR)
class Meta: class Meta:
verbose_name = _("tickets preferences") verbose_name = _("tickets options")
permissions = (("view_ticketoption", _("Can view tickets options")),)

View file

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

View file

@ -9,7 +9,7 @@
<div id="collapse_tickets" class="panel-collapse panel-body collapse"> <div id="collapse_tickets" class="panel-collapse panel-body collapse">
<a class="btn btn-primary btn-sm" role="button" href="{% url 'tickets:edit-preferences-tickets' %}"> <a class="btn btn-primary btn-sm" role="button" href="{% url 'tickets:edit-options' 'TicketOption' %}">
<i class="fa fa-edit"></i> <i class="fa fa-edit"></i>
{% trans "Edit" %} {% trans "Edit" %}
</a> </a>

View file

@ -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 django.conf.urls import url
from . import views from . import views
from .preferences.views import edit_options
urlpatterns = [ urlpatterns = [
url(r"^$", views.aff_tickets, name="aff-tickets"), url(r"^$", views.aff_tickets, name="aff-tickets"),
url(r"^ticket/(?P<ticketid>[0-9]+)$", views.aff_ticket, name="aff-ticket"), url(r"^(?P<ticketid>[0-9]+)$", views.aff_ticket, name="aff-ticket"),
url( url(
r"^ticket/edit-preferences-tickets$", r"^edit_options/(?P<section>TicketOption)$",
views.edit_preferences, edit_options,
name="edit-preferences-tickets", name="edit-options",
), ),
url(r"^new_ticket/$", views.new_ticket, name="new-ticket"), url(r"^new_ticket/$", views.new_ticket, name="new-ticket"),
] ]

View file

@ -3,9 +3,8 @@
# se veut agnostique au réseau considéré, de manière à être installable en # se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics. # quelques clics.
# #
# Copyright © 2017 Gabriel Détraz # Copyright © 2019 Arthur Grisel-Davy
# Copyright © 2017 Lara Kermarec # Copyright © 2020 Gabriel Détraz
# Copyright © 2017 Augustin Lemesle
# #
# This program is free software; you can redistribute it and/or modify # 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 # 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 .models import Ticket
from .preferences.models import Preferences
from .forms import NewTicketForm, ChangeStatusTicketForm from .forms import NewTicketForm, ChangeStatusTicketForm
from .preferences.forms import EditPreferencesForm
def new_ticket(request): def new_ticket(request):
""" Ticket creation view""" """ Ticket creation view"""
@ -140,31 +135,6 @@ def aff_tickets(request):
return render(request, "tickets/index.html", context=context) 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 # views cannoniques des apps optionnels
def profil(request, user): def profil(request, user):
""" View to display the ticket's module on the profil""" """ 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): def contact(request):
"""View to display a contact address on the contact page """View to display a contact address on the contact page
used here to display a link to open a ticket""" used here to display a link to open a ticket"""