mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 03:49:10 +02:00
layerindex/views: support querying by layer name
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> Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
parent
8dfe44ed5e
commit
b958a991ca
|
@ -390,13 +390,29 @@ 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.')
|
||||
else:
|
||||
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')
|
||||
|
|
Loading…
Reference in New Issue
Block a user