2008-05-21 23:16:44 +02:00
|
|
|
"""
|
2011-01-26 00:08:41 +01:00
|
|
|
django-helpdesk - A Django powered ticket tracker for small enterprise.
|
2008-05-21 23:16:44 +02:00
|
|
|
|
|
|
|
(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 _
|
|
|
|
|
2011-06-09 17:24:33 +02:00
|
|
|
from helpdesk import settings as helpdesk_settings
|
2008-05-21 23:16:44 +02:00
|
|
|
from helpdesk.forms import PublicTicketForm
|
2009-06-25 13:22:53 +02:00
|
|
|
from helpdesk.lib import send_templated_mail, text_is_spam
|
2012-03-01 23:28:54 +01:00
|
|
|
from helpdesk.models import Ticket, Queue, UserSettings, KBCategory
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
def homepage(request):
|
2011-11-19 09:34:07 +01:00
|
|
|
if not request.user.is_authenticated() and helpdesk_settings.HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT:
|
|
|
|
return HttpResponseRedirect(reverse('login'))
|
|
|
|
|
|
|
|
if (request.user.is_staff or (request.user.is_authenticated() and helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE)):
|
2011-02-04 01:40:15 +01:00
|
|
|
try:
|
|
|
|
if getattr(request.user.usersettings.settings, 'login_view_ticketlist', False):
|
|
|
|
return HttpResponseRedirect(reverse('helpdesk_list'))
|
|
|
|
else:
|
|
|
|
return HttpResponseRedirect(reverse('helpdesk_dashboard'))
|
|
|
|
except UserSettings.DoesNotExist:
|
2008-09-09 10:32:01 +02:00
|
|
|
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():
|
2009-06-25 13:22:53 +02:00
|
|
|
if text_is_spam(form.cleaned_data['body'], request):
|
|
|
|
# This submission is spam. Let's not save it.
|
|
|
|
return render_to_response('helpdesk/public_spam.html', RequestContext(request, {}))
|
|
|
|
else:
|
|
|
|
ticket = form.save()
|
|
|
|
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
|
2009-08-04 14:04:13 +02:00
|
|
|
|
|
|
|
if request.user.is_authenticated() and request.user.email:
|
|
|
|
initial_data['submitter_email'] = request.user.email
|
|
|
|
|
2008-10-07 08:52:52 +02:00
|
|
|
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)]
|
|
|
|
|
2012-03-01 23:28:54 +01:00
|
|
|
knowledgebase_categories = KBCategory.objects.all()
|
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
return render_to_response('helpdesk/public_homepage.html',
|
|
|
|
RequestContext(request, {
|
|
|
|
'form': form,
|
2011-06-09 17:24:33 +02:00
|
|
|
'helpdesk_settings': helpdesk_settings,
|
2012-03-01 23:28:54 +01:00
|
|
|
'kb_categories': knowledgebase_categories
|
2008-05-21 23:16:44 +02:00
|
|
|
}))
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
def view_ticket(request):
|
2009-07-22 10:19:46 +02:00
|
|
|
ticket_req = request.GET.get('ticket', '')
|
2009-08-08 04:53:33 +02:00
|
|
|
ticket = False
|
2008-05-21 23:16:44 +02:00
|
|
|
email = request.GET.get('email', '')
|
|
|
|
error_message = ''
|
|
|
|
|
2009-07-22 10:19:46 +02:00
|
|
|
if ticket_req and email:
|
|
|
|
parts = ticket_req.split('-')
|
2008-12-10 10:27:07 +01:00
|
|
|
queue = '-'.join(parts[0:-1])
|
|
|
|
ticket_id = parts[-1]
|
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
try:
|
2009-07-22 10:19:46 +02:00
|
|
|
ticket = Ticket.objects.get(id=ticket_id, queue__slug__iexact=queue, submitter_email__iexact=email)
|
2009-06-27 03:00:55 +02:00
|
|
|
except:
|
2009-07-22 10:19:46 +02:00
|
|
|
ticket = False
|
2008-05-21 23:16:44 +02:00
|
|
|
error_message = _('Invalid ticket ID or e-mail address. Please try again.')
|
|
|
|
|
2009-07-22 10:19:46 +02:00
|
|
|
if ticket:
|
2011-05-03 00:31:30 +02:00
|
|
|
|
|
|
|
if request.user.is_staff:
|
|
|
|
redirect_url = reverse('helpdesk_view', args=[ticket_id])
|
|
|
|
if request.GET.has_key('close'):
|
|
|
|
redirect_url += '?close'
|
|
|
|
return HttpResponseRedirect(redirect_url)
|
2011-06-09 17:24:33 +02:00
|
|
|
|
2009-01-23 11:35:14 +01:00
|
|
|
if request.GET.has_key('close') and ticket.status == Ticket.RESOLVED_STATUS:
|
|
|
|
from helpdesk.views.staff import update_ticket
|
|
|
|
# Trick the update_ticket() view into thinking it's being called with
|
|
|
|
# a valid POST.
|
|
|
|
request.POST = {
|
|
|
|
'new_status': Ticket.CLOSED_STATUS,
|
|
|
|
'public': 1,
|
|
|
|
'title': ticket.title,
|
|
|
|
'comment': _('Submitter accepted resolution and closed ticket'),
|
|
|
|
}
|
2011-04-28 12:23:16 +02:00
|
|
|
if ticket.assigned_to:
|
|
|
|
request.POST['owner'] = ticket.assigned_to.id
|
2009-01-23 11:35:14 +01:00
|
|
|
request.GET = {}
|
|
|
|
|
2009-07-22 10:19:46 +02:00
|
|
|
return update_ticket(request, ticket_id, public=True)
|
2011-06-09 17:24:33 +02:00
|
|
|
|
2011-11-23 19:56:36 +01:00
|
|
|
# redirect user back to this ticket if possible.
|
|
|
|
redirect_url = ''
|
|
|
|
if helpdesk_settings.HELPDESK_NAVIGATION_ENABLED:
|
|
|
|
redirect_url = reverse('helpdesk_view', args=[ticket_id])
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
return render_to_response('helpdesk/public_view_ticket.html',
|
|
|
|
RequestContext(request, {
|
2009-07-22 10:19:46 +02:00
|
|
|
'ticket': ticket,
|
2011-09-01 13:01:03 +02:00
|
|
|
'helpdesk_settings': helpdesk_settings,
|
2011-11-23 19:56:36 +01:00
|
|
|
'next': redirect_url,
|
2008-08-19 10:50:38 +02:00
|
|
|
}))
|
|
|
|
|
|
|
|
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,
|
2011-06-09 17:24:33 +02:00
|
|
|
'helpdesk_settings': helpdesk_settings,
|
2008-05-21 23:16:44 +02:00
|
|
|
}))
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2011-11-27 09:26:56 +01:00
|
|
|
def change_language(request):
|
2011-11-27 09:43:51 +01:00
|
|
|
return_to = ''
|
|
|
|
if request.GET.has_key('return_to'):
|
|
|
|
return_to = request.GET['return_to']
|
|
|
|
|
2011-11-27 09:26:56 +01:00
|
|
|
return render_to_response('helpdesk/public_change_language.html',
|
2011-11-27 09:43:51 +01:00
|
|
|
RequestContext(request, {'next': return_to}))
|