]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
toaster: Added custom filter tags for use in templates.
authorRavi Chintakunta <ravi.chintakunta@timesys.com>
Tue, 14 Jan 2014 19:06:38 +0000 (14:06 -0500)
committerAlexandru DAMIAN <alexandru.damian@intel.com>
Mon, 27 Jan 2014 15:19:49 +0000 (15:19 +0000)
- custom filter tag to return the css class based on
  the task execution status and execution outcome

- custom filters for active filter icon and tooltip text

- custom filter for displaying blank for None, zero, '0' and
  'Not Applicable'

Signed-off-by: Ravi Chintakunta <ravi.chintakunta@timesys.com>
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
lib/toaster/toastergui/templatetags/projecttags.py

index d57a0598f90895f53af33b7c9253b657f474c27a..5105be48d271873c306486fece603ff492787e74 100644 (file)
@@ -66,3 +66,38 @@ def datecompute(delta, start = timezone.now()):
 @register.filter(name = 'sortcols')
 def sortcols(tablecols):
     return sorted(tablecols, key = lambda t: t['name'])
+
+@register.filter
+def task_color(task_object):
+    """ Return css class depending on Task execution status and execution outcome
+    """
+    if not task_object.task_executed:
+        return 'class=muted'
+    elif task_object.get_outcome_display == 'Failed':
+        return 'class=error'
+    else:
+        return ''
+
+@register.filter
+def filtered_icon(options, filter):
+    """Returns btn-primary if the filter matches one of the filter options
+    """
+    for option in options:
+        if filter == option[1]:
+            return "btn-primary"
+    return ""
+
+@register.filter
+def filtered_tooltip(options, filter):
+    """Returns tooltip for the filter icon if the filter matches one of the filter options
+    """
+    for option in options:
+        if filter == option[1]:
+            return "Showing only %s"%option[0]
+    return ""
+
+@register.filter
+def format_none_and_zero(value):
+    """Return empty string if the value is None, zero or Not Applicable
+    """
+    return "" if (not value) or (value == 0) or (value == "0") or (value == 'Not Applicable') else value