From c4259658eb3c490c55563bd4f73da984dd7bd92b Mon Sep 17 00:00:00 2001 From: Grizzly Date: Wed, 10 Jul 2019 08:28:16 +0000 Subject: [PATCH] Formulaire de creation de ticket --- tickets/admin.py | 3 +- tickets/forms.py | 31 ++++++++------ tickets/models.py | 4 +- tickets/templates/tickets/form_ticket.html | 48 ++++++++++++++++++++++ tickets/urls.py | 2 +- tickets/views.py | 41 +++++++++++------- users/templates/users/profil.html | 5 +++ 7 files changed, 103 insertions(+), 31 deletions(-) create mode 100644 tickets/templates/tickets/form_ticket.html diff --git a/tickets/admin.py b/tickets/admin.py index 8c38f3f3..76763b9c 100644 --- a/tickets/admin.py +++ b/tickets/admin.py @@ -1,3 +1,4 @@ from django.contrib import admin - +from .models import Ticket +admin.site.register(Ticket) # Register your models here. diff --git a/tickets/forms.py b/tickets/forms.py index d1ebc323..f2a6891f 100644 --- a/tickets/forms.py +++ b/tickets/forms.py @@ -1,27 +1,34 @@ from django import forms from django.forms import ModelForm, Form +from re2o.field_permissions import FieldPermissionFormMixin +from re2o.mixins import FormRevMixin +from django.utils.translation import ugettext_lazy as _ from .models import( Ticket ) -class EditTicketForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): +class EditTicketForm(FormRevMixin, ModelForm): """Formulaire d'edition d'un Ticket""" + + #def __init__(self,*args, **kwargs): + #prefix = kwargs.pop('prefix',self.Meta.model.__name__) + #super(EditTicketForm, self).__init__(*args, prefix=prefix, **kwargs) + #self.fields['title'].label = _("Titre du ticket") + #self.fields['decription'].label = _("Description du ticket") + #self.fields['solved'].label = _("Problème réglé ?") 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): +class NewTicketForm(ModelForm): """ Creation d'une machine""" - class Meta(EditeTicketForm): - fields = '__all__' + class Meta: + model = Ticket + fields = ['title', 'description'] + + #def __init(self,*args, **kwargs): + #prefix = kwargs.pop('prefix', self.Meta.model.__name__) + #super(NewTicketForm, self).__init__(*args, prefix=prefix, **kwargs) diff --git a/tickets/models.py b/tickets/models.py index e1a0f81e..abdab335 100644 --- a/tickets/models.py +++ b/tickets/models.py @@ -15,7 +15,7 @@ class Ticket(models.Model): help_text=_("Nom du ticket"), blank=False, null=False,) - description = models.CharField( + description = models.TextField( max_length=3000, help_text=_("Description du ticket"), blank=False, @@ -25,7 +25,7 @@ class Ticket(models.Model): 'users.User', on_delete=models.PROTECT, related_name="tickets_assigned", - blank=False, + blank=True, null=True) #categories = models.OneToManyFiled('Category') solved = models.BooleanField(default=False) diff --git a/tickets/templates/tickets/form_ticket.html b/tickets/templates/tickets/form_ticket.html new file mode 100644 index 00000000..79e9c68f --- /dev/null +++ b/tickets/templates/tickets/form_ticket.html @@ -0,0 +1,48 @@ +{% extends 'machines/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 +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 %} +

Ouverture d'un Ticket

+ +{% for message in messages %} +
+ + {{ message | safe }} +
+{% endfor %} + +
+ {% csrf_token %} + {% bootstrap_form ticketform %} + {% bootstrap_button "Ouvrir le Ticket" button_type="submit" icon='ok' button_class='btn-success' %} +
+{% endblock %} diff --git a/tickets/urls.py b/tickets/urls.py index 3e1e2c48..d270aa4c 100644 --- a/tickets/urls.py +++ b/tickets/urls.py @@ -5,5 +5,5 @@ from . import views urlpatterns = [ url(r'^$', views.aff_tickets, name='aff-tickets'), url(r'^ticket/(?P[0-9]+)$', views.aff_ticket, name='aff-ticket'), - url(r'^new_ticket/(?P[0-9]+)$',views.new_ticket,name='new-ticket'), + url(r'^new_ticket/$',views.new_ticket,name='new-ticket'), ] diff --git a/tickets/views.py b/tickets/views.py index 70e3857e..af2ccc83 100644 --- a/tickets/views.py +++ b/tickets/views.py @@ -1,24 +1,35 @@ -from django.shortcuts import render +from django.contrib import messages +from django.shortcuts import render, redirect +from django.urls import reverse +from django.forms import modelformset_factory +from re2o.views import form 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() +from .forms import ( + NewTicketForm +) - return form( - { - 'ticketform':ticket, - }, - 'ticket/ticket.html', - request - ) +def new_ticket(request): + """ Vue de création d'un ticket """ + ticketform = NewTicketForm(request.POST or None)#, user=request.user) + + if request.method == 'POST': + ticketform = NewTicketForm(request.POST) + + if ticketform.is_valid(): + ticket = ticketform.save(commit=False) + ticket.user = request.user + ticket.save() + messages.success(request,'Votre ticket à été ouvert. Nous vous répondront le plus rapidement possible.') + return redirect(reverse('users:profil',kwargs={'userid':str(request.user.id)})) + else: + messages.error(request, 'Formulaire invalide') + else: + ticketform = NewTicketForm + return form({'ticketform':ticketform,},'tickets/form_ticket.html',request) def aff_ticket(request,ticketid): """Vue d'affichage d'un ticket""" diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html index 52a214a6..5b57f6a8 100644 --- a/users/templates/users/profil.html +++ b/users/templates/users/profil.html @@ -119,6 +119,11 @@ with this program; if not, write to the Free Software Foundation, Inc., + + + {% trans " Open a Ticket" %} + +