From f3e52a2f12d8d94db1ca481c512a119998cf681d Mon Sep 17 00:00:00 2001 From: Arne Brutschy Date: Tue, 9 Jan 2018 09:55:27 +0100 Subject: [PATCH] Adds pre-defined values for public tickets This commit adds three new settings that allow the operator to pre-define the `queue`, `priority` and `due_date` fields for public tickets. If one of these settings are present the corresponding input field is hidden from the form. The settings are the following: HELPDESK_PUBLIC_TICKET_QUEUE = 'website' HELPDESK_PUBLIC_TICKET_PRIORITY = 2 HELPDESK_PUBLIC_TICKET_DUE_DATE = '' If the due date is set to the empty string, no due date is saved in the ticket (analogously to the form). The other settings should be self-explanatory. --- helpdesk/forms.py | 8 ++++++++ helpdesk/views/public.py | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/helpdesk/forms.py b/helpdesk/forms.py index 7ab2024f..613f21b7 100644 --- a/helpdesk/forms.py +++ b/helpdesk/forms.py @@ -368,6 +368,14 @@ class PublicTicketForm(AbstractTicketForm): Add any (non-staff) custom fields that are defined to the form """ super(PublicTicketForm, self).__init__(*args, **kwargs) + + if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_QUEUE'): + self.fields['queue'].widget = forms.HiddenInput() + if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_PRIORITY'): + self.fields['priority'].widget = forms.HiddenInput() + if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_DUE_DATE'): + self.fields['due_date'].widget = forms.HiddenInput() + self._add_form_custom_fields(False) def save(self): diff --git a/helpdesk/views/public.py b/helpdesk/views/public.py index 9227e83d..72410755 100644 --- a/helpdesk/views/public.py +++ b/helpdesk/views/public.py @@ -8,10 +8,11 @@ views/public.py - All public facing views, eg non-staff (no authentication """ from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse -from django.http import HttpResponseRedirect +from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import render from django.utils.http import urlquote from django.utils.translation import ugettext as _ +from django.conf import settings from helpdesk import settings as helpdesk_settings from helpdesk.decorators import protect_view @@ -58,6 +59,19 @@ def homepage(request): except Queue.DoesNotExist: queue = None initial_data = {} + + # add pre-defined data for public ticket + if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_QUEUE'): + # get the requested queue; return an error if queue not found + try: + queue = Queue.objects.get(slug=settings.HELPDESK_PUBLIC_TICKET_QUEUE) + except Queue.DoesNotExist: + return HttpResponse(status=500) + if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_PRIORITY'): + initial_data['priority'] = settings.HELPDESK_PUBLIC_TICKET_PRIORITY + if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_DUE_DATE'): + initial_data['due_date'] = settings.HELPDESK_PUBLIC_TICKET_DUE_DATE + if queue: initial_data['queue'] = queue.id