Commits

Kai Diefenbach  committed bb97bf9

Added livesearch

  • Participants
  • Parent commits 7f1867f

Comments (0)

Files changed (2)

     url(r'^(?P<language>[-\w]{2})/search-results', "search_results", name="lfc_search"),
     url(r'^search-results', "search_results", name="lfc_search"),
 
+    url(r'^(?P<language>[-\w]{2})/live-search-results', "search_results", name="lfc_live_search"),
+    url(r'^live-search-results', "live_search_results", name="lfc_live_search"),
+
     url(r'^set-language/(?P<language>[-\w]{2})/$', 'set_language', name="lfc_set_language"),
     url(r'^set-language/(?P<language>[-\w]{2})/(?P<id>\d+)/$', 'set_language', name="lfc_set_language"),
 

File lfc/views.py

 
     return response
 
+def live_search_results(request, language=None, template_name="lfc/live_search_results.html"):
+    """Displays the live search result for passed language and query.
+    """
+    query = request.GET.get("q")
+
+    if language is None:
+        language = settings.LANGUAGE_CODE
+
+    f = Q(exclude_from_search=False) & \
+        (Q(language = language) | Q(language="0")) & \
+        (Q(searchable_text__icontains=query))
+
+    try:
+        obj = BaseContent.objects.get(slug="search-results")
+    except BaseContent.DoesNotExist:
+        obj = None
+
+    results = lfc.utils.get_content_objects(request, f)
+    
+    quantity = len(results)
+    return render_to_response(template_name, RequestContext(request, {
+        "lfc_context" : obj,
+        "query" : query,
+        "results" : results,
+        "quantity" : quantity,
+        "see_all" : quantity > 10,
+    }))
+    
 def search_results(request, language=None, template_name="lfc/search_results.html"):
     """Displays the search result for passed language and query.
     """