Added "empty" (rendering an empty string) viewlet and content provider as base classes
authorThierry Florac <thierry.florac@onf.fr>
Tue, 10 Apr 2018 15:13:32 +0200
changeset 17 47b6b7d92f4a
parent 16 6376d1ff2918
child 18 0c3173d06f3f
Added "empty" (rendering an empty string) viewlet and content provider as base classes
src/pyams_viewlet/viewlet.py
--- a/src/pyams_viewlet/viewlet.py	Tue Apr 03 15:22:12 2018 +0200
+++ b/src/pyams_viewlet/viewlet.py	Tue Apr 10 15:13:32 2018 +0200
@@ -28,8 +28,8 @@
 
 
 @implementer(IContentProvider)
-class BaseContentProvider(object):
-    """Base template based content provider"""
+class EmptyContentProvider(object):
+    """Empty content provider base class"""
 
     permission = None
 
@@ -37,15 +37,22 @@
         self.context = context
         self.request = request
 
-    def update(self):
-        pass
-
     def __call__(self):
         if self.permission and not self.request.has_permission(self.permission, context=self.context):
             return ''
         self.update()
         return self.render()
 
+    def update(self):
+        pass
+
+    def render(self):
+        return ''
+
+
+class BaseContentProvider(EmptyContentProvider):
+    """Base template based content provider"""
+
     render = get_view_template()
 
 
@@ -113,8 +120,8 @@
 
 
 @implementer(IViewlet)
-class Viewlet(object):
-    """Viewlet adapter class used in meta directive as a mixin class."""
+class EmptyViewlet(object):
+    """Empty viewlet base class"""
 
     permission = None
 
@@ -127,6 +134,13 @@
     def update(self):
         pass
 
+    def render(self):
+        return ''
+
+
+class Viewlet(EmptyViewlet):
+    """Viewlet adapter class used in meta directive as a mixin class."""
+
     render = get_view_template()