From 14002782e6b8c409c74492e0265c2c6c67d0071d Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 13 May 2010 15:32:14 +0200 Subject: [PATCH] Create a separate view for search with no hits --- apps/catalogue/urls.py | 1 + apps/catalogue/views.py | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/apps/catalogue/urls.py b/apps/catalogue/urls.py index 25389f48b..ea93cb32d 100644 --- a/apps/catalogue/urls.py +++ b/apps/catalogue/urls.py @@ -17,6 +17,7 @@ urlpatterns = patterns('catalogue.views', url(r'^polki/nowa/$', 'new_set', name='new_set'), url(r'^tags/$', 'tags_starting_with', name='hint'), url(r'^szukaj/$', 'search', name='search'), + url(r'^nie_ma/(?P[a-zA-Z0-9-/]*)$', 'search_no_hits', name='search_no_hits'), # tools url(r'^zegar', 'clock', name='clock'), diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index b4fb0924c..e50e51a51 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -214,8 +214,9 @@ def search(request): # Prefix must have at least 2 characters if len(prefix) < 2: - return render_to_response('catalogue/search_no_hits.html', {'query':prefix, 'tags':tag_list}, - context_instance=RequestContext(request)) + return HttpResponseRedirect(reverse('catalogue.views.search_no_hits', + kwargs={'tags': '/'.join(tag.slug for tag in tag_list)} + )) result = _tags_starting_with(prefix, request.user) if len(result) > 0: @@ -229,9 +230,22 @@ def search(request): kwargs={'tags': '/'.join(tag.slug for tag in tag_list)} )) else: - return render_to_response('catalogue/search_no_hits.html', {'query':prefix, 'tags':tag_list}, - context_instance=RequestContext(request)) + return HttpResponseRedirect(reverse('catalogue.views.search_no_hits', + kwargs={'tags': '/'.join(tag.slug for tag in tag_list)} + )) + + +def search_no_hits(request, tags): + try: + tag_list = models.Tag.get_tag_list(tags) + except: + tag_list = [] + + return render_to_response('catalogue/search_no_hits.html', {'tags':tag_list}, + context_instance=RequestContext(request)) + +search_no_hits def tags_starting_with(request): prefix = request.GET.get('q', '') -- 2.20.1