]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
toaster: widgets ToasterTable Catch template rendering exceptions
authorMichael Wood <michael.g.wood@intel.com>
Thu, 26 May 2016 15:12:26 +0000 (16:12 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 13 Jun 2016 21:04:30 +0000 (22:04 +0100)
If a cell template rendering causes an exception catch it and carry on,
this at least allows the table to show the rest of the data if nothing
else. Also improve the error logging so that it's possible what the
offending template snippet was.

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
lib/toaster/toastergui/widgets.py

index 584bde7db518ff8165b248aa9e185d5707f562ae..4276c2aabffca7144313f1abc7c07b7b00a0aebc 100644 (file)
@@ -29,6 +29,8 @@ from django.core.paginator import Paginator, EmptyPage
 from django.db.models import Q
 from orm.models import Project, ProjectLayer, Layer_Version
 from django.template import Context, Template
+from django.template import VariableDoesNotExist
+from django.template import TemplateSyntaxError
 from django.core.serializers.json import DjangoJSONEncoder
 from django.core.exceptions import FieldError
 from django.conf.urls import url, patterns
@@ -349,10 +351,20 @@ class ToasterTable(TemplateView):
                         # so that this can be used as the html class name
                         col['field_name'] = col['static_data_name']
 
-                        # Render the template given
-                        required_data[col['static_data_name']] = \
-                            self.render_static_data(
-                                col['static_data_template'], model_obj)
+                        try:
+                            # Render the template given
+                            required_data[col['static_data_name']] = \
+                                    self.render_static_data(
+                                        col['static_data_template'], model_obj)
+                        except (TemplateSyntaxError,
+                                VariableDoesNotExist) as e:
+                            logger.error("could not render template code"
+                                         "%s %s %s",
+                                         col['static_data_template'],
+                                         e, self.__class__.__name__)
+                            required_data[col['static_data_name']] =\
+                                '<!--error-->'
+
                     else:
                         # Traverse to any foriegn key in the field
                         # e.g. recipe__layer_version__name