From 06a153206e3eefc7f2ab2ec12e2959b3408cb14f Mon Sep 17 00:00:00 2001 From: Ross Poulton Date: Sun, 8 Mar 2009 05:55:35 +0000 Subject: [PATCH] Issue #53: Enhance search box to allow entry of a ticket ID (and have the user taken straight to that ticket rather than a search results page). --- templates/helpdesk/base.html | 2 +- views/staff.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/templates/helpdesk/base.html b/templates/helpdesk/base.html index 3c10ea4c..92ee165e 100644 --- a/templates/helpdesk/base.html +++ b/templates/helpdesk/base.html @@ -21,7 +21,7 @@
  • {% trans "New Ticket" %}
  • {% trans "Stats" %}
  • {% trans "Logout" %}
  • - {% if not query %}
  • {% endif %} + {% if not query %}
  • {% endif %}
    diff --git a/views/staff.py b/views/staff.py index 1c186f99..678cea87 100644 --- a/views/staff.py +++ b/views/staff.py @@ -318,6 +318,40 @@ def ticket_list(request): from_saved_query = False + # If the user is coming from the header/navigation search box, lets' first + # look at their query to see if they have entered a valid ticket number. If + # they have, just redirect to that ticket number. Otherwise, we treat it as + # a keyword search. + + if request.GET.get('search_type', None) == 'header': + query = request.GET.get('q') + filter = None + if query.find('-') > 0: + queue, id = query.split('-') + try: + id = int(id) + except ValueError: + id = None + + if id: + filter = {'queue__slug': queue, 'id': id } + else: + try: + query = int(query) + except ValueError: + query = None + + if query: + filter = {'id': int(query) } + + if filter: + try: + ticket = Ticket.objects.get(**filter) + return HttpResponseRedirect(ticket.staff_url) + except Ticket.DoesNotExist: + # Go on to standard keyword searching + pass + if request.GET.get('saved_query', None): from_saved_query = True try: