diff options
author | Michael Wood <michael.g.wood@intel.com> | 2015-08-04 22:46:30 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-08-06 16:04:44 -0500 |
commit | c4e7113dd09c11a8a661cbefc417fcfbc5d5f6af (patch) | |
tree | 8281f715ca6cdcd8872e14018d621a6e19980288 | |
parent | d3b9927a3cfc5adbfbb1fe88378ed8dde7644a8c (diff) | |
download | poky-c4e7113dd09c11a8a661cbefc417fcfbc5d5f6af.tar.gz |
bitbake: toaster: orm Add util functions to return common querysets
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.
(Bitbake rev: 2a10fecd985343802f0e99c6fff25c28980eee20)
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/toaster/orm/models.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index 3b72f802a0..4f07e37c52 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py | |||
@@ -20,7 +20,7 @@ | |||
20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
21 | 21 | ||
22 | from django.db import models | 22 | from django.db import models |
23 | from django.db.models import F, Q, Avg | 23 | from django.db.models import F, Q, Avg, Max |
24 | from django.utils import timezone | 24 | from django.utils import timezone |
25 | 25 | ||
26 | from django.core.urlresolvers import reverse | 26 | from django.core.urlresolvers import reverse |
@@ -195,6 +195,45 @@ class Project(models.Model): | |||
195 | def projectlayer_equivalent_set(self): | 195 | def projectlayer_equivalent_set(self): |
196 | return self.compatible_layerversions().filter(layer__name__in = [x.layercommit.layer.name for x in self.projectlayer_set.all()]).select_related("up_branch") | 196 | return self.compatible_layerversions().filter(layer__name__in = [x.layercommit.layer.name for x in self.projectlayer_set.all()]).select_related("up_branch") |
197 | 197 | ||
198 | def get_available_machines(self): | ||
199 | """ Returns QuerySet of all Machines which are provided by the | ||
200 | Layers currently added to the Project """ | ||
201 | queryset = Machine.objects.filter(layer_version__in=self.projectlayer_equivalent_set) | ||
202 | return queryset | ||
203 | |||
204 | def get_all_compatible_machines(self): | ||
205 | """ Returns QuerySet of all the compatible machines available to the | ||
206 | project including ones from Layers not currently added """ | ||
207 | compatible_layers = self.compatible_layerversions() | ||
208 | |||
209 | queryset = Machine.objects.filter(layer_version__in=compatible_layers) | ||
210 | return queryset | ||
211 | |||
212 | def get_available_recipes(self): | ||
213 | """ Returns QuerySet of all Recipes which are provided by the Layers | ||
214 | currently added to the Project """ | ||
215 | project_layers = self.projectlayer_equivalent_set() | ||
216 | queryset = Recipe.objects.filter(layer_version__in = project_layers) | ||
217 | |||
218 | # Copied from get_all_compatible_recipes | ||
219 | search_maxids = map(lambda i: i[0], list(queryset.values('name').distinct().annotate(max_id=Max('id')).values_list('max_id'))) | ||
220 | queryset = queryset.filter(id__in=search_maxids).select_related('layer_version', 'layer_version__layer', 'layer_version__up_branch', 'layer_source') | ||
221 | # End copy | ||
222 | |||
223 | return queryset | ||
224 | |||
225 | def get_all_compatible_recipes(self): | ||
226 | """ Returns QuerySet of all the compatible Recipes available to the | ||
227 | project including ones from Layers not currently added """ | ||
228 | compatible_layerversions = self.compatible_layerversions() | ||
229 | queryset = Recipe.objects.filter(layer_version__in = compatible_layerversions) | ||
230 | |||
231 | search_maxids = map(lambda i: i[0], list(queryset.values('name').distinct().annotate(max_id=Max('id')).values_list('max_id'))) | ||
232 | |||
233 | queryset = queryset.filter(id__in=search_maxids).select_related('layer_version', 'layer_version__layer', 'layer_version__up_branch', 'layer_source') | ||
234 | return queryset | ||
235 | |||
236 | |||
198 | def schedule_build(self): | 237 | def schedule_build(self): |
199 | from bldcontrol.models import BuildRequest, BRTarget, BRLayer, BRVariable, BRBitbake | 238 | from bldcontrol.models import BuildRequest, BRTarget, BRLayer, BRVariable, BRBitbake |
200 | br = BuildRequest.objects.create(project = self) | 239 | br = BuildRequest.objects.create(project = self) |