From c941743c9a1310c1b5ef942fa6e6d1ed31a7faa7 Mon Sep 17 00:00:00 2001 From: Alexandru DAMIAN Date: Fri, 5 Jun 2015 12:30:12 +0100 Subject: 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 Signed-off-by: Richard Purdie --- bitbake/lib/toaster/toastergui/widgets.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'bitbake/lib/toaster/toastergui/widgets.py') 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): self.empty_state = "Sorry - no data found" self.default_orderby = "" + # add the "id" column, undisplayable, by default + self.add_column(title="Id", + displayable=False, + orderable=True, + field_name="id") + + def get(self, request, *args, **kwargs): if request.GET.get('format', None) == 'json': @@ -142,6 +149,7 @@ class ToasterTable(TemplateView): def add_column(self, title="", help_text="", orderable=False, hideable=True, hidden=False, field_name="", filter_name=None, static_data_name=None, + displayable=True, computation=None, static_data_template=None): """Add a column to the table. @@ -168,6 +176,8 @@ class ToasterTable(TemplateView): 'filter_name' : filter_name, 'static_data_name': static_data_name, 'static_data_template': static_data_template, + 'displayable': displayable, + 'computation': computation, }) def render_static_data(self, template, row): @@ -289,8 +299,11 @@ class ToasterTable(TemplateView): col['field_name'] = col['static_data_name'] - if True: # we add the raw model data at all times - model_data = row + # compute the computation on the raw data if needed + model_data = row + if col['computation']: + model_data = col['computation'](row) + else: # Traverse to any foriegn key in the object hierachy for subfield in field.split("__"): if hasattr(model_data, subfield): @@ -300,7 +313,7 @@ class ToasterTable(TemplateView): if isinstance(model_data, types.MethodType): model_data = model_data() - required_data[field] = model_data + required_data[col['field_name']] = model_data data['rows'].append(required_data) -- cgit v1.2.3-54-g00ecf