summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/widgets.py
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-06-05 12:30:12 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-06-12 00:01:48 +0100
commitc941743c9a1310c1b5ef942fa6e6d1ed31a7faa7 (patch)
tree19a7e7c37848359f98f50fb260fe1b45be8ceb56 /bitbake/lib/toaster/toastergui/widgets.py
parent58600cf8e76f270969ded6ec63ac0908f39dae09 (diff)
downloadpoky-c941743c9a1310c1b5ef942fa6e6d1ed31a7faa7.tar.gz
bitbake: toaster: ToasterTables add computational fields
This patch adds the ability to pass a function to be computed for generating a field value in setting up a column in ToasterTables. Also adding "displayable" property that can be turned False for columns that are present in JSON data but are not part of the UI. Add the "id" column by default for all rows. (Bitbake rev: fb683135348b074412da154585c75865aad1eab0) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/widgets.py')
-rw-r--r--bitbake/lib/toaster/toastergui/widgets.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/bitbake/lib/toaster/toastergui/widgets.py b/bitbake/lib/toaster/toastergui/widgets.py
index 82b7514bd8..407a0fbe15 100644
--- a/bitbake/lib/toaster/toastergui/widgets.py
+++ b/bitbake/lib/toaster/toastergui/widgets.py
@@ -54,6 +54,13 @@ class ToasterTable(TemplateView):
54 self.empty_state = "Sorry - no data found" 54 self.empty_state = "Sorry - no data found"
55 self.default_orderby = "" 55 self.default_orderby = ""
56 56
57 # add the "id" column, undisplayable, by default
58 self.add_column(title="Id",
59 displayable=False,
60 orderable=True,
61 field_name="id")
62
63
57 def get(self, request, *args, **kwargs): 64 def get(self, request, *args, **kwargs):
58 if request.GET.get('format', None) == 'json': 65 if request.GET.get('format', None) == 'json':
59 66
@@ -142,6 +149,7 @@ class ToasterTable(TemplateView):
142 def add_column(self, title="", help_text="", 149 def add_column(self, title="", help_text="",
143 orderable=False, hideable=True, hidden=False, 150 orderable=False, hideable=True, hidden=False,
144 field_name="", filter_name=None, static_data_name=None, 151 field_name="", filter_name=None, static_data_name=None,
152 displayable=True, computation=None,
145 static_data_template=None): 153 static_data_template=None):
146 """Add a column to the table. 154 """Add a column to the table.
147 155
@@ -168,6 +176,8 @@ class ToasterTable(TemplateView):
168 'filter_name' : filter_name, 176 'filter_name' : filter_name,
169 'static_data_name': static_data_name, 177 'static_data_name': static_data_name,
170 'static_data_template': static_data_template, 178 'static_data_template': static_data_template,
179 'displayable': displayable,
180 'computation': computation,
171 }) 181 })
172 182
173 def render_static_data(self, template, row): 183 def render_static_data(self, template, row):
@@ -289,8 +299,11 @@ class ToasterTable(TemplateView):
289 299
290 col['field_name'] = col['static_data_name'] 300 col['field_name'] = col['static_data_name']
291 301
292 if True: # we add the raw model data at all times 302 # compute the computation on the raw data if needed
293 model_data = row 303 model_data = row
304 if col['computation']:
305 model_data = col['computation'](row)
306 else:
294 # Traverse to any foriegn key in the object hierachy 307 # Traverse to any foriegn key in the object hierachy
295 for subfield in field.split("__"): 308 for subfield in field.split("__"):
296 if hasattr(model_data, subfield): 309 if hasattr(model_data, subfield):
@@ -300,7 +313,7 @@ class ToasterTable(TemplateView):
300 if isinstance(model_data, types.MethodType): 313 if isinstance(model_data, types.MethodType):
301 model_data = model_data() 314 model_data = model_data()
302 315
303 required_data[field] = model_data 316 required_data[col['field_name']] = model_data
304 317
305 data['rows'].append(required_data) 318 data['rows'].append(required_data)
306 319