views.py: single result redirect

When the recipe search returns a single result, redirect to it
instead of showing the full result list view.

Part of the fix for [YOCTO #6618].

Signed-off-by: Alex Franco <alejandro.franco@linux.intel.com>
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Alex Franco 2015-10-29 18:06:38 -06:00 committed by Paul Eggleton
parent b1c5b15ae8
commit c8c25fb641

View File

@ -372,6 +372,12 @@ class RecipeSearchView(ListView):
context_object_name = 'recipe_list'
paginate_by = 50
def render_to_response(self, context, **kwargs):
if len(self.object_list) == 1:
return HttpResponseRedirect(reverse('recipe', args=(self.object_list[0].id,)))
else:
return super(ListView, self).render_to_response(context, **kwargs)
def get_queryset(self):
_check_url_branch(self.kwargs)
query_string = self.request.GET.get('q', '')