All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jose Lamego <jose.a.lamego@linux.intel.com>
To: yocto@yoctoproject.org
Subject: [layerindex-web][PATCH v2] layerindex/views: support querying by layer name
Date: Wed, 31 May 2017 15:47:24 -0500	[thread overview]
Message-ID: <1496263644-16202-1-git-send-email-jose.a.lamego@linux.intel.com> (raw)
In-Reply-To: <1491247889-13977-1-git-send-email-jose.a.lamego@linux.intel.com>

This change supports querying recipes that belong to a specific layer
by using the prefix "layer:" + the desired layer name, for example:
"layer: openembedded-core" and this string can be used by itself or
combined with other supported options.

A descriptive error message is displayed when the query string has an
unexpected formatting or a non-valid layer name is searched.

[YOCTO #6618]

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

diff --git a/layerindex/views.py b/layerindex/views.py
index 65a536a..3eac3ac 100644
--- a/layerindex/views.py
+++ b/layerindex/views.py
@@ -390,13 +390,28 @@ class RecipeSearchView(ListView):
         for item in query_items:
             if item.startswith('inherits:'):
                 inherits.append(item.split(':')[1])
+            # support searches by layer name
+            elif item.startswith('layer:'):
+                query_layername = item.split(':')[1].strip().lower()
+                if not query_layername:
+                    messages.add_message(self.request, messages.ERROR, 'The \
+layer name is expected to follow the \"layer:\" prefix without any spaces.')
+                query_layer = LayerBranch.objects.filter(
+                    layer__name=query_layername)
+                if query_layer:
+                    init_qs = init_qs.filter(
+                        layerbranch__layer__id=query_layer[0].id)
+                else:
+                    messages.add_message(self.request, messages.ERROR,
+                                         'No layer \"%s\" was found.'
+                                         % query_layername)
             else:
                 query_terms.append(item)
         if inherits:
             # FIXME This is a bit ugly, perhaps we should consider having this as a one-many relationship instead
             for inherit in inherits:
                 init_qs = init_qs.filter(Q(inherits=inherit) | Q(inherits__startswith=inherit + ' ') | Q(inherits__endswith=' ' + inherit) | Q(inherits__contains=' %s ' % inherit))
-            query_string = ' '.join(query_terms)
+        query_string = ' '.join(query_terms)
 
         if query_string.strip():
             order_by = ('pn', 'layerbranch__layer')
-- 
2.7.4



  parent reply	other threads:[~2017-05-31 20:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-03 19:31 [layerindex-web][PATCH] views: support querying by layer name Jose Lamego
2017-05-25  0:16 ` Paul Eggleton
2017-05-31 20:47 ` Jose Lamego [this message]
2017-06-15 13:19   ` [layerindex-web][PATCH v2] layerindex/views: " Jose Lamego
2017-06-15 14:06     ` Paul Eggleton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1496263644-16202-1-git-send-email-jose.a.lamego@linux.intel.com \
    --to=jose.a.lamego@linux.intel.com \
    --cc=yocto@yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.