diff options
author | Elliot Smith <elliot.smith@intel.com> | 2016-04-19 17:28:46 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-04-19 21:11:26 +0100 |
commit | 1cf8f215b3543ce0f39ebd3321d58cfb518f1c1f (patch) | |
tree | ac2ec1be24db0eb3f845d53cfa7ce6c18c36ab70 /bitbake/lib/toaster/toastergui/templatetags/objects_to_dictionaries_filter.py | |
parent | a40a3e6defefd69521a417a366b8752be7e778f9 (diff) | |
download | poky-1cf8f215b3543ce0f39ebd3321d58cfb518f1c1f.tar.gz |
bitbake: toaster: add modal to select custom image for editing
Add functionality to the placeholder button on the build dashboard
to open a modal dialog displaying editable custom images, in cases
where multiple custom images were built by the build. Where there
is only one editable custom image, go direct to its edit page.
The images shown in the modal are custom recipes for the project
which were built during the build shown in the dashboard.
This also affects the new custom image dialog, as that also has
to show custom image recipes as well as image recipes built during
the build. Modify the API on the Build object to support both.
Also modify and rename the queryset_to_list template filter so that
it can deal with lists as well as querysets, as the new custom image
modal has to show a list of image recipes which is an amalgam of two
querysets.
[YOCTO #9123]
(Bitbake rev: 8c2aea3fa8e1071de60390e86e2536904fa9b7c0)
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 'bitbake/lib/toaster/toastergui/templatetags/objects_to_dictionaries_filter.py')
-rw-r--r-- | bitbake/lib/toaster/toastergui/templatetags/objects_to_dictionaries_filter.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/toastergui/templatetags/objects_to_dictionaries_filter.py b/bitbake/lib/toaster/toastergui/templatetags/objects_to_dictionaries_filter.py new file mode 100644 index 0000000000..0dcc7d2714 --- /dev/null +++ b/bitbake/lib/toaster/toastergui/templatetags/objects_to_dictionaries_filter.py | |||
@@ -0,0 +1,35 @@ | |||
1 | from django import template | ||
2 | import json | ||
3 | |||
4 | register = template.Library() | ||
5 | |||
6 | def objects_to_dictionaries(iterable, fields): | ||
7 | """ | ||
8 | Convert an iterable into a list of dictionaries; fields should be set | ||
9 | to a comma-separated string of properties for each item included in the | ||
10 | resulting list; e.g. for a queryset: | ||
11 | |||
12 | {{ queryset | objects_to_dictionaries:"id,name" }} | ||
13 | |||
14 | will return a list like | ||
15 | |||
16 | [{'id': 1, 'name': 'foo'}, ...] | ||
17 | |||
18 | providing queryset has id and name fields | ||
19 | |||
20 | This is mostly to support serialising querysets or lists of model objects | ||
21 | to JSON | ||
22 | """ | ||
23 | objects = [] | ||
24 | |||
25 | if fields: | ||
26 | fields_list = [field.strip() for field in fields.split(',')] | ||
27 | for item in iterable: | ||
28 | out = {} | ||
29 | for field in fields_list: | ||
30 | out[field] = getattr(item, field) | ||
31 | objects.append(out) | ||
32 | |||
33 | return objects | ||
34 | |||
35 | register.filter('objects_to_dictionaries', objects_to_dictionaries) | ||