new set_session_props method exposed by the repository, use it to be sure session language is in sync the request language
--- a/dbapi.py Thu Jul 02 12:59:16 2009 +0200
+++ b/dbapi.py Thu Jul 02 13:00:20 2009 +0200
@@ -245,7 +245,7 @@
@property
def user(self):
if self._user is None and self.cnx:
- self.set_user(self.cnx.user(self))
+ self.set_user(self.cnx.user(self, {'lang': self.lang}))
return self._user
def set_user(self, user):
@@ -367,6 +367,10 @@
"""raise `BadSessionId` if the connection is no more valid"""
self._repo.check_session(self.sessionid)
+ def set_session_props(self, **props):
+ """raise `BadSessionId` if the connection is no more valid"""
+ self._repo.set_session_props(self.sessionid, props)
+
def get_shared_data(self, key, default=None, pop=False):
"""return value associated to `key` in shared data"""
return self._repo.get_shared_data(self.sessionid, key, default, pop)
@@ -434,7 +438,8 @@
def user(self, req=None, props=None):
"""return the User object associated to this connection"""
# cnx validity is checked by the call to .user_info
- eid, login, groups, properties = self._repo.user_info(self.sessionid, props)
+ eid, login, groups, properties = self._repo.user_info(self.sessionid,
+ props)
if req is None:
req = self.request()
rset = req.eid_rset(eid, 'CWUser')
--- a/server/repository.py Thu Jul 02 12:59:16 2009 +0200
+++ b/server/repository.py Thu Jul 02 13:00:20 2009 +0200
@@ -664,13 +664,22 @@
custom properties)
"""
session = self._get_session(sessionid, setpool=False)
- if props:
- # update session properties
- for prop, value in props.items():
- session.change_property(prop, value)
+ if props is not None:
+ self.set_session_props(sessionid, props)
user = session.user
return user.eid, user.login, user.groups, user.properties
+ def set_session_props(self, sessionid, props):
+ """this method should be used by client to:
+ * check session id validity
+ * update user information on each user's request (i.e. groups and
+ custom properties)
+ """
+ session = self._get_session(sessionid, setpool=False)
+ # update session properties
+ for prop, value in props.items():
+ session.change_property(prop, value)
+
# public (inter-repository) interface #####################################
def entities_modified_since(self, etypes, mtime):
--- a/web/request.py Thu Jul 02 12:59:16 2009 +0200
+++ b/web/request.py Thu Jul 02 13:00:20 2009 +0200
@@ -91,7 +91,7 @@
or an anonymous connection is open
"""
super(CubicWebRequestBase, self).set_connection(cnx, user)
- # get request language:
+ # set request language
vreg = self.vreg
if self.user:
try:
@@ -114,6 +114,7 @@
def set_language(self, lang):
self._ = self.__ = self.translations[lang]
self.lang = lang
+ self.cnx.set_session_props(lang=lang)
self.debug('request language: %s', lang)
# input form parameters management ########################################
@@ -336,7 +337,6 @@
params[name] = value
params['eid'] = eid
if len(params) < minparams:
- print eid, params
raise RequestError(self._('missing parameters for entity %s') % eid)
return params