Skip to contentSkip to conversation

views.py: Redirect to recipe details for single results

PATCH Jose Lamego 2 participants 5 messages Mar 13, 2017 – Apr 3, 2017 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Ping.

Quoted 36 lines · Jose Lamego

From: Alex Franco <[email protected]>

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]

---
 layerindex/views.py | 8 ++++++++
 1 file changed, 8 insertions(+)
layerindex/views.py +8 -0
index 0f73e93..03fadbb 100644
@@ -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', '')
Signature · 1 line
Jose Lamego | OTC Embedded Platforms & Tools | GDC
#3 lore raw

This should be using a reverse() call instead of a hardcoded URL path suffix. However, since that was a trivial fix I've done that and merged it - it'll appear in the layer index once we do the next upgrade (fairly soon).

Cheers,
Paul

Quoted 41 lines · NZDT Jose Lamego

Ping.

Quoted 38 lines · Jose Lamego

From: Alex Franco <[email protected]>

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]

---

 layerindex/views.py | 8 ++++++++
 1 file changed, 8 insertions(+)
layerindex/views.py +8 -0
index 0f73e93..03fadbb 100644
@@ -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', '')
Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

Re: [layerindex-web][PATCH 2/2] views.py: Consider layer name in recipe search

Ping.

Quoted 31 lines · Jose Lamego

From: Alex Franco <[email protected]>

Recipe search cannot be narrowed to a specific layer, producing unnecessary results.

This change allows including a layers name when searching for recipes to narrow the yielded results by adding a layer name to the simplesearch.getquery call in the recipe search view.

[YOCTO #6618]

---
 layerindex/views.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
layerindex/views.py +2 -1
index 03fadbb..5db6fbc 100644
@@ -406,7 +406,8 @@ class RecipeSearchView(ListView):
             qs0 = init_qs.filter(pn=query_string).order_by(*order_by)
             qs0 = recipes_preferred_count(qs0)
 
-            entry_query = simplesearch.get_query(query_string, ['pn'])
+            entry_query = simplesearch.get_query(
+                query_string, ['pn', 'layerbranch__layer__name'])
             qs1 = init_qs.filter(entry_query).order_by(*order_by)
             qs1 = recipes_preferred_count(qs1)
 
Signature · 1 line
Jose Lamego | OTC Embedded Platforms & Tools | GDC
#6 lore raw

Re: [layerindex-web][PATCH 2/2] views.py: Consider layer name in recipe search

Hi Jose,

Sorry for the delay in responding to this.

I'd prefer if this were implemented like the recently added "inherits:" where we have a special prefix e.g. "layer:" in order to search for things in a particular layer. Then it's much clearer as to what's going on.

Cheers,
Paul

Quoted 35 lines · NZDT Jose Lamego

Ping.

Quoted 32 lines · Jose Lamego

From: Alex Franco <[email protected]>

Recipe search cannot be narrowed to a specific layer, producing unnecessary results.

This change allows including a layers name when searching for recipes to narrow the yielded results by adding a layer name to the simplesearch.getquery call in the recipe search view.

[YOCTO #6618]

---

 layerindex/views.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
layerindex/views.py +2 -1
index 03fadbb..5db6fbc 100644
@@ -406,7 +406,8 @@ class RecipeSearchView(ListView):
             qs0 = init_qs.filter(pn=query_string).order_by(*order_by)
             qs0 = recipes_preferred_count(qs0)
 
-            entry_query = simplesearch.get_query(query_string, ['pn'])
+            entry_query = simplesearch.get_query(
+                query_string, ['pn', 'layerbranch__layer__name'])
 
             qs1 = init_qs.filter(entry_query).order_by(*order_by)
             qs1 = recipes_preferred_count(qs1)
Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre
#7 lore raw

Re: [layerindex-web][PATCH 2/2] views.py: Consider layer name in recipe search

Quoted 8 lines · Paul Eggleton

Hi Jose,

Sorry for the delay in responding to this.

I'd prefer if this were implemented like the recently added "inherits:" where we have a special prefix e.g. "layer:" in order to search for things in a particular layer. Then it's much clearer as to what's going on.

I've submitted a new patch following this approach:
https://lists.yoctoproject.org/pipermail/yocto/2017-April/035451.html

Quoted 41 lines

Cheers,
Paul

Quoted 35 lines · NZDT Jose Lamego

Ping.

Quoted 32 lines · Jose Lamego

From: Alex Franco <[email protected]>

Recipe search cannot be narrowed to a specific layer, producing unnecessary results.

This change allows including a layers name when searching for recipes to narrow the yielded results by adding a layer name to the simplesearch.getquery call in the recipe search view.

[YOCTO #6618]

---

 layerindex/views.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
layerindex/views.py +2 -1
index 03fadbb..5db6fbc 100644
@@ -406,7 +406,8 @@ class RecipeSearchView(ListView):
             qs0 = init_qs.filter(pn=query_string).order_by(*order_by)
             qs0 = recipes_preferred_count(qs0)
 
-            entry_query = simplesearch.get_query(query_string, ['pn'])
+            entry_query = simplesearch.get_query(
+                query_string, ['pn', 'layerbranch__layer__name'])
 
             qs1 = init_qs.filter(entry_query).order_by(*order_by)
             qs1 = recipes_preferred_count(qs1)
Signature · 1 line
Jose Lamego | OTC Embedded Platforms & Tools | GDC