[oe-commits] [bitbake] 15/44: toaster: widgets ToasterTable Catch template rendering exceptions

git at git.openembedded.org git at git.openembedded.org
Mon Jun 13 21:11:03 UTC 2016


rpurdie pushed a commit to branch master-next
in repository bitbake.

commit 566b4fbe9cfe4c6c0605c4f6444083ee4cf8b958
Author: Michael Wood <michael.g.wood at intel.com>
AuthorDate: Thu May 26 16:12:26 2016 +0100

    toaster: widgets ToasterTable Catch template rendering exceptions
    
    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 at intel.com>
---
 lib/toaster/toastergui/widgets.py | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/lib/toaster/toastergui/widgets.py b/lib/toaster/toastergui/widgets.py
index 584bde7..4276c2a 100644
--- a/lib/toaster/toastergui/widgets.py
+++ b/lib/toaster/toastergui/widgets.py
@@ -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

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list