Added attribute to portlet renderer to specify if portlet is using authentication information
authorThierry Florac <thierry.florac@onf.fr>
Mon, 25 Jun 2018 09:42:24 +0200
changeset 138 b671ae6b0e88
parent 137 33c0a30554c7
child 139 e93775177b43
Added attribute to portlet renderer to specify if portlet is using authentication information
src/pyams_portal/interfaces/__init__.py
src/pyams_portal/portlet.py
--- a/src/pyams_portal/interfaces/__init__.py	Sat Jun 23 14:32:56 2018 +0200
+++ b/src/pyams_portal/interfaces/__init__.py	Mon Jun 25 09:42:24 2018 +0200
@@ -159,6 +159,7 @@
     target_interface = Attribute("Target interface provided by this renderer")
 
     use_portlets_cache = Attribute("Can renderer use rendering cache?")
+    use_authentication = Attribute("If 'True', portlet cache entry key is based on current authentication")
 
 
 PORTLET_RENDERER_SETTINGS_KEY = 'pyams_portal.renderer.settings::{0}'
--- a/src/pyams_portal/portlet.py	Sat Jun 23 14:32:56 2018 +0200
+++ b/src/pyams_portal/portlet.py	Mon Jun 25 09:42:24 2018 +0200
@@ -186,6 +186,7 @@
 
     target_interface = None
     use_portlets_cache = True
+    use_authentication = False
 
     weight = 0
 
@@ -215,6 +216,8 @@
                 cache_key = PORTLETS_CACHE_DISPLAY_CONTEXT_KEY.format(portlet=ICacheKeyValue(self.settings),
                                                                       context=ICacheKeyValue(self.context),
                                                                       display=ICacheKeyValue(display_context))
+            if self.use_authentication:
+                cache_key = '{0}::{1}'.format(cache_key, self.request.principal.id)
             # load rendered content from cache, or create output and store it in cache
             try:
                 result = portlets_cache.get_value(cache_key)