From c8c89fab1d439f9ade49ba53bf8864fe5c0aa807 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 22 Apr 2020 21:37:21 +0200 Subject: [PATCH] Fix and harmonize some issues in ticket app --- tickets/forms.py | 25 ++- tickets/locale/fr/LC_MESSAGES/django.po | 149 +++++++++--------- tickets/migrations/0004_auto_20200422_2127.py | 24 +++ tickets/models.py | 18 +-- tickets/preferences/forms.py | 1 - tickets/preferences/models.py | 4 - tickets/preferences/views.py | 1 - tickets/templates/tickets/aff_ticket.html | 19 +-- .../{form_preferences.html => edit.html} | 20 +-- tickets/templates/tickets/form_ticket.html | 59 ------- tickets/templates/tickets/help_text.html | 14 ++ tickets/templates/tickets/preferences.html | 6 +- tickets/templates/tickets/publication_mail_en | 4 +- tickets/templates/tickets/publication_mail_fr | 4 +- tickets/urls.py | 2 + tickets/views.py | 103 ++++++------ 16 files changed, 216 insertions(+), 237 deletions(-) create mode 100644 tickets/migrations/0004_auto_20200422_2127.py rename tickets/templates/tickets/{form_preferences.html => edit.html} (67%) delete mode 100644 tickets/templates/tickets/form_ticket.html create mode 100644 tickets/templates/tickets/help_text.html diff --git a/tickets/forms.py b/tickets/forms.py index 4f62db84..b1be6597 100644 --- a/tickets/forms.py +++ b/tickets/forms.py @@ -25,6 +25,7 @@ Ticket form from django import forms +from django.template.loader import render_to_string from django.forms import ModelForm, Form from re2o.field_permissions import FieldPermissionFormMixin from re2o.mixins import FormRevMixin @@ -33,19 +34,31 @@ from django.utils.translation import ugettext_lazy as _ from .models import Ticket -class NewTicketForm(ModelForm): +class NewTicketForm(FormRevMixin, ModelForm): """ Creation of a ticket""" - email = forms.EmailField(required=False) - class Meta: model = Ticket fields = ["title", "description", "email"] + def __init__(self, *args, **kwargs): + request = kwargs.pop("request") + super(NewTicketForm, self).__init__(*args, **kwargs) + if request.user.is_authenticated: + self.fields.pop('email') + self.instance.user = request.user + self.fields['description'].help_text = render_to_string('tickets/help_text.html') + self.instance.request = request -class ChangeStatusTicketForm(ModelForm): - """ Change ticket status""" + +class EditTicketForm(FormRevMixin, ModelForm): + """ Creation of a ticket""" class Meta: model = Ticket - fields = [] + fields = "__all__" + + def __init__(self, *args, **kwargs): + super(EditTicketForm, self).__init__(*args, **kwargs) + self.fields['email'].required = False + diff --git a/tickets/locale/fr/LC_MESSAGES/django.po b/tickets/locale/fr/LC_MESSAGES/django.po index 528bf611..05ce5d9b 100644 --- a/tickets/locale/fr/LC_MESSAGES/django.po +++ b/tickets/locale/fr/LC_MESSAGES/django.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: 2.5\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-04-22 19:00+0200\n" +"POT-Creation-Date: 2020-04-22 22:06+0200\n" "PO-Revision-Date: 2019-11-16 00:35+0100\n" "Last-Translator: Laouen Fernet \n" "Language-Team: \n" @@ -34,32 +34,28 @@ msgstr "" msgid "Title of the ticket." msgstr "Titre du ticket." -#: tickets/models.py:58 -msgid "Description of the ticket." -msgstr "Description du ticket." - -#: tickets/models.py:64 +#: tickets/models.py:63 msgid "An email address to get back to you." msgstr "Une adresse mail pour vous recontacter." -#: tickets/models.py:70 +#: tickets/models.py:69 msgid "Can view a ticket object" msgstr "Peut voir un objet ticket" -#: tickets/models.py:71 +#: tickets/models.py:70 msgid "ticket" msgstr "ticket" -#: tickets/models.py:72 +#: tickets/models.py:71 msgid "tickets" msgstr "tickets" -#: tickets/models.py:76 +#: tickets/models.py:75 #, python-format msgid "Ticket from %(name)s. Date: %(date)s." msgstr "Ticket de %(name)s. Date : %(date)s." -#: tickets/models.py:78 +#: tickets/models.py:77 #, python-format msgid "Anonymous ticket. Date: %s." msgstr "Ticket anonyme. Date : %s." @@ -76,34 +72,22 @@ msgstr "Vous n'avez pas le droit de voir la liste des tickets." 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 +#: tickets/preferences/models.py:39 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:45 -msgid "French" -msgstr "Français" - -#: tickets/preferences/models.py:45 -msgid "English" -msgstr "Anglais" - -#: tickets/preferences/models.py:49 +#: tickets/preferences/models.py:46 msgid "tickets options" msgstr "Options des tickets" -#: tickets/preferences/models.py:50 +#: tickets/preferences/models.py:47 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:31 #: tickets/templates/tickets/contact.html:4 #: tickets/templates/tickets/index.html:29 #: tickets/templates/tickets/preferences.html:6 @@ -111,59 +95,62 @@ msgstr "Peut voir les options des tickets" msgid "Tickets" msgstr "Tickets" -#: tickets/templates/tickets/aff_ticket.html:34 +#: tickets/templates/tickets/aff_ticket.html:35 #, python-format msgid "Ticket #%(id)s" msgstr "Ticket #%(id)s" -#: tickets/templates/tickets/aff_ticket.html:36 +#: tickets/templates/tickets/aff_ticket.html:37 #: tickets/templates/tickets/aff_tickets.html:58 msgid "Solved" msgstr "Résolu" -#: tickets/templates/tickets/aff_ticket.html:38 +#: tickets/templates/tickets/aff_ticket.html:39 msgid "Not solved" msgstr "Non résolu" -#: tickets/templates/tickets/aff_ticket.html:44 +#: tickets/templates/tickets/aff_ticket.html:45 msgid "Opened by" msgstr "Ouvert par" -#: tickets/templates/tickets/aff_ticket.html:50 +#: tickets/templates/tickets/aff_ticket.html:51 msgid "Anonymous user" msgstr "Utilisateur anonyme" -#: tickets/templates/tickets/aff_ticket.html:54 +#: tickets/templates/tickets/aff_ticket.html:55 msgid "Response address: " msgstr "Adresse de réponse : " -#: tickets/templates/tickets/aff_ticket.html:54 +#: tickets/templates/tickets/aff_ticket.html:55 msgid "Response to your ticket" msgstr "Réponse à votre ticket" -#: tickets/templates/tickets/aff_ticket.html:59 +#: tickets/templates/tickets/aff_ticket.html:60 msgid "Title:" msgstr "Titre :" -#: tickets/templates/tickets/aff_ticket.html:60 +#: tickets/templates/tickets/aff_ticket.html:61 msgid "Description:" msgstr "Description :" -#: tickets/templates/tickets/aff_ticket.html:68 +#: tickets/templates/tickets/aff_ticket.html:65 +msgid "Edit this ticket" +msgstr "Modifier le ticket." + +#: tickets/templates/tickets/aff_ticket.html:67 msgid "Mark as solved" msgstr "Marquer comme résolu" -#: tickets/templates/tickets/aff_ticket.html:71 -msgid "Mark as not solved" +#: tickets/templates/tickets/aff_ticket.html:69 +msgid "Mark as unsolved" msgstr "Marquer comme non résolu" -#: tickets/templates/tickets/aff_ticket.html:81 +#: tickets/templates/tickets/aff_ticket.html:78 msgid "All tickets" msgstr "Tous les tickets" #: tickets/templates/tickets/aff_tickets.html:35 -#: tickets/templates/tickets/form_preferences.html:30 -#: tickets/templates/tickets/form_ticket.html:31 +#: tickets/templates/tickets/edit.html:31 msgid "Ticket" msgid_plural "Tickets" msgstr[0] "Ticket" @@ -213,28 +200,11 @@ msgstr "" msgid "Open a ticket" msgstr "Ouvrir un ticket" -#: tickets/templates/tickets/form_preferences.html:33 -msgid "Editing of tickets preferences" -msgstr "Modification des préférences de tickets" - -#: tickets/templates/tickets/form_preferences.html:46 -#: tickets/templates/tickets/preferences.html:14 -msgid "Edit" -msgstr "Modifier" - -#: tickets/templates/tickets/form_ticket.html:34 +#: tickets/templates/tickets/edit.html:34 msgid "Ticket opening" msgstr "Ouverture de ticket" -#: 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." -msgstr "" -"Vous n'êtes pas authentifié. Veuillez vous connecter ou fournir une adresse " -"mail pour que nous puissions vous recontacter." - -#: tickets/templates/tickets/form_ticket.html:44 +#: tickets/templates/tickets/help_text.html:3 msgid "" "Description of your problem. Please give as much information as possible to " "help us searching for a solution. Here is some information we might need:" @@ -243,11 +213,11 @@ msgstr "" "possible pour nous aider à chercher une solution. Voici quelques " "informations dont nous pourrions avoir besoin :" -#: tickets/templates/tickets/form_ticket.html:47 +#: tickets/templates/tickets/help_text.html:6 msgid "The type of your problem (membership, connection, payment etc.)." msgstr "Le type de votre problème (adhésion, connexion, paiement etc.)." -#: tickets/templates/tickets/form_ticket.html:50 +#: tickets/templates/tickets/help_text.html:9 msgid "" "The conditions in which you encounter the problem (Wi-Fi/wired connection, " "on every machines or only one, on a new machine etc.)." @@ -256,7 +226,7 @@ msgstr "" "filaire, sur toutes les machines ou une seule, sur une nouvelle machine " "etc.)." -#: tickets/templates/tickets/form_ticket.html:53 +#: tickets/templates/tickets/help_text.html:12 msgid "" "The locations where you encounter the problem (in your room, in a common " "space, in a specific building etc.)." @@ -264,10 +234,6 @@ msgstr "" "Les lieux où vous rencontrez le problème (dans votre chambre, dans un espace " "commun, dans un bâtiment en particulier etc.)." -#: tickets/templates/tickets/form_ticket.html:56 -msgid "Open the ticket" -msgstr "Ouvrir le ticket" - #: tickets/templates/tickets/index.html:32 msgid "List of tickets" msgstr "Liste des tickets" @@ -276,6 +242,10 @@ msgstr "Liste des tickets" msgid "Manage the tickets" msgstr "Gérer les tickets" +#: tickets/templates/tickets/preferences.html:14 +msgid "Edit" +msgstr "Modifier" + #: tickets/templates/tickets/preferences.html:21 msgid "Publication email address" msgstr "Adresse mail de publication" @@ -284,25 +254,56 @@ msgstr "Adresse mail de publication" msgid "No email address, the tickets will not be published." msgstr "Pas d'adresse mail, les tickets ne seront pas publiés." -#: tickets/templates/tickets/preferences.html:29 -msgid "Email language" -msgstr "Langue du mail" - #: tickets/templates/tickets/profil.html:19 msgid "No tickets" msgstr "Pas de tickets" -#: tickets/views.py:66 tickets/views.py:77 +#: tickets/views.py:56 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:122 tickets/views.py:147 +#: tickets/views.py:102 +msgid "Ticket has been updated successfully" +msgstr "Le ticket a été mis à jour" + +#: tickets/views.py:123 tickets/views.py:148 msgid "Never" msgstr "Jamais" +#~ msgid "Description of the ticket." +#~ msgstr "Description du ticket." + +#~ msgid "Mail language" +#~ msgstr "Langue du mail" + +#~ msgid "French" +#~ msgstr "Français" + +#~ msgid "English" +#~ msgstr "Anglais" + +#~ msgid "Mark as not solved" +#~ msgstr "Marquer comme non résolu" + +#~ msgid "Editing of tickets preferences" +#~ msgstr "Modification des préférences de tickets" + +#~ msgid "" +#~ "You are not authenticated. Please log in or provide an email address so " +#~ "we can get back to you." +#~ msgstr "" +#~ "Vous n'êtes pas authentifié. Veuillez vous connecter ou fournir une " +#~ "adresse mail pour que nous puissions vous recontacter." + +#~ msgid "Open the ticket" +#~ msgstr "Ouvrir le ticket" + +#~ msgid "Email language" +#~ msgstr "Langue du mail" + #~ msgid "The tickets preferences were edited." #~ msgstr "Les préférences de tickets ont été modifiées." diff --git a/tickets/migrations/0004_auto_20200422_2127.py b/tickets/migrations/0004_auto_20200422_2127.py new file mode 100644 index 00000000..c1dfa3f4 --- /dev/null +++ b/tickets/migrations/0004_auto_20200422_2127.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.28 on 2020-04-22 19:27 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tickets', '0003_auto_20200422_1839'), + ] + + operations = [ + migrations.RemoveField( + model_name='ticketoption', + name='mail_language', + ), + migrations.AlterField( + model_name='ticket', + name='description', + field=models.TextField(max_length=3000), + ), + ] diff --git a/tickets/models.py b/tickets/models.py index bf0a3794..5cc7d003 100644 --- a/tickets/models.py +++ b/tickets/models.py @@ -31,7 +31,7 @@ from django.db.models.signals import post_save from django.dispatch import receiver from re2o.mixins import AclMixin -from re2o.mail_utils import send_mail +from django.core.mail import EmailMessage from preferences.models import GeneralOption @@ -55,7 +55,6 @@ class Ticket(AclMixin, models.Model): ) description = models.TextField( max_length=3000, - help_text=_("Description of the ticket."), blank=False, null=False, ) @@ -77,27 +76,28 @@ class Ticket(AclMixin, models.Model): else: return _("Anonymous ticket. Date: %s.") % (self.date) - def publish_mail(self, request=None): + def publish_mail(self): 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 = TicketOption.get_cached_value("mail_language") - if lang == 0: + language = getattr(self.request, "LANGUAGE_CODE", "en") + if language == "fr": obj = "Nouveau ticket ouvert" template = loader.get_template("tickets/publication_mail_fr") else: obj = "New ticket opened" template = loader.get_template("tickets/publication_mail_en") - send_mail( - request, + mail_to_send = EmailMessage( obj, template.render(context), GeneralOption.get_cached_value("email_from"), [to_addr], - fail_silently=False, + reply_to=[self.email], ) + mail_to_send.send(fail_silently=False) + def can_view(self, user_request, *_args, **_kwargs): """ Check that the user has the right to view the ticket @@ -137,4 +137,4 @@ def ticket_post_save(**kwargs): if kwargs["created"]: if TicketOption.get_cached_value("publish_address"): ticket = kwargs["instance"] - ticket.publish_mail(ticket.request) + ticket.publish_mail() diff --git a/tickets/preferences/forms.py b/tickets/preferences/forms.py index 05b40ec3..04845ab8 100644 --- a/tickets/preferences/forms.py +++ b/tickets/preferences/forms.py @@ -42,4 +42,3 @@ class EditTicketOptionForm(FormRevMixin, ModelForm): 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 abc4d5fd..d02202f3 100644 --- a/tickets/preferences/models.py +++ b/tickets/preferences/models.py @@ -41,10 +41,6 @@ class TicketOption(AclMixin, PreferencesModel): max_length=1000, null=True, ) - LANG_FR = 0 - LANG_EN = 1 - LANGUES = ((0, _("French")), (1, _("English"))) - mail_language = models.IntegerField(choices=LANGUES, default=LANG_FR) class Meta: verbose_name = _("tickets options") diff --git a/tickets/preferences/views.py b/tickets/preferences/views.py index f26473a4..29465b1c 100644 --- a/tickets/preferences/views.py +++ b/tickets/preferences/views.py @@ -49,7 +49,6 @@ def aff_preferences(request): 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 diff --git a/tickets/templates/tickets/aff_ticket.html b/tickets/templates/tickets/aff_ticket.html index b66ad1c5..c4b2625d 100644 --- a/tickets/templates/tickets/aff_ticket.html +++ b/tickets/templates/tickets/aff_ticket.html @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% load bootstrap3 %} {% load i18n %} {% load humanize %} +{% load acl %} {% block title %}{% trans "Tickets" %}{% endblock %} @@ -57,21 +58,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,

