2019-07-10 08:28:16 +00:00
|
|
|
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
|
2019-07-06 08:25:24 +00:00
|
|
|
|
2019-07-07 17:09:56 +00:00
|
|
|
from .models import(
|
|
|
|
Ticket
|
|
|
|
)
|
|
|
|
|
2019-07-10 08:28:16 +00:00
|
|
|
from .forms import (
|
|
|
|
NewTicketForm
|
|
|
|
)
|
|
|
|
|
|
|
|
def new_ticket(request):
|
2019-07-07 17:09:56 +00:00
|
|
|
""" Vue de création d'un ticket """
|
2019-07-10 08:28:16 +00:00
|
|
|
ticketform = NewTicketForm(request.POST or None)#, user=request.user)
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
ticketform = NewTicketForm(request.POST)
|
2019-07-07 17:09:56 +00:00
|
|
|
|
2019-07-10 08:28:16 +00:00
|
|
|
if ticketform.is_valid():
|
2019-07-12 11:41:17 +00:00
|
|
|
email = ticketform.cleaned_data.get('email')
|
2019-07-10 08:28:16 +00:00
|
|
|
ticket = ticketform.save(commit=False)
|
2019-07-12 11:41:17 +00:00
|
|
|
#raise ValueError("email: {} type: {}".format(email,type(email)))
|
|
|
|
if request.user.is_authenticated:
|
|
|
|
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)}))
|
|
|
|
if not request.user.is_authenticated and email != "":
|
|
|
|
ticket.save()
|
|
|
|
messages.success(request,'Votre ticket à été ouvert. Nous vous répondront le plus rapidement 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")
|
|
|
|
return form({'ticketform':ticketform,},'tickets/form_ticket.html',request)
|
|
|
|
|
2019-07-10 08:28:16 +00:00
|
|
|
else:
|
|
|
|
ticketform = NewTicketForm
|
|
|
|
return form({'ticketform':ticketform,},'tickets/form_ticket.html',request)
|
2019-07-08 10:21:51 +00:00
|
|
|
|
|
|
|
def aff_ticket(request,ticketid):
|
|
|
|
"""Vue d'affichage d'un ticket"""
|
|
|
|
ticket = Ticket.objects.filter(id=ticketid).get()
|
|
|
|
return render(request,'tickets/aff_ticket.html',{'ticket':ticket})
|
|
|
|
|
2019-07-07 17:09:56 +00:00
|
|
|
def aff_tickets(request):
|
|
|
|
""" Vue d'affichage de tout les tickets """
|
2019-07-11 08:27:58 +00:00
|
|
|
tickets = Ticket.objects.all().order_by('-date')
|
2019-07-10 14:39:55 +00:00
|
|
|
return render(request,'tickets/index.html',
|
2019-07-07 17:09:56 +00:00
|
|
|
{'tickets_list':tickets})
|