[bitbake-devel] [PATCH 44/94] bitbake: webhob: add search for build model

Alex DAMIAN alexandru.damian at intel.com
Tue Sep 24 16:52:13 UTC 2013


From: Calin Dragomir <calinx.l.dragomir at intel.com>

This patch enables search on the build model. However, the
search can be executed only on a predefined list of fields
allowed to be searched.

Signed-off-by: Calin Dragomir <calinx.l.dragomir at intel.com>
Signed-off-by: Alexandru DAMIAN <alexandru.damian at intel.com>
---
 bitbake/lib/webhob/bldviewer/views.py | 17 +++++++++++++++++
 bitbake/lib/webhob/orm/models.py      |  3 +++
 2 files changed, 20 insertions(+)

diff --git a/bitbake/lib/webhob/bldviewer/views.py b/bitbake/lib/webhob/bldviewer/views.py
index 3ef6940..423fdf7 100644
--- a/bitbake/lib/webhob/bldviewer/views.py
+++ b/bitbake/lib/webhob/bldviewer/views.py
@@ -1,3 +1,6 @@
+import operator
+
+from django.db.models import Q
 from django.shortcuts import render
 from orm.models import Build, Task, Layer, Layer_Version, Task_Dependency, Recipe, Package
 
@@ -93,6 +96,8 @@ def model_explorer(request, model_name):
     if invalid:
         return HttpResponseBadRequest()
 
+    search_term = request.GET.get('search', '')
+
     if filter_string:
         filter_terms = _get_filtering_terms(filter_string)
         try:
@@ -102,6 +107,9 @@ def model_explorer(request, model_name):
     else:
         queryset = model.objects.all()
 
+    if search_term:
+        queryset = _get_search_results(search_term, queryset, model)
+
     if offset and limit:
         queryset = queryset[offset:(offset+limit)]
     elif offset:
@@ -159,3 +167,12 @@ def _validate_input(input, model):
                 return None, invalid
 
     return input, invalid
+
+def _get_search_results(search_term, queryset, model):
+    q_map = map(lambda x: Q(**{x+'__icontains': search_term}),
+                model.search_allowed_fields)
+
+    search_object = reduce(operator.or_, q_map)
+    queryset = queryset.filter(search_object)
+
+    return queryset
diff --git a/bitbake/lib/webhob/orm/models.py b/bitbake/lib/webhob/orm/models.py
index 0d6cf15..a4721db 100644
--- a/bitbake/lib/webhob/orm/models.py
+++ b/bitbake/lib/webhob/orm/models.py
@@ -12,6 +12,9 @@ class Build(models.Model):
         (IN_PROGRESS, 'In Progress'),
     )
 
+    search_allowed_fields = ['target', 'machine__name',
+                             'cooker_log_path', 'image_fstypes']
+
     uuid = models.CharField(max_length=100, unique=True)
     target = models.CharField(max_length=100)
     is_image = models.BooleanField(default = False)
-- 
1.8.1.2




More information about the bitbake-devel mailing list