From 1c24d88680d7a198cd592ae2ca2d26426e1e1406 Mon Sep 17 00:00:00 2001 From: Timothy Hobbs Date: Thu, 27 Dec 2018 16:39:31 +0100 Subject: [PATCH] Enable better ticket form pre-filling --- docs/integration.txt | 11 +++++++++++ helpdesk/views/public.py | 4 ++++ 2 files changed, 15 insertions(+) create mode 100644 docs/integration.txt diff --git a/docs/integration.txt b/docs/integration.txt new file mode 100644 index 00000000..59ab0538 --- /dev/null +++ b/docs/integration.txt @@ -0,0 +1,11 @@ +Integrating django-helpdesk into your application +------------------------------------------------- + +Django-helpdesk associates an email address with each submitted ticket. If you integrate django-helpdesk directly into your django application, logged in users will automatically have their email address set when they visit the `/tickets/submit/` form. If you wish to pre-fill fields in this form, you can do so simply by setting the following query parameters: + + - `queue` + - `title` + - `body` + - `submitter_email` + +Note that these fields will continue to be user-editable despite being pre-filled. diff --git a/helpdesk/views/public.py b/helpdesk/views/public.py index 157a31f3..1e94cd82 100644 --- a/helpdesk/views/public.py +++ b/helpdesk/views/public.py @@ -87,6 +87,10 @@ class CreateTicketView(FormView): if request.user.is_authenticated and request.user.email: initial_data['submitter_email'] = request.user.email + + query_param_fields = ['submitter_email', 'title', 'body'] + for qpf in query_param_fields: + initial_data[qpf] = request.GET.get(qpf, initial_data.get(qpf, "")) return initial_data def form_valid(self, form):