From: Alex Franco <alejandro.fra...@linux.intel.com>

When a recipe search returns only one result, clicking the single
result at the results view is still required to view further
recipe detail.

This change automatically redirects to the recipe details view
when the recipe search returns a single result.

[YOCTO #6618]

Signed-off-by: Jose Lamego <jose.a.lam...@linux.intel.com>
---
 layerindex/views.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/layerindex/views.py b/layerindex/views.py
index 0f73e93..03fadbb 100644
--- a/layerindex/views.py
+++ b/layerindex/views.py
@@ -372,6 +372,14 @@ 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', '')
-- 
1.9.1

-- 
_______________________________________________
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto

Reply via email to