From f3e52a2f12d8d94db1ca481c512a119998cf681d Mon Sep 17 00:00:00 2001 From: Arne Brutschy Date: Tue, 9 Jan 2018 09:55:27 +0100 Subject: [PATCH 1/2] 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 From 1b7214a797334789a3f9695e9f7945cd253b236d Mon Sep 17 00:00:00 2001 From: Arne Brutschy Date: Wed, 10 Jan 2018 18:44:15 +0100 Subject: [PATCH 2/2] Added documentation for public form defaults --- docs/settings.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/settings.rst b/docs/settings.rst index 554cc895..1ccbe75e 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -105,6 +105,22 @@ These options only change display of items on public-facing pages, not staff pag **Default:** ``HELPDESK_SUBMIT_A_TICKET_PUBLIC = True`` +Options for public ticket submission form +----------------------------------------- + +- **HELPDESK_PUBLIC_TICKET_QUEUE** Sets the queue for tickets submitted through the public form. If defined, the matching form field will be hidden. This cannot be `None` but must be set to a valid queue slug. + + **Default:** Not defined + +- **HELPDESK_PUBLIC_TICKET_PRIORITY** Sets the priority for tickets submitted through the public form. If defined, the matching form field will be hidden. Must be set to a valid integer priority. + + **Default:** Not defined + +- **HELPDESK_PUBLIC_TICKET_DUE_DATE** Sets the due date for tickets submitted through the public form. If defined, the matching form field will be hidden. Set to `None` if you want to hide the form field but do not want to define a value. + + **Default:** Not defined + + Options that change ticket updates ----------------------------------