[web session] proper reloading of the session manager on vreg update
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 05 Aug 2009 18:56:22 +0200
changeset 2706 09baf5175196
parent 2705 30bcdbd92820
child 2707 15ffc3c8923c
[web session] proper reloading of the session manager on vreg update
web/application.py
web/views/sessions.py
--- a/web/application.py	Wed Aug 05 18:18:12 2009 +0200
+++ b/web/application.py	Wed Aug 05 18:56:22 2009 +0200
@@ -116,11 +116,20 @@
     SESSION_VAR = '__session'
 
     def __init__(self, appli):
-        self.session_manager = appli.vreg['components'].select('sessionmanager')
+        self.vreg = appli.vreg
+        self.session_manager = self.vreg['components'].select('sessionmanager')
         global SESSION_MANAGER
         SESSION_MANAGER = self.session_manager
-        if not 'last_login_time' in appli.vreg.schema:
+        if not 'last_login_time' in self.vreg.schema:
             self._update_last_login_time = lambda x: None
+        CW_EVENT_MANAGER.bind('after-registry-reload', self.reset_session_manager)
+
+    def reset_session_manager(self):
+        data = self.session_manager.dump_data()
+        self.session_manager = self.vreg['components'].select('sessionmanager')
+        self.session_manager.restore_data(data)
+        global SESSION_MANAGER
+        SESSION_MANAGER = self.session_manager
 
     def clean_sessions(self):
         """cleanup sessions which has not been unused since a given amount of
--- a/web/views/sessions.py	Wed Aug 05 18:18:12 2009 +0200
+++ b/web/views/sessions.py	Wed Aug 05 18:56:22 2009 +0200
@@ -22,6 +22,11 @@
         #assert isinstance(self.authmanager, RepositoryAuthenticationManager)
         self._sessions = {}
 
+    def dump_data(self):
+        return self._sessions
+    def restore_data(self, data):
+        self._sessions = data
+
     def current_sessions(self):
         return self._sessions.values()