diff --git a/re2o/settings.py b/re2o/settings.py index f2557b44..ce7d3257 100644 --- a/re2o/settings.py +++ b/re2o/settings.py @@ -77,6 +77,7 @@ LOCAL_APPS = ( 're2o', 'preferences', 'logs', + 'tickets', ) INSTALLED_APPS = ( DJANGO_CONTRIB_APPS + diff --git a/re2o/urls.py b/re2o/urls.py index 37497572..c9e00667 100644 --- a/re2o/urls.py +++ b/re2o/urls.py @@ -70,6 +70,7 @@ urlpatterns = [ include('cotisations.urls', namespace='cotisations') ), url(r'^machines/', include('machines.urls', namespace='machines')), + url(r'^tickets/', include('tickets.urls', namespace='tickets')), url(r'^topologie/', include('topologie.urls', namespace='topologie')), url(r'^logs/', include('logs.urls', namespace='logs')), url( diff --git a/tickets/forms.py b/tickets/forms.py new file mode 100644 index 00000000..d1ebc323 --- /dev/null +++ b/tickets/forms.py @@ -0,0 +1,27 @@ +from django import forms +from django.forms import ModelForm, Form + +from .models import( + Ticket +) + +class EditTicketForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): + """Formulaire d'edition d'un Ticket""" + + class Meta: + model = Ticket + exclude = ['user','assigned_staff','date'] + + def __init__(self,*args, **kwargs): + prefix = kwargs.pop('prefix',self.Meta.model.__name__) + super(EditMachineForm, self).__init__(*args, prefix=prefix, **kwargs) + self.fields['title'].label = _("Titre du ticket") + self.fields['decription'].label = _("Description du ticket") + self.field['solved'].label = _("Problème réglé ?") + + + +class NewTicketForm(EditTicketForm): + """ Creation d'une machine""" + class Meta(EditeTicketForm): + fields = '__all__' diff --git a/tickets/models.py b/tickets/models.py index 71a83623..e1a0f81e 100644 --- a/tickets/models.py +++ b/tickets/models.py @@ -1,3 +1,35 @@ from django.db import models +from django.utils.translation import ugettext_lazy as _ -# Create your models here. +import users.models + +class Ticket(models.Model): + """Class définissant un ticket""" + + user = models.ForeignKey( + 'users.User', + on_delete=models.CASCADE, + related_name="tickets") + title = models.CharField( + max_length=255, + help_text=_("Nom du ticket"), + blank=False, + null=False,) + description = models.CharField( + max_length=3000, + help_text=_("Description du ticket"), + blank=False, + null=False) + date = models.DateTimeField(auto_now_add=True) + assigned_staff = models.ForeignKey( + 'users.User', + on_delete=models.PROTECT, + related_name="tickets_assigned", + blank=False, + null=True) + #categories = models.OneToManyFiled('Category') + solved = models.BooleanField(default=False) + + class Meta: + verbose_name = _("Ticket") + verbose_name_plural = _("Tickets") diff --git a/tickets/templates/tickets/aff_tickets.html b/tickets/templates/tickets/aff_tickets.html new file mode 100644 index 00000000..ebd658b1 --- /dev/null +++ b/tickets/templates/tickets/aff_tickets.html @@ -0,0 +1,59 @@ +{% 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 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. +{% endcomment %} + +{% load bootstrap3 %} +{% load i18n %} + +{% block title %}{% trans "Tickets" %}{% endblock %} + +{% block content %} +
+ + + + + + + + + + {% for ticket in tickets_list %} + + + + + + {% if ticket.solved %} + + {% else %} + + {% endif %} + + {% endfor %} + + +
UserTitreDateRésolu
Lien {{ ticket.user }}{{ ticket.title }}{{ ticket.date }}
+
+{% endblock %} diff --git a/tickets/urls.py b/tickets/urls.py new file mode 100644 index 00000000..f7af41ce --- /dev/null +++ b/tickets/urls.py @@ -0,0 +1,10 @@ +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url(r'^$', views.aff_tickets, name='index des tickets'), + url(r'^new_ticket/(?P[0-9]+)$', + views.new_ticket, + name='new-ticket'), +] diff --git a/tickets/views.py b/tickets/views.py index 91ea44a2..51c3e104 100644 --- a/tickets/views.py +++ b/tickets/views.py @@ -1,3 +1,26 @@ from django.shortcuts import render -# Create your views here. +from .models import( + Ticket +) + +def new_ticket(request,user): + """ Vue de création d'un ticket """ + ticket = NewTicketForm(request.POST or None, user=request.user) + if ticket.is_valid(): + new_ticket_obj = machine.save(commit=False) + nex_ticket_obj.user = user + new_machine_obj.save() + + return form( + { + 'ticketform':ticket, + }, + 'ticket/ticket.html', + request + ) +def aff_tickets(request): + """ Vue d'affichage de tout les tickets """ + tickets = Ticket.objects.all() + return render(request,'tickets/aff_tickets.html', + {'tickets_list':tickets})