Updated content provider rendering API
authorThierry Florac <tflorac@ulthar.net>
Wed, 25 Aug 2021 12:46:41 +0200
changeset 62 f0a0c441c806
parent 61 c6f035153997
child 63 ef62d05e9e39
Updated content provider rendering API
src/pyams_viewlet/viewlet.py
--- a/src/pyams_viewlet/viewlet.py	Wed Nov 18 13:05:25 2020 +0100
+++ b/src/pyams_viewlet/viewlet.py	Wed Aug 25 12:46:41 2021 +0200
@@ -21,6 +21,7 @@
 import venusian
 from pyramid.exceptions import ConfigurationError
 from pyramid.interfaces import IRequest, IView
+from zope.component import ComponentLookupError
 from zope.contentprovider.interfaces import IContentProvider
 from zope.interface import Interface, implementer
 
@@ -43,17 +44,17 @@
         self.context = context
         self.request = request
 
-    def __call__(self):
+    def __call__(self, template_name=''):
         if self.permission and not self.request.has_permission(self.permission,
                                                                context=self.context):
             return ''
         self.update()
-        return self.render()
+        return self.render(template_name)
 
     def update(self):
         """See `IContentProvider` interface"""
 
-    def render(self):  # pylint: disable=no-self-use
+    def render(self, template_name=''):  # pylint: disable=no-self-use
         """See `IContentProvider` interface"""
         return ''
 
@@ -67,7 +68,13 @@
         for resource in self.resources:
             resource.need()
 
-    render = get_view_template()
+    def render(self, template_name=''):
+        template = get_view_template(name=template_name)
+        try:
+            return template(self)
+        except ComponentLookupError:
+            template = get_view_template()
+            return template(self)
 
 
 @implementer(IContentProvider)