{% trans "Title:" %} {{ticket.title}}

-

{% trans "Description:" %} {{ ticket.description }}

- +

{% trans "Description:" %} {{ ticket.description | linebreaks }}

+
-
- {% csrf_token %} - {% bootstrap_form changestatusform %} - + {% can_edit ticket %} +

{% trans "Edit this ticket" %}

{% if not ticket.solved %} - {% trans "Mark as solved" as tr_mark_solved %} - {% bootstrap_button tr_mark_solved button_type="submit" button_class='btn-info' %} +

{% trans "Mark as solved" %}

{% else %} - {% trans "Mark as not solved" as tr_mark_not_solved %} - {% bootstrap_button tr_mark_not_solved button_type="submit" button_class='btn-warning' %} +

{% trans "Mark as unsolved" %}

{% endif %} -
+ {% acl_end %}
diff --git a/tickets/templates/tickets/form_preferences.html b/tickets/templates/tickets/edit.html similarity index 67% rename from tickets/templates/tickets/form_preferences.html rename to tickets/templates/tickets/edit.html index d5dd223b..29725fc4 100644 --- a/tickets/templates/tickets/form_preferences.html +++ b/tickets/templates/tickets/edit.html @@ -1,4 +1,4 @@ -{% extends 'machines/sidebar.html' %} +{% extends 'users/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 @@ -25,25 +25,21 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endcomment %} {% load bootstrap3 %} +{% load massive_bootstrap_form %} {% load i18n %} {% block title %}{% trans "Ticket" %}{% endblock %} {% block content %} -

{% trans "Editing of tickets preferences" %}

+

{% trans "Ticket opening" %}

-{% for message in messages %} -
- - {{ message | safe }} -
-{% endfor %} +{% bootstrap_form_errors ticketform %}
{% csrf_token %} - {% bootstrap_field preferencesform.publish_address %} - {% bootstrap_field preferencesform.mail_language %} - {% trans "Edit" as tr_edit %} - {% bootstrap_button tr_edit button_type="submit" icon='ok' button_class='btn-success' %} + {% bootstrap_form ticketform %} + {% bootstrap_button action_name button_type="submit" icon='ok' button_class='btn-success' %}
+ + {% endblock %} diff --git a/tickets/templates/tickets/form_ticket.html b/tickets/templates/tickets/form_ticket.html deleted file mode 100644 index b05803bc..00000000 --- a/tickets/templates/tickets/form_ticket.html +++ /dev/null @@ -1,59 +0,0 @@ -{% extends 'users/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 Lara 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 %} -

{% trans "Ticket opening" %}

- -
- {% csrf_token %} - {% if not user.is_authenticated %} -

{% trans "You are not authenticated. Please log in or provide an email address so we can get back to you." %}

- {% bootstrap_field ticketform.email %} - {% endif %} - {% bootstrap_field ticketform.title %} -
-

{% trans "Description of your problem. Please give as much information as possible to help us searching for a solution. Here is some information we might need:" %}

-
    -
  • -

    {% trans "The type of your problem (membership, connection, payment etc.)." %}

    -
  • -
  • -

    {% trans "The conditions in which you encounter the problem (Wi-Fi/wired connection, on every machines or only one, on a new machine etc.)." %}

    -
  • -
  • -

    {% trans "The locations where you encounter the problem (in your room, in a common space, in a specific building etc.)." %}

    -
- {% bootstrap_field ticketform.description %} - {% trans "Open the ticket" as tr_open %} - {% bootstrap_button tr_open button_type="submit" icon='ok' button_class='btn-success' %} -
-{% endblock %} diff --git a/tickets/templates/tickets/help_text.html b/tickets/templates/tickets/help_text.html new file mode 100644 index 00000000..599d00f7 --- /dev/null +++ b/tickets/templates/tickets/help_text.html @@ -0,0 +1,14 @@ +{% load i18n %} +
+

{% trans "Description of your problem. Please give as much information as possible to help us searching for a solution. Here is some information we might need:" %}

+ + diff --git a/tickets/templates/tickets/preferences.html b/tickets/templates/tickets/preferences.html index 5952a496..5808ce3b 100644 --- a/tickets/templates/tickets/preferences.html +++ b/tickets/templates/tickets/preferences.html @@ -25,12 +25,8 @@

{% trans "No email address, the tickets will not be published." %}

{% endif %} - -

{% trans "Email language" %}

-

{{ language }}

-
- + diff --git a/tickets/templates/tickets/publication_mail_en b/tickets/templates/tickets/publication_mail_en index 5224a80b..1e436877 100644 --- a/tickets/templates/tickets/publication_mail_en +++ b/tickets/templates/tickets/publication_mail_en @@ -7,6 +7,6 @@ An anonymous user (not authenticated) opened a ticket Answer to the address:{{ticket.email}}. {% endif %} -Title: {{ticket.title}} +Title: {{ ticket.title | safe }} -Description: {{ticket.description}} +Description: {{ ticket.description | safe }} diff --git a/tickets/templates/tickets/publication_mail_fr b/tickets/templates/tickets/publication_mail_fr index ef1099da..3b733e8f 100644 --- a/tickets/templates/tickets/publication_mail_fr +++ b/tickets/templates/tickets/publication_mail_fr @@ -7,6 +7,6 @@ Un utilisateur anonyme (non connecté) a ouvert un ticket. Répondre à l'adresse : {{ticket.email}}. {% endif %} -Titre : {{ticket.title}} +Titre : {{ ticket.title | safe }} -Description : {{ticket.description}} +Description : {{ ticket.description | safe }} diff --git a/tickets/urls.py b/tickets/urls.py index c6eaefde..dee41a14 100644 --- a/tickets/urls.py +++ b/tickets/urls.py @@ -31,6 +31,8 @@ from .preferences.views import edit_options urlpatterns = [ url(r"^$", views.aff_tickets, name="aff-tickets"), url(r"^(?P[0-9]+)$", views.aff_ticket, name="aff-ticket"), + url(r"^change_ticket_status/(?P[0-9]+)$", views.change_ticket_status, name="change-ticket-status"), + url(r"^edit_ticket/(?P[0-9]+)$", views.edit_ticket, name="edit-ticket"), url( r"^edit_options/(?P
TicketOption)$", edit_options, diff --git a/tickets/views.py b/tickets/views.py index f5186cdf..f8342476 100644 --- a/tickets/views.py +++ b/tickets/views.py @@ -42,70 +42,71 @@ from preferences.models import GeneralOption from .models import Ticket -from .forms import NewTicketForm, ChangeStatusTicketForm +from .forms import NewTicketForm, EditTicketForm def new_ticket(request): """ Ticket creation view""" - ticketform = NewTicketForm(request.POST or None) - - if request.method == "POST": - ticketform = NewTicketForm(request.POST) - - if ticketform.is_valid(): - email = ticketform.cleaned_data.get("email") - ticket = ticketform.save(commit=False) - ticket.request = request - - if request.user.is_authenticated: - ticket.user = request.user - ticket.save() - messages.success( - request, - _( - "Your ticket has been succesfully opened. We will take care of it as soon as possible." - ), - ) - return redirect( - reverse("users:profil", kwargs={"userid": str(request.user.id)}) - ) - if not request.user.is_authenticated and email != "": - ticket.save() - messages.success( - request, - _( - "Your ticket has been succesfully opened. We will take care of it as soon as possible." - ), - ) - return redirect(reverse("index")) - else: - messages.error( - request, - _( - "You are not authenticated. Please log in or provide an email address so we can get back to you." - ), - ) - return form( - {"ticketform": ticketform}, "tickets/form_ticket.html", request - ) - - else: - ticketform = NewTicketForm - return form({"ticketform": ticketform}, "tickets/form_ticket.html", request) + ticketform = NewTicketForm(request.POST or None, request=request) + if ticketform.is_valid(): + ticketform.save() + messages.success( + request, + _( + "Your ticket has been succesfully opened. We will take care of it as soon as possible." + ), + ) + if not request.user.is_authenticated: + return redirect(reverse("index")) + else: + return redirect( + reverse("users:profil", kwargs={"userid": str(request.user.id)}) + ) + return form( + {"ticketform": ticketform, 'action_name': ("Create a ticket")}, "tickets/edit.html", request + ) @login_required @can_view(Ticket) def aff_ticket(request, ticket, ticketid): """View to display only one ticket""" - changestatusform = ChangeStatusTicketForm(request.POST) - if request.method == "POST": - ticket.solved = not ticket.solved - ticket.save() return render( request, "tickets/aff_ticket.html", - {"ticket": ticket, "changestatusform": changestatusform}, + {"ticket": ticket}, + ) + + +@login_required +@can_edit(Ticket) +def change_ticket_status(request, ticket, ticketid): + """View to edit ticket state""" + ticket.solved = not ticket.solved + ticket.save() + return redirect( + reverse("tickets:aff-ticket", kwargs={"ticketid": str(ticketid)}) + ) + + +@login_required +@can_edit(Ticket) +def edit_ticket(request, ticket, ticketid): + """ Ticket creation view""" + ticketform = EditTicketForm(request.POST or None, instance=ticket) + if ticketform.is_valid(): + ticketform.save() + messages.success( + request, + _( + "Ticket has been updated successfully" + ), + ) + return redirect( + reverse("tickets:aff-ticket", kwargs={"ticketid": str(ticketid)}) + ) + return form( + {"ticketform": ticketform, 'action_name': ("Edit this ticket")}, "tickets/edit.html", request )