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

Fix and harmonize some issues in ticket app

This commit is contained in:
Gabriel Detraz 2020-04-22 21:37:21 +02:00
parent acf510a8e7
commit c8c89fab1d
16 changed files with 216 additions and 237 deletions

View file

@ -25,6 +25,7 @@ Ticket form
from django import forms from django import forms
from django.template.loader import render_to_string
from django.forms import ModelForm, Form from django.forms import ModelForm, Form
from re2o.field_permissions import FieldPermissionFormMixin from re2o.field_permissions import FieldPermissionFormMixin
from re2o.mixins import FormRevMixin from re2o.mixins import FormRevMixin
@ -33,19 +34,31 @@ from django.utils.translation import ugettext_lazy as _
from .models import Ticket from .models import Ticket
class NewTicketForm(ModelForm): class NewTicketForm(FormRevMixin, ModelForm):
""" Creation of a ticket""" """ Creation of a ticket"""
email = forms.EmailField(required=False)
class Meta: class Meta:
model = Ticket model = Ticket
fields = ["title", "description", "email"] 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: class Meta:
model = Ticket model = Ticket
fields = [] fields = "__all__"
def __init__(self, *args, **kwargs):
super(EditTicketForm, self).__init__(*args, **kwargs)
self.fields['email'].required = False

View file

