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).
This commit is contained in:
Ross Poulton 2009-03-08 05:55:35 +00:00
parent db2dc108e5
commit 06a153206e
2 changed files with 35 additions and 1 deletions

View File

@ -21,7 +21,7 @@
<li><a href='{% url helpdesk_submit %}'>{% trans "New Ticket" %}</a></li> <li><a href='{% url helpdesk_submit %}'>{% trans "New Ticket" %}</a></li>
<li><a href='{% url helpdesk_report_index %}'>{% trans "Stats" %}</a></li> <li><a href='{% url helpdesk_report_index %}'>{% trans "Stats" %}</a></li>
<li><a href='{% url logout %}'>{% trans "Logout" %}</a></li> <li><a href='{% url logout %}'>{% trans "Logout" %}</a></li>
{% if not query %}<li><form id='searchform' method='get' action='{% url helpdesk_list %}'><input type='text' name='q' size='10' class='input' value='{% trans "Search..." %}' id='search_query' onFocus='s=document.getElementById("search_query");if (s.value == "{% trans "Search..." %}") { s.value = ""; }' /><input type='hidden' name='status' value='1' /><input type='hidden' name='status' value='2' /><input type='hidden' name='status' value='3' /></form></li>{% endif %} {% if not query %}<li><form id='searchform' method='get' action='{% url helpdesk_list %}'><input type='text' name='q' size='10' class='input' value='{% trans "Search..." %}' id='search_query' onFocus='s=document.getElementById("search_query");if (s.value == "{% trans "Search..." %}") { s.value = ""; }' title='{% trans "Enter a keyword, or a ticket number to jump straight to that ticket." %}'/><input type='hidden' name='status' value='1' /><input type='hidden' name='status' value='2' /><input type='hidden' name='status' value='3' /><input type='hidden' name='search_type' value='header' /></form></li>{% endif %}
</ul> </ul>
</div> </div>
<div id='body'> <div id='body'>

View File

@ -318,6 +318,40 @@ def ticket_list(request):
from_saved_query = False 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): if request.GET.get('saved_query', None):
from_saved_query = True from_saved_query = True
try: try: