mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-08-20 06:03:40 +00:00
La doc en anglais et le commentaires en moins
This commit is contained in:
parent
d59783fd6b
commit
0f203f43e4
5 changed files with 61 additions and 64 deletions
|
@ -8,28 +8,16 @@ from .models import(
|
|||
Ticket,
|
||||
)
|
||||
|
||||
class EditTicketForm(FormRevMixin, ModelForm):
|
||||
"""Formulaire d'edition d'un Ticket"""
|
||||
class Meta:
|
||||
model = Ticket
|
||||
exclude = ['user','assigned_staff','date']
|
||||
|
||||
|
||||
class NewTicketForm(ModelForm):
|
||||
""" Creation d'une machine"""
|
||||
""" Creation of a ticket"""
|
||||
email = forms.EmailField(required=False)
|
||||
class Meta:
|
||||
model = Ticket
|
||||
fields = ['title', 'description', 'email']
|
||||
"""
|
||||
class EditPreferencesForm(ModelForm):
|
||||
class Meta:
|
||||
model = Preferences
|
||||
fields = '__all__'
|
||||
"""
|
||||
|
||||
class ChangeStatusTicketForm(ModelForm):
|
||||
""" Passe un Ticket en résolu """
|
||||
""" Change ticket status"""
|
||||
class Meta:
|
||||
model = Ticket
|
||||
fields = []
|
||||
|
|
|
@ -14,7 +14,7 @@ import users.models
|
|||
from .preferences.models import Preferences
|
||||
|
||||
class Ticket(AclMixin, models.Model):
|
||||
"""Class définissant un ticket"""
|
||||
"""Model of a ticket"""
|
||||
|
||||
user = models.ForeignKey(
|
||||
'users.User',
|
||||
|
@ -24,26 +24,19 @@ class Ticket(AclMixin, models.Model):
|
|||
null=True)
|
||||
title = models.CharField(
|
||||
max_length=255,
|
||||
help_text=_("Nom du ticket"),
|
||||
help_text=_("Title of the ticket"),
|
||||
blank=False,
|
||||
null=False,)
|
||||
description = models.TextField(
|
||||
max_length=3000,
|
||||
help_text=_("Description du ticket"),
|
||||
help_text=_("Description of the ticket"),
|
||||
blank=False,
|
||||
null=False)
|
||||
date = models.DateTimeField(auto_now_add=True)
|
||||
email = models.EmailField(
|
||||
help_text = _("Une adresse mail pour vous recontacter"),
|
||||
help_text = _("An email address to get back to you"),
|
||||
max_length=100,
|
||||
null=True)
|
||||
assigned_staff = models.ForeignKey(
|
||||
'users.User',
|
||||
on_delete=models.PROTECT,
|
||||
related_name="tickets_assigned",
|
||||
blank=True,
|
||||
null=True)
|
||||
#categories = models.OneToManyFiled('Category')
|
||||
solved = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
|
@ -52,9 +45,9 @@ class Ticket(AclMixin, models.Model):
|
|||
|
||||
def __str__(self):
|
||||
if self.user:
|
||||
return "Ticket de {}. Date: {}".format(self.user.surname,self.date)
|
||||
return "Ticket from {}. Date: {}".format(self.user.surname,self.date)
|
||||
else:
|
||||
return "Ticket anonyme. Date: {}".format(self.date)
|
||||
return "Anonymous Ticket. Date: {}".format(self.date)
|
||||
|
||||
def publish_mail(self):
|
||||
site_url = GeneralOption.objects.first().main_site_url
|
||||
|
@ -69,38 +62,28 @@ class Ticket(AclMixin, models.Model):
|
|||
fail_silently = False)
|
||||
|
||||
def can_view(self, user_request, *_args, **_kwargs):
|
||||
"""Verifie que la personne à le droit pour voir le ticket
|
||||
ou qu'elle est l'auteur du ticket"""
|
||||
""" Check that the user has the right to view the ticket
|
||||
or that it is the author"""
|
||||
if (not user_request.has_perm('tickets.view_ticket') and self.user != user_request):
|
||||
return False, _("You don't have the right to view other Tickets than yours.")
|
||||
return False, _("You don't have the right to view other tickets than yours.")
|
||||
else:
|
||||
return True, None
|
||||
|
||||
@staticmethod
|
||||
def can_view_all(user_request, *_args, **_kwargs):
|
||||
"""Vérifie si l'user a acccés à la liste de tous les tickets"""
|
||||
""" Check that the user has access to the list of all tickets"""
|
||||
return(
|
||||
user_request.has_perm('tickets.view_tickets'),
|
||||
_("You don't have the right to view the list of tickets.")
|
||||
)
|
||||
|
||||
def can_create(user_request,*_args, **_kwargs):
|
||||
"""Autorise tout les utilisateurs à créer des tickets"""
|
||||
""" Authorise all users to open tickets """
|
||||
return True,None
|
||||
"""
|
||||
class Preferences(models.Model):
|
||||
|
||||
publish_address = models.EmailField(
|
||||
help_text = _("Adresse mail pour annoncer les nouveau tickets (laisser vide pour ne rien annoncer)"),
|
||||
max_length = 1000,
|
||||
null = True)
|
||||
class Meta:
|
||||
verbose_name = _("Préférences des tickets")
|
||||
"""
|
||||
|
||||
@receiver(post_save, sender=Ticket)
|
||||
def ticket_post_save(**kwargs):
|
||||
"""Envoit du mail de publication du ticket"""
|
||||
""" Send the mail to publish the new ticket """
|
||||
if kwargs['created']:
|
||||
if Preferences.objects.first().publish_address:
|
||||
ticket = kwargs['instance']
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from .models import Preferences
|
||||
|
||||
class EditPreferencesForm(ModelForm):
|
||||
""" Edition des préférences des tickets """
|
||||
""" Edit the ticket's settings"""
|
||||
class Meta:
|
||||
model = Preferences
|
||||
fields = '__all__'
|
||||
|
|
|
@ -2,11 +2,11 @@ from django.db import models
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
class Preferences(models.Model):
|
||||
""" Class cannonique définissants les préférences des tickets """
|
||||
""" Definition of the ticket's settings"""
|
||||
|
||||
publish_address = models.EmailField(
|
||||
help_text = _("Adresse mail pour annoncer les nouveau tickets (laisser vide pour ne rien annoncer)"),
|
||||
help_text = _("Email address to publish the new tickets (leave empty for no publications)"),
|
||||
max_length = 1000,
|
||||
null = True)
|
||||
class Meta:
|
||||
verbose_name = _("Préférences des tickets")
|
||||
verbose_name = _("Ticket's settings")
|
||||
|
|
|
@ -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 © 2017 Gabriel Détraz
|
||||
# Copyright © 2017 Goulven Kermarec
|
||||
# Copyright © 2017 Augustin Lemesle
|
||||
#
|
||||
# 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
|
||||
# Goulven 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
|
||||
|
@ -40,7 +68,7 @@ from .preferences.forms import (
|
|||
|
||||
|
||||
def new_ticket(request):
|
||||
""" Vue de création d'un ticket """
|
||||
""" Ticket creation view"""
|
||||
ticketform = NewTicketForm(request.POST or None)
|
||||
|
||||
if request.method == 'POST':
|
||||
|
@ -49,18 +77,17 @@ def new_ticket(request):
|
|||
if ticketform.is_valid():
|
||||
email = ticketform.cleaned_data.get('email')
|
||||
ticket = ticketform.save(commit=False)
|
||||
#raise ValueError("email: {} type: {}".format(email,type(email)))
|
||||
if request.user.is_authenticated:
|
||||
ticket.user = request.user
|
||||
ticket.save()
|
||||
messages.success(request,'Votre ticket a été ouvert. Nous vous répondrons le plus rapidement possible.')
|
||||
messages.success(request,_('Your ticket has been succesfully open. 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,'Votre ticket a été ouvert. Nous vous répondront le plus rapidement possible.')
|
||||
messages.success(request,_('Your ticket has been succesfully open. We will take care of it as soon as possible.'))
|
||||
return redirect(reverse('index'))
|
||||
else:
|
||||
messages.error(request,"Vous n'êtes pas authentifié, veuillez vous authentifier ou fournir une adresse mail pour que nous puissions vous recontacter")
|
||||
messages.error(request,_("You are not authenticated. Please login or provide an email address so we can get back to you."))
|
||||
return form({'ticketform':ticketform,},'tickets/form_ticket.html',request)
|
||||
|
||||
else:
|
||||
|
@ -70,7 +97,7 @@ def new_ticket(request):
|
|||
@login_required
|
||||
@can_view(Ticket)
|
||||
def aff_ticket(request, ticket, ticketid):
|
||||
"""Vue d'affichage d'un ticket"""
|
||||
"""View to display only one ticket"""
|
||||
changestatusform = ChangeStatusTicketForm(request.POST)
|
||||
if request.method == 'POST':
|
||||
ticket.solved = not ticket.solved
|
||||
|
@ -80,14 +107,14 @@ def aff_ticket(request, ticket, ticketid):
|
|||
@login_required
|
||||
@can_view_all(Ticket)
|
||||
def aff_tickets(request):
|
||||
""" Vue d'affichage de tout les tickets """
|
||||
""" View to display all the tickets """
|
||||
tickets_list = Ticket.objects.all().order_by('-date')
|
||||
nbr_tickets = tickets_list.count()
|
||||
nbr_tickets_unsolved = tickets_list.filter(solved=False).count()
|
||||
if nbr_tickets:
|
||||
last_ticket_date = tickets_list.first().date
|
||||
else:
|
||||
last_ticket_date = "Jamais"
|
||||
last_ticket_date = _("Never")
|
||||
|
||||
pagination_number = (GeneralOption
|
||||
.get_cached_value('pagination_number'))
|
||||
|
@ -107,7 +134,7 @@ def aff_tickets(request):
|
|||
|
||||
|
||||
def edit_preferences(request):
|
||||
""" Vue d'édition des préférences des tickets """
|
||||
""" View to edit the settings of the tickets """
|
||||
|
||||
preferences_instance, created = Preferences.objects.get_or_create(id=1)
|
||||
preferencesform = EditPreferencesForm(
|
||||
|
@ -126,14 +153,14 @@ def edit_preferences(request):
|
|||
|
||||
# views cannoniques des apps optionnels
|
||||
def profil(request,user):
|
||||
""" Vue cannonique d'affichage des tickets dans l'accordeon du profil"""
|
||||
""" View to display the ticket's module on the profil"""
|
||||
tickets_list = Ticket.objects.filter(user=user).all().order_by('-date')
|
||||
nbr_tickets = tickets_list.count()
|
||||
nbr_tickets_unsolved = tickets_list.filter(solved=False).count()
|
||||
if nbr_tickets:
|
||||
last_ticket_date = tickets_list.first().date
|
||||
else:
|
||||
last_ticket_date = "Jamais"
|
||||
last_ticket_date = _("Never")
|
||||
|
||||
pagination_number = (GeneralOption
|
||||
.get_cached_value('pagination_large_number'))
|
||||
|
@ -151,21 +178,20 @@ def profil(request,user):
|
|||
return render_to_string('tickets/profil.html', context=context, request=request, using=None)
|
||||
|
||||
def preferences(request):
|
||||
""" Vue cannonique d'affichage des tickets dans l'affichage du profil"""
|
||||
""" View to display the settings of the tickets in the preferences page"""
|
||||
preferences = Preferences.objects.first()
|
||||
context = {'preferences':preferences}
|
||||
return render_to_string('tickets/preferences.html', context=context, request=request, using=None)
|
||||
|
||||
def contact(request):
|
||||
"""Vue cannonique d'affichage d'une adresse dans la page contact.
|
||||
Utilisée ici pour proposer l'ouverture d'un ticket"""
|
||||
"""View to display a contact address on the contact page
|
||||
used here to display a link to open a ticket"""
|
||||
return render_to_string('tickets/contact.html')
|
||||
|
||||
def navbar_user(request):
|
||||
"""Vue cannonique d'affichage des tickets dans la navbar"""
|
||||
"""View to display the ticket link in thet user's dropdown in the navbar"""
|
||||
return render_to_string('tickets/navbar.html')
|
||||
|
||||
def navbar_logout(request):
|
||||
"""Vue cannonique d'affichage du lien de creation de ticket
|
||||
lorsque l'utilisateur est déconnecté dans la navbar"""
|
||||
"""View to display the ticket link to log out users"""
|
||||
return render_to_string('tickets/navbar_logout.html')
|
||||
|
|
Loading…
Reference in a new issue