summaryrefslogtreecommitdiffstats
path: root/lib/toaster/orm/models.py
diff options
context:
space:
mode:
authorElliot Smith <elliot.smith@intel.com>2016-04-19 17:28:45 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-04-19 21:10:58 +0100
commit4c49ffd28e41c4597bdac34d5e54c125571a4b95 (patch)
tree586a0510eec3ca7dd5f403d3cd1a5a49a553fcdf /lib/toaster/orm/models.py
parentcea34880ad3847bd0e24c9b650eb816e1757cf2b (diff)
downloadbitbake-4c49ffd28e41c4597bdac34d5e54c125571a4b95.tar.gz
toaster: add build dashboard buttons to edit/create custom images
When a build is viewed in the dashboard, enable users to edit a custom image which was built during that build, and/or create a new custom image based on one of the image recipes built during the build. Add methods to the Build model to enable querying for the set of image recipes built during a build. Add buttons to the dashboard, with the "Edit custom image" button opening a basic modal for now. The "New custom image" button opens the existing new custom image modal, but is modified to show a list of images available as a base for a new custom image. Add a new function to the new custom image modal's script which enables multiple potential custom images to be shown as radio buttons in the dialog (if there is more than 1). Modify existing code to use this new function. Add a template filter which allows the queryset of recipes for a build to be available to client-side scripts, and from there be used to populate the new custom image modal. [YOCTO #9123] Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/toaster/orm/models.py')
-rw-r--r--lib/toaster/orm/models.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/toaster/orm/models.py b/lib/toaster/orm/models.py
index f0a878664..75e6ea399 100644
--- a/lib/toaster/orm/models.py
+++ b/lib/toaster/orm/models.py
@@ -490,6 +490,47 @@ class Build(models.Model):
tgts = Target.objects.filter(build_id = self.id).order_by( 'target' );
return( tgts );
+ def get_recipes(self):
+ """
+ Get the recipes related to this build;
+ note that the related layer versions and layers are also prefetched
+ by this query, as this queryset can be sorted by these objects in the
+ build recipes view; prefetching them here removes the need
+ for another query in that view
+ """
+ layer_versions = Layer_Version.objects.filter(build=self)
+ criteria = Q(layer_version__id__in=layer_versions)
+ return Recipe.objects.filter(criteria) \
+ .select_related('layer_version', 'layer_version__layer')
+
+ def get_custom_image_recipe_names(self):
+ """
+ Get the names of custom image recipes for this build's project
+ as a list; this is used to screen out custom image recipes from the
+ recipes for the build by name, and to distinguish image recipes from
+ custom image recipes
+ """
+ custom_image_recipes = \
+ CustomImageRecipe.objects.filter(project=self.project)
+ return custom_image_recipes.values_list('name', flat=True)
+
+ def get_image_recipes(self):
+ """
+ Returns a queryset of image recipes related to this build, sorted
+ by name
+ """
+ criteria = Q(is_image=True)
+ return self.get_recipes().filter(criteria).order_by('name')
+
+ def get_custom_image_recipes(self):
+ """
+ Returns a queryset of custom image recipes related to this build,
+ sorted by name
+ """
+ custom_image_recipe_names = self.get_custom_image_recipe_names()
+ criteria = Q(is_image=True) & Q(name__in=custom_image_recipe_names)
+ return self.get_recipes().filter(criteria).order_by('name')
+
def get_outcome_text(self):
return Build.BUILD_OUTCOME[int(self.outcome)][1]