@ -21,7 +21,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 2.5\n" "Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: 2019-11-16 00:35+0100\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n" "Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language-Team: \n" "Language-Team: \n"
@ -34,32 +34,28 @@ msgstr ""
msgid "Title of the ticket." msgid "Title of the ticket."
msgstr "Titre du ticket." msgstr "Titre du ticket."
#: tickets/models.py:58 #: tickets/models.py:63
msgid "Description of the ticket."
msgstr "Description du ticket."
#: 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:70 #: tickets/models.py:69
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:71 #: tickets/models.py:70
msgid "ticket" msgid "ticket"
msgstr "ticket" msgstr "ticket"
#: tickets/models.py:72 #: tickets/models.py:71
msgid "tickets" msgid "tickets"
msgstr "tickets" msgstr "tickets"
#: tickets/models.py:76 #: tickets/models.py:75
#, 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:78 #: tickets/models.py:77
#, python-format #, python-format
msgid "Anonymous ticket. Date: %s." msgid "Anonymous ticket. Date: %s."
msgstr "Ticket anonyme. 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" msgid "Publish address"
msgstr "Adresse mail de publication" msgstr "Adresse mail de publication"
#: tickets/preferences/forms.py:45 #: tickets/preferences/models.py:39
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:45 #: tickets/preferences/models.py:46
msgid "French"
msgstr "Français"
#: tickets/preferences/models.py:45
msgid "English"
msgstr "Anglais"
#: tickets/preferences/models.py:49
msgid "tickets options" msgid "tickets options"
msgstr "Options des tickets" msgstr "Options des tickets"
#: tickets/preferences/models.py:50 #: tickets/preferences/models.py:47
msgid "Can view tickets options" msgid "Can view tickets options"
msgstr "Peut voir les options des tickets" 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/contact.html:4
#: tickets/templates/tickets/index.html:29 #: tickets/templates/tickets/index.html:29
#: tickets/templates/tickets/preferences.html:6 #: tickets/templates/tickets/preferences.html:6
@ -111,59 +95,62 @@ msgstr "Peut voir les options des tickets"
msgid "Tickets" msgid "Tickets"
msgstr "Tickets" msgstr "Tickets"
#: tickets/templates/tickets/aff_ticket.html:34 #: tickets/templates/tickets/aff_ticket.html:35
#, python-format #, python-format
msgid "Ticket #%(id)s" msgid "Ticket #%(id)s"
msgstr "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 #: tickets/templates/tickets/aff_tickets.html:58
msgid "Solved" msgid "Solved"
msgstr "Résolu" msgstr "Résolu"
#: tickets/templates/tickets/aff_ticket.html:38 #: tickets/templates/tickets/aff_ticket.html:39
msgid "Not solved" msgid "Not solved"
msgstr "Non résolu" msgstr "Non résolu"
#: tickets/templates/tickets/aff_ticket.html:44 #: tickets/templates/tickets/aff_ticket.html:45
msgid "Opened by" msgid "Opened by"
msgstr "Ouvert par" msgstr "Ouvert par"
#: tickets/templates/tickets/aff_ticket.html:50 #: tickets/templates/tickets/aff_ticket.html:51
msgid "Anonymous user" msgid "Anonymous user"
msgstr "Utilisateur anonyme" msgstr "Utilisateur anonyme"
#: tickets/templates/tickets/aff_ticket.html:54 #: tickets/templates/tickets/aff_ticket.html:55
msgid "Response address: " msgid "Response address: "
msgstr "Adresse de réponse : " msgstr "Adresse de réponse : "
#: tickets/templates/tickets/aff_ticket.html:54 #: tickets/templates/tickets/aff_ticket.html:55
msgid "Response to your ticket" msgid "Response to your ticket"
msgstr "Réponse à votre ticket" msgstr "Réponse à votre ticket"
#: tickets/templates/tickets/aff_ticket.html:59 #: tickets/templates/tickets/aff_ticket.html:60
msgid "Title:" msgid "Title:"
msgstr "Titre :" msgstr "Titre :"
#: tickets/templates/tickets/aff_ticket.html:60 #: tickets/templates/tickets/aff_ticket.html:61
msgid "Description:" msgid "Description:"
msgstr "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" msgid "Mark as solved"
msgstr "Marquer comme résolu" msgstr "Marquer comme résolu"
#: tickets/templates/tickets/aff_ticket.html:71 #: tickets/templates/tickets/aff_ticket.html:69
msgid "Mark as not solved" msgid "Mark as unsolved"
msgstr "Marquer comme non résolu" msgstr "Marquer comme non résolu"
#: tickets/templates/tickets/aff_ticket.html:81 #: tickets/templates/tickets/aff_ticket.html:78
msgid "All tickets" msgid "All tickets"
msgstr "Tous les tickets" msgstr "Tous les tickets"
#: tickets/templates/tickets/aff_tickets.html:35 #: tickets/templates/tickets/aff_tickets.html:35
#: tickets/templates/tickets/form_preferences.html:30 #: tickets/templates/tickets/edit.html:31
#: tickets/templates/tickets/form_ticket.html:31
msgid "Ticket" msgid "Ticket"
msgid_plural "Tickets" msgid_plural "Tickets"
msgstr[0] "Ticket" msgstr[0] "Ticket"
@ -213,28 +200,11 @@ msgstr ""
msgid "Open a ticket" msgid "Open a ticket"
msgstr "Ouvrir un ticket" msgstr "Ouvrir un ticket"
#: tickets/templates/tickets/form_preferences.html:33 #: tickets/templates/tickets/edit.html:34
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
msgid "Ticket opening" msgid "Ticket opening"
msgstr "Ouverture de ticket" msgstr "Ouverture de ticket"
#: tickets/templates/tickets/form_ticket.html:39 tickets/views.py:85 #: tickets/templates/tickets/help_text.html:3
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
msgid "" msgid ""
"Description of your problem. Please give as much information as possible to " "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:" "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 " "possible pour nous aider à chercher une solution. Voici quelques "
"informations dont nous pourrions avoir besoin :" "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.)." msgid "The type of your problem (membership, connection, payment etc.)."
msgstr "Le type de votre problème (adhésion, connexion, paiement 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 "" msgid ""
"The conditions in which you encounter the problem (Wi-Fi/wired connection, " "The conditions in which you encounter the problem (Wi-Fi/wired connection, "
"on every machines or only one, on a new machine etc.)." "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 " "filaire, sur toutes les machines ou une seule, sur une nouvelle machine "
"etc.)." "etc.)."
#: tickets/templates/tickets/form_ticket.html:53 #: tickets/templates/tickets/help_text.html:12
msgid "" msgid ""
"The locations where you encounter the problem (in your room, in a common " "The locations where you encounter the problem (in your room, in a common "
"space, in a specific building etc.)." "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 " "Les lieux où vous rencontrez le problème (dans votre chambre, dans un espace "
"commun, dans un bâtiment en particulier etc.)." "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 #: tickets/templates/tickets/index.html:32
msgid "List of tickets" msgid "List of tickets"
msgstr "Liste des tickets" msgstr "Liste des tickets"
@ -276,6 +242,10 @@ msgstr "Liste des tickets"
msgid "Manage the tickets" msgid "Manage the tickets"
msgstr "Gérer les tickets" msgstr "Gérer les tickets"
#: tickets/templates/tickets/preferences.html:14
msgid "Edit"
msgstr "Modifier"
#: tickets/templates/tickets/preferences.html:21 #: tickets/templates/tickets/preferences.html:21
msgid "Publication email address" msgid "Publication email address"
msgstr "Adresse mail de publication" msgstr "Adresse mail de publication"
@ -284,25 +254,56 @@ msgstr "Adresse mail de publication"
msgid "No email address, the tickets will not be published." msgid "No email address, the tickets will not be published."
msgstr "Pas d'adresse mail, les tickets ne seront pas publiés." 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 #: tickets/templates/tickets/profil.html:19
msgid "No tickets" msgid "No tickets"
msgstr "Pas de tickets" msgstr "Pas de tickets"
#: tickets/views.py:66 tickets/views.py:77 #: tickets/views.py:56
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: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" msgid "Never"
msgstr "Jamais" 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." #~ 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."

