Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

started adding custom data and display to search autocomplete

  • Loading branch information...
commit d17d1ee890780748310e0229c4a9d9d3f091135e 1 parent c2bc6f1
@yekibud yekibud authored
View
9 helpdesk/templates/helpdesk/navigation.html
@@ -24,21 +24,22 @@
{% endif %}
<li><a href='/helpdesk/search'>{% trans "Search" %}</a></li>
- <li><a href='{% url logout %}'>{% trans "Logout" %}</a></li>
{% comment %}
+ <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='4' 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' />{% csrf_token %}</form></li>{% endif %}
</ul>
{% else %}
-<ul>
{% if helpdesk_settings.HELPDESK_SUBMIT_A_TICKET_PUBLIC %}
<li><a href='{% url helpdesk_home %}'>{% trans "Submit A Ticket" %}</a></li>
{% endif %}
{% if helpdesk_settings.HELPDESK_KB_ENABLED %}<li><a href='{% url helpdesk_kb_index %}'>{% trans "Knowledgebase" %}</a></li>{% endif %}
+{% endcomment %}
+{% endif %}
+
+<ul>
{% if not request.path == '/helpdesk/login/' or user.is_authenticated %}
<li>{% if user.is_authenticated %}<a href='{% url logout %}'>{% trans "Logout" %}</a>{% else %}<a href='{% url login %}?next={% if next %}{{ next|escape }}{% else %}{% url helpdesk_dashboard %}{% endif %}'>{% trans "Log In" %}</a>{% endif %}</li>
{% endif %}
</ul>
-{% endcomment %}
-{% endif %}
View
13 helpdesk/templates/search/search.html
@@ -105,8 +105,7 @@
$(function() {
-
-function split( val ) {
+ function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
@@ -147,7 +146,15 @@
this.value = terms.join( ", " );
return false;
}
- });
+ })
+ /* TODO: broken :-(
+ .data( "autocomplete" )._renderItem = function( ul, item ) {
+ return $( "<li></li>" )
+ .data( "item.autocomplete", item )
+ .append( "<b>" + item.label + ":</b> " + item.desc )
+ .appendTo( ul );
+ };
+ */
});
View
27 helpdesk/views/search.py
@@ -3,42 +3,25 @@
(c) Copyright 2012 Sacramento Natural Foods Co-op, Inc. All Rights Reserved. See LICENSE for details.
-views/search.py - Autocomplete subclass for Haystack search.
+views/search.py - autocomplete function for Haystack search.
"""
-from helpdesk.models import Ticket, Queue
-from haystack.views import FacetedSearchView
-from haystack.query import SearchQuerySet
+from helpdesk.models import Ticket, Queue
from django.http import HttpResponse
from django.utils import simplejson as json
from django.contrib.auth.models import User
-class AutocompleteFacetedSearchView(FacetedSearchView):
-
- __name__ = 'AutocompleteFacetedSearchView'
-
- def build_form(self, form_kwargs=None):
- if form_kwargs is None:
- form_kwargs = {}
-
- if self.searchqueryset is None:
- #sqs = SearchQuerySet().filter(content_auto=self.request.GET.get('q', ''))
- sqs = SearchQuerySet().filter(owner_auto=self.request.GET.get('q','')).facet('queue').facet('assigned_to').facet('priority').facet('tags')
- import ipdb; ipdb.set_trace()
- form_kwargs['searchqueryset'] = sqs
-
- return super(AutocompleteFacetedSearchView, self).build_form(form_kwargs)
-
def autocomplete_search(request):
- #term = request.GET.get('term','').split(' ')[-1]
term = request.GET.get('term','')
users = User.objects.filter(is_active=True, is_staff=True).filter(username__icontains=term).order_by('username')
tickets = Ticket.objects.filter(title__icontains=term).order_by('title')
queues = Queue.objects.filter(title__icontains=term).order_by('title')
return HttpResponse(json.dumps(
- [user.username for user in users] + [ticket.title for ticket in tickets] + [queue.title for queue in queues]
+ [{'value': user.username, 'label': 'username', 'desc': user.username} for user in users]
+ # + ["<b>ticket: </b>%s" % ticket.title for ticket in tickets] +
+ # + ["<b>queue: </b>%s" % queue.title for queue in queues]
))
Please sign in to comment.
Something went wrong with that request. Please try again.