From afbfd01fabb4961807a45defb365eb4eb13e7d5e Mon Sep 17 00:00:00 2001 From: Daryl Date: Sun, 26 Jun 2016 12:45:55 +1200 Subject: [PATCH] Fix Issue #404: Refactor converting query string into queue:id --- helpdesk/models.py | 8 ++++++++ helpdesk/views/public.py | 5 +---- helpdesk/views/staff.py | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/helpdesk/models.py b/helpdesk/models.py index 8740f661..8599093a 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -562,6 +562,14 @@ class Ticket(models.Model): super(Ticket, self).save(*args, **kwargs) + @classmethod + def queue_and_id_from_query(klass, query): + # Apply the opposite logic here compared to self._get_ticket_for_url + # Ensure that queues with '-' in them will work + parts = query.split('-') + queue = '-'.join(parts[0:-1]) + return queue, parts[-1] + class FollowUpManager(models.Manager): def private_followups(self): diff --git a/helpdesk/views/public.py b/helpdesk/views/public.py index 34493c9b..c0f36c80 100644 --- a/helpdesk/views/public.py +++ b/helpdesk/views/public.py @@ -78,10 +78,7 @@ def view_ticket(request): error_message = '' if ticket_req and email: - parts = ticket_req.split('-') - queue = '-'.join(parts[0:-1]) - ticket_id = parts[-1] - + queue, ticket_id = Ticket.queue_and_id_from_query(ticket_req) try: ticket = Ticket.objects.get(id=ticket_id, submitter_email__iexact=email) except: diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index a9eb70a2..0a652ebb 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -739,7 +739,7 @@ def ticket_list(request): filter = None if query.find('-') > 0: try: - queue, id = query.split('-') + queue, id = Ticket.queue_and_id_from_query(query) id = int(id) except ValueError: id = None