summaryrefslogtreecommitdiffstats
path: root/idp/extra/modules/store.py
diff options
context:
space:
mode:
Diffstat (limited to 'idp/extra/modules/store.py')
-rw-r--r--idp/extra/modules/store.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/idp/extra/modules/store.py b/idp/extra/modules/store.py
index 1adac77..c2dc654 100644
--- a/idp/extra/modules/store.py
+++ b/idp/extra/modules/store.py
@@ -152,10 +152,7 @@ class MiniIdentityPratic(StorableObject):
return directory.get_collectivity(collectivity_ou)
def get_attributes(self):
- store = directory.get_store()
- ldap_conn = ldap.initialize(store.pratic_ldap_url)
- record = ldap_conn.search_s(self.id, ldap.SCOPE_BASE)[0]
- agent = directory.Agent(record)
+ agent = self.get_as_agent()
attributes = {}
for k in ('username', 'cn', 'mail'):
v = getattr(agent, k)
@@ -171,5 +168,28 @@ class MiniIdentityPratic(StorableObject):
return attributes
attributes = property(get_attributes)
+ _agent = None
+ def get_as_agent(self):
+ if self._agent:
+ return self._agent
+ store = directory.get_store()
+ ldap_conn = ldap.initialize(store.pratic_ldap_url)
+ record = ldap_conn.search_s(self.id, ldap.SCOPE_BASE)[0]
+ print 'record:', record
+ self._agent = directory.Agent(record)
+ return self._agent
+
+ # don't pickle _agent cache
+ def __getstate__(self):
+ odict = self.__dict__
+ if odict.has_key('_agent'):
+ del odict['_agent']
+ return odict
+
+ def __setstate__(self, dict):
+ self.__dict__ = dict
+ self._agent = None
+
+
identities.stores['pratic'] = IdentitiesStorePratic