2019-07-10 08:28:16 +00:00
|
|
|
from django.contrib import messages
|
2019-08-11 13:06:56 +00:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2019-07-10 08:28:16 +00:00
|
|
|
from django.shortcuts import render, redirect
|
2019-07-25 14:44:40 +00:00
|
|
|
from django.template.loader import render_to_string
|
2019-08-10 17:25:21 +00:00
|
|
|
from django.views.decorators.cache import cache_page
|
2019-07-10 08:28:16 +00:00
|
|
|
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-08-06 19:27:03 +00:00
|
|
|
from re2o.base import (
|
|
|
|
re2o_paginator,
|
|
|
|
)
|
|
|
|
|
2019-08-11 13:06:56 +00:00
|
|
|
from re2o.acl import(
|
|
|
|
can_view,
|
|
|
|
can_view_all,
|
|
|
|
can_edit,
|
|
|
|
can_create,
|
|
|
|
)
|
|
|
|
|
2019-08-06 19:27:03 +00:00
|
|
|
from preferences.models import GeneralOption
|
2019-07-07 17:09:56 +00:00
|
|
|
from .models import(
|
2019-08-05 14:38:53 +00:00
|
|
|
Ticket,
|
|
|
|
Preferences,
|
2019-07-07 17:09:56 +00:00
|
|
|
)
|
|
|
|
|
2019-07-10 08:28:16 +00:00
|
|
|
from .forms import (
|
2019-08-06 05:10:37 +00:00
|
|
|
NewTicketForm,
|
2019-08-06 07:41:27 +00:00
|
|
|
ChangeStatusTicketForm,
|
2019-08-06 05:10:37 +00:00
|
|
|
EditPreferencesForm,
|
2019-07-10 08:28:16 +00:00
|
|
|
)
|
|
|
|
|
2019-08-05 14:38:53 +00:00
|
|
|
|
2019-07-10 08:28:16 +00:00
|
|
|
def new_ticket(request):
|
2019-07-07 17:09:56 +00:00
|
|
|
""" Vue de création d'un ticket """
|
2019-08-06 05:10:37 +00:00
|
|
|
ticketform = NewTicketForm(request.POST or None)
|
2019-07-10 08:28:16 +00:00
|
|
|
|
|
|
|
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()
|
2019-08-10 09:45:13 +00:00
|
|
|
messages.success(request,'Votre ticket a été ouvert. Nous vous répondrons le plus rapidement possible.')
|
2019-07-12 11:41:17 +00:00
|
|
|
return redirect(reverse('users:profil',kwargs={'userid':str(request.user.id)}))
|
|
|
|
if not request.user.is_authenticated and email != "":
|
|
|
|
ticket.save()
|
2019-08-10 09:45:13 +00:00
|
|
|
messages.success(request,'Votre ticket a été ouvert. Nous vous répondront le plus rapidement possible.')
|
2019-07-12 11:41:17 +00:00
|
|
|
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
|
|
|
|
2019-08-11 13:06:56 +00:00
|
|
|
@login_required
|
|
|
|
@can_view(Ticket)
|
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()
|
2019-08-06 07:41:27 +00:00
|
|
|
changestatusform = ChangeStatusTicketForm(request.POST)
|
|
|
|
if request.method == 'POST':
|
|
|
|
ticket.solved = not ticket.solved
|
|
|
|
ticket.save()
|
|
|
|
return render(request,'tickets/aff_ticket.html',{'ticket':ticket,'changestatusform':changestatusform})
|
2019-08-11 13:06:56 +00:00
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_view_all(Ticket)
|
2019-07-07 17:09:56 +00:00
|
|
|
def aff_tickets(request):
|
|
|
|
""" Vue d'affichage de tout les tickets """
|
2019-08-06 19:27:03 +00:00
|
|
|
tickets_list = Ticket.objects.all().order_by('-date')
|
|
|
|
nbr_tickets = tickets_list.count()
|
|
|
|
nbr_tickets_unsolved = tickets_list.filter(solved=False).count()
|
2019-08-11 13:06:56 +00:00
|
|
|
if nbr_tickets:
|
|
|
|
last_ticket_date = tickets_list.first().date
|
|
|
|
else:
|
|
|
|
last_ticket_date = "Jamais"
|
2019-08-06 19:27:03 +00:00
|
|
|
|
|
|
|
pagination_number = (GeneralOption
|
|
|
|
.get_cached_value('pagination_number'))
|
|
|
|
|
|
|
|
tickets = re2o_paginator(
|
|
|
|
request,
|
|
|
|
tickets_list,
|
|
|
|
pagination_number,
|
|
|
|
)
|
|
|
|
|
2019-08-06 16:06:53 +00:00
|
|
|
context = {'tickets_list':tickets,
|
|
|
|
'last_ticket_date':last_ticket_date,
|
|
|
|
'nbr_tickets':nbr_tickets,
|
|
|
|
'nbr_tickets_unsolved':nbr_tickets_unsolved}
|
|
|
|
|
|
|
|
return render(request,'tickets/index.html',context=context)
|
2019-08-05 14:38:53 +00:00
|
|
|
|
2019-08-06 05:10:37 +00:00
|
|
|
def edit_preferences(request):
|
|
|
|
""" Vue d'édition des préférences des tickets """
|
|
|
|
|
|
|
|
preferences_instance, created = Preferences.objects.get_or_create(id=1)
|
|
|
|
preferencesform = EditPreferencesForm(
|
|
|
|
request.POST or None,
|
|
|
|
instance = preferences_instance,)
|
|
|
|
|
|
|
|
if preferencesform.is_valid():
|
|
|
|
if preferencesform.changed_data:
|
|
|
|
preferencesform.save()
|
|
|
|
messages.success(request,'Préférences des Tickets mises à jour')
|
|
|
|
return redirect(reverse('preferences:display-options',))
|
|
|
|
else:
|
|
|
|
messages.error(request,'Formulaire Invalide')
|
|
|
|
return form({'preferencesform':preferencesform,},'tickets/form_preferences.html',request)
|
|
|
|
return form({'preferencesform':preferencesform,},'tickets/form_preferences.html',request)
|
2019-08-05 14:38:53 +00:00
|
|
|
|
|
|
|
# views cannoniques des apps optionnels
|
2019-07-25 14:44:40 +00:00
|
|
|
def profil(request,user):
|
|
|
|
""" Vue cannonique d'affichage des tickets dans l'accordeon du profil"""
|
2019-08-10 08:12:49 +00:00
|
|
|
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()
|
2019-08-11 13:06:56 +00:00
|
|
|
if nbr_tickets:
|
|
|
|
last_ticket_date = tickets_list.first().date
|
|
|
|
else:
|
|
|
|
last_ticket_date = "Jamais"
|
|
|
|
|
2019-08-10 08:12:49 +00:00
|
|
|
pagination_number = (GeneralOption
|
|
|
|
.get_cached_value('pagination_large_number'))
|
|
|
|
|
|
|
|
tickets = re2o_paginator(
|
|
|
|
request,
|
|
|
|
tickets_list,
|
|
|
|
pagination_number,
|
|
|
|
)
|
|
|
|
|
|
|
|
context = {'tickets_list':tickets,
|
|
|
|
'last_ticket_date':last_ticket_date,
|
|
|
|
'nbr_tickets':nbr_tickets,
|
|
|
|
'nbr_tickets_unsolved':nbr_tickets_unsolved}
|
2019-07-25 14:44:40 +00:00
|
|
|
return render_to_string('tickets/profil.html', context=context, request=request, using=None)
|
2019-08-05 14:38:53 +00:00
|
|
|
|
|
|
|
def preferences(request):
|
|
|
|
""" Vue cannonique d'affichage des tickets dans l'affichage du profil"""
|
|
|
|
preferences = Preferences.objects.first()
|
|
|
|
context = {'preferences':preferences}
|
|
|
|
return render_to_string('tickets/preferences.html', context=context, request=request, using=None)
|
2019-08-10 17:25:21 +00:00
|
|
|
|
2019-08-11 09:50:37 +00:00
|
|
|
def navbar_user(request):
|
2019-08-10 17:25:21 +00:00
|
|
|
"""Vue cannonique d'affichage des tickets dans la navbar"""
|
|
|
|
return render_to_string('tickets/navbar.html')
|