2008-05-21 23:16:44 +02:00
|
|
|
"""
|
|
|
|
Jutda Helpdesk - A Django powered ticket tracker for small enterprise.
|
|
|
|
|
|
|
|
(c) Copyright 2008 Jutda. All Rights Reserved. See LICENSE for details.
|
|
|
|
|
|
|
|
views/public.py - All public facing views, eg non-staff (no authentication
|
|
|
|
required) views.
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.http import HttpResponseRedirect, Http404, HttpResponse
|
|
|
|
from django.shortcuts import render_to_response, get_object_or_404
|
|
|
|
from django.template import loader, Context, RequestContext
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
|
|
from helpdesk.forms import PublicTicketForm
|
|
|
|
from helpdesk.lib import send_templated_mail
|
|
|
|
from helpdesk.models import Ticket, Queue
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
def homepage(request):
|
2009-01-19 10:31:24 +01:00
|
|
|
if request.user.is_staff:
|
2008-09-09 10:32:01 +02:00
|
|
|
if getattr(request.user.usersettings.settings, 'login_view_ticketlist', False):
|
|
|
|
return HttpResponseRedirect(reverse('helpdesk_list'))
|
|
|
|
else:
|
|
|
|
return HttpResponseRedirect(reverse('helpdesk_dashboard'))
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
if request.method == 'POST':
|
2009-01-22 09:08:22 +01:00
|
|
|
form = PublicTicketForm(request.POST, request.FILES)
|
2008-05-21 23:16:44 +02:00
|
|
|
form.fields['queue'].choices = [('', '--------')] + [[q.id, q.title] for q in Queue.objects.filter(allow_public_submission=True)]
|
|
|
|
if form.is_valid():
|
|
|
|
ticket = form.save()
|
2008-08-19 10:50:38 +02:00
|
|
|
return HttpResponseRedirect('%s?ticket=%s&email=%s'% (
|
|
|
|
reverse('helpdesk_public_view'),
|
|
|
|
ticket.ticket_for_url,
|
|
|
|
ticket.submitter_email)
|
|
|
|
)
|
2008-05-21 23:16:44 +02:00
|
|
|
else:
|
2008-10-07 08:52:52 +02:00
|
|
|
try:
|
|
|
|
queue = Queue.objects.get(slug=request.GET.get('queue', None))
|
|
|
|
except Queue.DoesNotExist:
|
|
|
|
queue = None
|
|
|
|
initial_data = {}
|
|
|
|
if queue:
|
|
|
|
initial_data['queue'] = queue.id
|
|
|
|
form = PublicTicketForm(initial=initial_data)
|
2008-05-21 23:16:44 +02:00
|
|
|
form.fields['queue'].choices = [('', '--------')] + [[q.id, q.title] for q in Queue.objects.filter(allow_public_submission=True)]
|
|
|
|
|
|
|
|
return render_to_response('helpdesk/public_homepage.html',
|
|
|
|
RequestContext(request, {
|
|
|
|
'form': form,
|
|
|
|
}))
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
def view_ticket(request):
|
|
|
|
ticket = request.GET.get('ticket', '')
|
|
|
|
email = request.GET.get('email', '')
|
|
|
|
error_message = ''
|
|
|
|
|
|
|
|
if ticket and email:
|
2008-12-10 10:27:07 +01:00
|
|
|
parts = ticket.split('-')
|
|
|
|
queue = '-'.join(parts[0:-1])
|
|
|
|
ticket_id = parts[-1]
|
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
try:
|
|
|
|
t = Ticket.objects.get(id=ticket_id, queue__slug__iexact=queue, submitter_email__iexact=email)
|
2008-08-18 23:29:31 +02:00
|
|
|
except Ticket.DoesNotExist:
|
2008-05-21 23:16:44 +02:00
|
|
|
t = False;
|
|
|
|
error_message = _('Invalid ticket ID or e-mail address. Please try again.')
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
if t:
|
|
|
|
return render_to_response('helpdesk/public_view_ticket.html',
|
|
|
|
RequestContext(request, {
|
|
|
|
'ticket': t,
|
|
|
|
}))
|
|
|
|
|
|
|
|
return render_to_response('helpdesk/public_view_form.html',
|
2008-05-21 23:16:44 +02:00
|
|
|
RequestContext(request, {
|
|
|
|
'ticket': ticket,
|
|
|
|
'email': email,
|
|
|
|
'error_message': error_message,
|
|
|
|
}))
|
2008-08-19 10:50:38 +02:00
|
|
|
|