View file

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

View file

@ -31,7 +31,7 @@ from django.db.models.signals import post_save
from django.dispatch import receiver from django.dispatch import receiver
from re2o.mixins import AclMixin from re2o.mixins import AclMixin
from re2o.mail_utils import send_mail from django.core.mail import EmailMessage
from preferences.models import GeneralOption from preferences.models import GeneralOption
@ -55,7 +55,6 @@ class Ticket(AclMixin, models.Model):
) )
description = models.TextField( description = models.TextField(
max_length=3000, max_length=3000,
help_text=_("Description of the ticket."),
blank=False, blank=False,
null=False, null=False,
) )
@ -77,27 +76,28 @@ class Ticket(AclMixin, models.Model):
else: else:
return _("Anonymous ticket. Date: %s.") % (self.date) 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") site_url = GeneralOption.get_cached_value("main_site_url")
to_addr = TicketOption.get_cached_value("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 = TicketOption.get_cached_value("mail_language") language = getattr(self.request, "LANGUAGE_CODE", "en")
if lang == 0: if language == "fr":
obj = "Nouveau ticket ouvert" obj = "Nouveau ticket ouvert"
template = loader.get_template("tickets/publication_mail_fr") template = loader.get_template("tickets/publication_mail_fr")
else: else:
obj = "New ticket opened" obj = "New ticket opened"
template = loader.get_template("tickets/publication_mail_en") template = loader.get_template("tickets/publication_mail_en")
send_mail( mail_to_send = EmailMessage(
request,
obj, obj,
template.render(context), template.render(context),
GeneralOption.get_cached_value("email_from"), GeneralOption.get_cached_value("email_from"),
[to_addr], [to_addr],
fail_silently=False, reply_to=[self.email],
) )
mail_to_send.send(fail_silently=False)
def can_view(self, user_request, *_args, **_kwargs): def can_view(self, user_request, *_args, **_kwargs):
""" Check that the user has the right to view the ticket """ Check that the user has the right to view the ticket
@ -137,4 +137,4 @@ def ticket_post_save(**kwargs):
if kwargs["created"]: if kwargs["created"]:
if TicketOption.get_cached_value("publish_address"): if TicketOption.get_cached_value("publish_address"):
ticket = kwargs["instance"] ticket = kwargs["instance"]
ticket.publish_mail(ticket.request) ticket.publish_mail()

View file

@ -42,4 +42,3 @@ class EditTicketOptionForm(FormRevMixin, ModelForm):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
super(EditTicketOptionForm, self).__init__(*args, prefix=prefix, **kwargs) super(EditTicketOptionForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields["publish_address"].label = _("Publish address") self.fields["publish_address"].label = _("Publish address")
self.fields["mail_language"].label = _("Mail language")

View file

@ -41,10 +41,6 @@ class TicketOption(AclMixin, PreferencesModel):
max_length=1000, max_length=1000,
null=True, null=True,
) )
LANG_FR = 0
LANG_EN = 1
LANGUES = ((0, _("French")), (1, _("English")))
mail_language = models.IntegerField(choices=LANGUES, default=LANG_FR)
class Meta: class Meta:
verbose_name = _("tickets options") verbose_name = _("tickets options")

View file

