mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2024-12-13 02:10:49 +01:00
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:
parent
db2dc108e5
commit
06a153206e
@ -21,7 +21,7 @@
|
||||
<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 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>
|
||||
</div>
|
||||
<div id='body'>
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user