From 4481795c7fe719cce89a0db9d92fec2939e7199d Mon Sep 17 00:00:00 2001 From: Timothy Hobbs Date: Thu, 23 Nov 2023 20:52:27 +0100 Subject: [PATCH] =?UTF-8?q?search=5Ffor=5Fticket=20=E2=86=92=20class=20bas?= =?UTF-8?q?ed=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helpdesk/views/public.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/helpdesk/views/public.py b/helpdesk/views/public.py index 5968d6a0..57b87331 100644 --- a/helpdesk/views/public.py +++ b/helpdesk/views/public.py @@ -166,18 +166,29 @@ class Homepage(CreateTicketView): return context -def search_for_ticket(request, error_message=None): - if hasattr(settings, 'HELPDESK_VIEW_A_TICKET_PUBLIC') and settings.HELPDESK_VIEW_A_TICKET_PUBLIC: +class SearchForTicketView(TemplateView): + template_name = 'helpdesk/public_view_form.html' + + def get(self, request, *args, **kwargs): + if hasattr(settings, 'HELPDESK_VIEW_A_TICKET_PUBLIC') and settings.HELPDESK_VIEW_A_TICKET_PUBLIC: + context = self.get_context_data(**kwargs) + return self.render_to_response(context) + else: + raise PermissionDenied("Public viewing of tickets without a secret key is forbidden.") + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + request = self.request email = request.GET.get('email', None) - return render(request, 'helpdesk/public_view_form.html', { + error_message = kwargs.get('error_message', None) + + context.update({ 'ticket': False, 'email': email, 'error_message': error_message, 'helpdesk_settings': helpdesk_settings, }) - else: - raise PermissionDenied( - "Public viewing of tickets without a secret key is forbidden.") + return context class ViewTicket(TemplateView): @@ -191,9 +202,9 @@ class ViewTicket(TemplateView): if not (ticket_req and email): if ticket_req is None and email is None: - return search_for_ticket(request) + return SearchForTicketView.as_view()(request) else: - return search_for_ticket(request, _('Missing ticket ID or e-mail address. Please try again.')) + return SearchForTicketView.as_view()(request, _('Missing ticket ID or e-mail address. Please try again.')) try: queue, ticket_id = Ticket.queue_and_id_from_query(ticket_req)