@ -49,7 +49,6 @@ def aff_preferences(request):
pref, created = models.TicketOption.objects.get_or_create() pref, created = models.TicketOption.objects.get_or_create()
context = { context = {
"preferences": pref, "preferences": pref,
"language": str(pref.LANGUES[pref.mail_language][1]),
} }
return render_to_string( return render_to_string(
"tickets/preferences.html", context=context, request=request, using=None "tickets/preferences.html", context=context, request=request, using=None

View file

@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% load bootstrap3 %} {% load bootstrap3 %}
{% load i18n %} {% load i18n %}
{% load humanize %} {% load humanize %}
{% load acl %}
{% block title %}{% trans "Tickets" %}{% endblock %} {% block title %}{% trans "Tickets" %}{% endblock %}
@ -57,21 +58,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<div class="panel-body"> <div class="panel-body">
<p><b>{% trans "Title:" %}</b> {{ticket.title}}</p> <p><b>{% trans "Title:" %}</b> {{ticket.title}}</p>
<p><b>{% trans "Description:" %}</b> {{ ticket.description }}</p> <p><b>{% trans "Description:" %}</b> {{ ticket.description | linebreaks }}</p>
<div class="text-right"> <div class="text-right">
<form class="form" method="post"> {% can_edit ticket %}
{% csrf_token %} <a type="button" href="{% url 'tickets:edit-ticket' ticket.id %}" class="btn btn-info"><p>{% trans "Edit this ticket" %}</p></a>
{% bootstrap_form changestatusform %}
{% if not ticket.solved %} {% if not ticket.solved %}
{% trans "Mark as solved" as tr_mark_solved %} <a type="button" href="{% url 'tickets:change-ticket-status' ticket.id %}" class="btn btn-success"><p>{% trans "Mark as solved" %}</p></a>
{% bootstrap_button tr_mark_solved button_type="submit" button_class='btn-info' %}
{% else %} {% else %}
{% trans "Mark as not solved" as tr_mark_not_solved %} <a type="button" href="{% url 'tickets:change-ticket-status' ticket.id %}" class="btn btn-warning"><p>{% trans "Mark as unsolved" %}</p></a>
{% bootstrap_button tr_mark_not_solved button_type="submit" button_class='btn-warning' %}
{% endif %} {% endif %}
</form> {% acl_end %}
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,4 +1,4 @@
{% extends 'machines/sidebar.html' %} {% extends 'users/sidebar.html' %}
{% comment %} {% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il 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 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 %} {% endcomment %}
{% load bootstrap3 %} {% load bootstrap3 %}
{% load massive_bootstrap_form %}
{% load i18n %} {% load i18n %}
{% block title %}{% trans "Ticket" %}{% endblock %} {% block title %}{% trans "Ticket" %}{% endblock %}
{% block content %} {% block content %}
<h2> {% trans "Editing of tickets preferences" %}</h2> <h2>{% trans "Ticket opening" %}</h2>
{% for message in messages %} {% bootstrap_form_errors ticketform %}
<div class="{{ message| bootstrap_message_classes }} alert-dismissable">
<button type="button" class="close" data_dismiss="alert" aria-hidden="true">&#125;</button>
{{ message | safe }}
</div>
{% endfor %}
<form class="form" method="post"> <form class="form" method="post">
{% csrf_token %} {% csrf_token %}
{% bootstrap_field preferencesform.publish_address %} {% bootstrap_form ticketform %}
{% bootstrap_field preferencesform.mail_language %} {% bootstrap_button action_name button_type="submit" icon='ok' button_class='btn-success' %}
{% trans "Edit" as tr_edit %}
{% bootstrap_button tr_edit button_type="submit" icon='ok' button_class='btn-success' %}
</form> </form>
{% endblock %} {% endblock %}

View file

@ -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 %}
<h2>{% trans "Ticket opening" %}</h2>
<form class="form" method="post">
{% csrf_token %}
{% if not user.is_authenticated %}
<p>{% trans "You are not authenticated. Please log in or provide an email address so we can get back to you." %}</p>
{% bootstrap_field ticketform.email %}
{% endif %}
{% bootstrap_field ticketform.title %}
<br>
<p>{% 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:" %}</p>
<ul class="list">
<li>
<p> {% trans "The type of your problem (membership, connection, payment etc.)." %}</p>
</li>
<li>
<p> {% trans "The conditions in which you encounter the problem (Wi-Fi/wired connection, on every machines or only one, on a new machine etc.)." %}</p>
</li>
<li>
<p> {% trans "The locations where you encounter the problem (in your room, in a common space, in a specific building etc.)." %}</p>
</ul>
{% bootstrap_field ticketform.description %}
{% trans "Open the ticket" as tr_open %}
{% bootstrap_button tr_open button_type="submit" icon='ok' button_class='btn-success' %}
</form>
{% endblock %}

View file

@ -0,0 +1,14 @@
{% load i18n %}
<br>
<p>{% 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:" %}</p>
<ul class="list">
<li>
<p> {% trans "The type of your problem (membership, connection, payment etc.)." %}</p>
</li>
<li>
<p> {% trans "The conditions in which you encounter the problem (Wi-Fi/wired connection, on every machines or only one, on a new machine etc.)." %}</p>
</li>
<li>
<p> {% trans "The locations where you encounter the problem (in your room, in a common space, in a specific building etc.)." %}</p>
</ul>

View file

@ -25,12 +25,8 @@
<td><p>{% trans "No email address, the tickets will not be published." %}</p></td> <td><p>{% trans "No email address, the tickets will not be published." %}</p></td>
{% endif %} {% endif %}
</tr> </tr>
<tr>
<th><p>{% trans "Email language" %}</p></th>
<td><p>{{ language }}</p></th>
</tr>
<table class="table"> <table class="table">
</table> </table>
</div> </div>
</div> </div>
</div> </div>

View file

@ -7,6 +7,6 @@ An anonymous user (not authenticated) opened a ticket
Answer to the address:{{ticket.email}}. Answer to the address:{{ticket.email}}.
{% endif %} {% endif %}
Title: {{ticket.title}} Title: {{ ticket.title | safe }}
Description: {{ticket.description}} Description: {{ ticket.description | safe }}

View file

@ -7,6 +7,6 @@ Un utilisateur anonyme (non connecté) a ouvert un ticket.
Répondre à l'adresse : {{ticket.email}}. Répondre à l'adresse : {{ticket.email}}.
{% endif %} {% endif %}
Titre : {{ticket.title}} Titre : {{ ticket.title | safe }}
Description : {{ticket.description}} Description : {{ ticket.description | safe }}

View file

@ -31,6 +31,8 @@ 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"^(?P<ticketid>[0-9]+)$", views.aff_ticket, name="aff-ticket"), url(r"^(?P<ticketid>[0-9]+)$", views.aff_ticket, name="aff-ticket"),
url(r"^change_ticket_status/(?P<ticketid>[0-9]+)$", views.change_ticket_status, name="change-ticket-status"),
url(r"^edit_ticket/(?P<ticketid>[0-9]+)$", views.edit_ticket, name="edit-ticket"),
url( url(
r"^edit_options/(?P<section>TicketOption)$", r"^edit_options/(?P<section>TicketOption)$",
edit_options, edit_options,

View file

@ -42,70 +42,71 @@ from preferences.models import GeneralOption
from .models import Ticket from .models import Ticket
from .forms import NewTicketForm, ChangeStatusTicketForm from .forms import NewTicketForm, EditTicketForm
def new_ticket(request): def new_ticket(request):
""" Ticket creation view""" """ Ticket creation view"""
ticketform = NewTicketForm(request.POST or None) ticketform = NewTicketForm(request.POST or None, request=request)
if ticketform.is_valid():
if request.method == "POST": ticketform.save()
ticketform = NewTicketForm(request.POST) messages.success(
request,
if ticketform.is_valid(): _(
email = ticketform.cleaned_data.get("email") "Your ticket has been succesfully opened. We will take care of it as soon as possible."
ticket = ticketform.save(commit=False) ),
ticket.request = request )
if not request.user.is_authenticated:
if request.user.is_authenticated: return redirect(reverse("index"))
ticket.user = request.user else:
ticket.save() return redirect(
messages.success( reverse("users:profil", kwargs={"userid": str(request.user.id)})
request, )
_( return form(
"Your ticket has been succesfully opened. We will take care of it as soon as possible." {"ticketform": ticketform, 'action_name': ("Create a ticket")}, "tickets/edit.html", request
), )
)
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)
@login_required @login_required
@can_view(Ticket) @can_view(Ticket)
def aff_ticket(request, ticket, ticketid): def aff_ticket(request, ticket, ticketid):
"""View to display only one ticket""" """View to display only one ticket"""
changestatusform = ChangeStatusTicketForm(request.POST)
if request.method == "POST":
ticket.solved = not ticket.solved
ticket.save()
return render( return render(
request, request,
"tickets/aff_ticket.html", "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
) )