Set distinct profile name to correctly get user's avatar
authorThierry Florac <thierry.florac@onf.fr>
Thu, 02 Jun 2016 16:18:03 +0200
changeset 64 59d37fc75008
parent 63 402858ec5ac9
child 65 e2733978d478
Set distinct profile name to correctly get user's avatar
src/pyams_security/profile.py
--- a/src/pyams_security/profile.py	Thu Jun 02 16:17:08 2016 +0200
+++ b/src/pyams_security/profile.py	Thu Jun 02 16:18:03 2016 +0200
@@ -22,12 +22,14 @@
 from pyams_utils.interfaces.site import ISiteRoot
 from pyams_utils.interfaces.tales import ITALESExtension
 from zope.annotation.interfaces import IAnnotations, IAttributeAnnotatable
+from zope.intid.interfaces import IIntIds
 from zope.traversing.interfaces import ITraversable
 
 # import packages
 from persistent import Persistent
 from pyams_file.property import FileProperty
 from pyams_utils.adapter import adapter_config, ContextRequestAdapter
+from pyams_utils.registry import get_utility
 from pyams_utils.request import check_request, query_request
 from pyams_utils.traversing import get_parent
 from pyramid.security import Allow, ALL_PERMISSIONS, Everyone
@@ -70,7 +72,9 @@
         request = get_current_request()
         if request is not None:
             root = get_parent(request.context, ISiteRoot)
-            locate(profile, root, '++profile++')
+            intids = get_utility(IIntIds)
+            locate(profile, root)  # avoid NotYet exception
+            locate(profile, root, '++profile++{0}'.format(intids.register(profile)))
     return profile
 
 
@@ -79,7 +83,12 @@
     """++profile++ namespace traverser"""
 
     def traverse(self, name, furtherpath=None):
-        return IPublicProfile(self.request)
+        if not name:
+            return IPublicProfile(self.request.principal)
+        else:
+            intids = get_utility(IIntIds)
+            profile = intids.queryObject(int(name))
+            return IPublicProfile(profile, None)
 
 
 @adapter_config(name='public_profile', context=(Interface, Interface), provides=ITALESExtension)