[yocto] [PATCH 1/2] [layerindex-web] views.py: single result redirect

Alex Franco alejandro.franco at linux.intel.com
Thu Oct 29 17:06:38 PDT 2015


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

[YOCTO #6618]

Signed-off-by: Alex Franco <alejandro.franco at linux.intel.com>
---
 layerindex/views.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/layerindex/views.py b/layerindex/views.py
index 7e877ac..8be3311 100644
--- a/layerindex/views.py
+++ b/layerindex/views.py
@@ -368,6 +368,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("/layerindex/recipe/%s/" % 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', '')
-- 
2.6.1




More information about the yocto mailing list