Openembedded Bitbake Development
 help / color / mirror / Atom feed
From: Ed Bartosh <ed.bartosh@linux.intel.com>
To: bitbake-devel@lists.openembedded.org
Subject: [PATCH 02/12] bitbake: toaster: orm Add util functions to return common querysets
Date: Tue,  4 Aug 2015 22:46:30 +0300	[thread overview]
Message-ID: <3af50d06b1f56cc8d64bc69bb26de075bd388dd5.1438717072.git.ed.bartosh@linux.intel.com> (raw)
In-Reply-To: <691696f2b87d41540b14b10ef08762f8529b4909.1438717072.git.ed.bartosh@linux.intel.com>
In-Reply-To: <cover.1438717072.git.ed.bartosh@linux.intel.com>

From: Michael Wood <michael.g.wood@intel.com>

We use these querysets when creating tables of results and also when we
want to have a typeahead search. These can also form the basis of future
API endpoints.

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 lib/toaster/orm/models.py | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/lib/toaster/orm/models.py b/lib/toaster/orm/models.py
index 3b72f80..4f07e37 100644
--- a/lib/toaster/orm/models.py
+++ b/lib/toaster/orm/models.py
@@ -20,7 +20,7 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 from django.db import models
-from django.db.models import F, Q, Avg
+from django.db.models import F, Q, Avg, Max
 from django.utils import timezone
 
 from django.core.urlresolvers import reverse
@@ -195,6 +195,45 @@ class Project(models.Model):
     def projectlayer_equivalent_set(self):
         return self.compatible_layerversions().filter(layer__name__in = [x.layercommit.layer.name for x in self.projectlayer_set.all()]).select_related("up_branch")
 
+    def get_available_machines(self):
+        """ Returns QuerySet of all Machines which are provided by the
+        Layers currently added to the Project """
+        queryset = Machine.objects.filter(layer_version__in=self.projectlayer_equivalent_set)
+        return queryset
+
+    def get_all_compatible_machines(self):
+        """ Returns QuerySet of all the compatible machines available to the
+        project including ones from Layers not currently added """
+        compatible_layers = self.compatible_layerversions()
+
+        queryset = Machine.objects.filter(layer_version__in=compatible_layers)
+        return queryset
+
+    def get_available_recipes(self):
+        """ Returns QuerySet of all Recipes which are provided by the Layers
+        currently added to the Project """
+        project_layers = self.projectlayer_equivalent_set()
+        queryset = Recipe.objects.filter(layer_version__in = project_layers)
+
+        # Copied from get_all_compatible_recipes
+        search_maxids = map(lambda i: i[0], list(queryset.values('name').distinct().annotate(max_id=Max('id')).values_list('max_id')))
+        queryset = queryset.filter(id__in=search_maxids).select_related('layer_version', 'layer_version__layer', 'layer_version__up_branch', 'layer_source')
+        # End copy
+
+        return queryset
+
+    def get_all_compatible_recipes(self):
+        """ Returns QuerySet of all the compatible Recipes available to the
+        project including ones from Layers not currently added """
+        compatible_layerversions = self.compatible_layerversions()
+        queryset = Recipe.objects.filter(layer_version__in = compatible_layerversions)
+
+        search_maxids = map(lambda i: i[0], list(queryset.values('name').distinct().annotate(max_id=Max('id')).values_list('max_id')))
+
+        queryset = queryset.filter(id__in=search_maxids).select_related('layer_version', 'layer_version__layer', 'layer_version__up_branch', 'layer_source')
+        return queryset
+
+
     def schedule_build(self):
         from bldcontrol.models import BuildRequest, BRTarget, BRLayer, BRVariable, BRBitbake
         br = BuildRequest.objects.create(project = self)
-- 
2.1.4



  parent reply	other threads:[~2015-08-04 19:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-04 19:45 [PATCH 00/12] toaster: bring back the correct typeahead behaviour as a modular widget Ed Bartosh
2015-08-04 19:46 ` [PATCH 01/12] bitbake: toaster: orm Add util function to return the url to layerversion Ed Bartosh
2015-08-04 19:46 ` Ed Bartosh [this message]
2015-08-04 19:46 ` [PATCH 03/12] bitbake: toastergui: tables Use util functions for the common querysets Ed Bartosh
2015-08-04 19:46 ` [PATCH 04/12] bitbake: toastergui: widgets Add a typeahead widget Ed Bartosh
2015-08-04 19:46 ` [PATCH 05/12] bitbake: toastergui: Add typeaheads layers, machines, projects, recipes Ed Bartosh
2015-08-04 19:46 ` [PATCH 06/12] bitbake: toastergui: Switch to using the new toaster typeahead widget Ed Bartosh
2015-08-04 19:46 ` [PATCH 07/12] bitbake: toastergui: libtoaster Throw an exception no url is specified Ed Bartosh
2015-08-04 19:46 ` [PATCH 08/12] bitbake: toasterui: views Remove unused xhr_typeahead view definition Ed Bartosh
2015-08-04 19:46 ` [PATCH 09/12] bitbake: toastergui: views Standardise the fields project layer response Ed Bartosh
2015-08-04 19:46 ` [PATCH 10/12] bitbake: toastergui: tests Fix and more comprehensive typeahead unittest Ed Bartosh
2015-08-04 19:46 ` [PATCH 11/12] bitbake: toastergui: libtoaster: typeahead resiliency for slow server Ed Bartosh
2015-08-04 19:46 ` [PATCH 12/12] bitbake: toastergui: libtoaster typeahead Add in results highlighter Ed Bartosh

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=3af50d06b1f56cc8d64bc69bb26de075bd388dd5.1438717072.git.ed.bartosh@linux.intel.com \
    --to=ed.bartosh@linux.intel.com \
    --cc=bitbake-devel@lists.openembedded.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox