cubicweb/pyramid/core.py
changeset 12043 b8d2e6b9f548
parent 12036 4c2c731f9190
child 12225 a8ed10f80a85
equal deleted inserted replaced
12042:5e64a98572de 12043:b8d2e6b9f548
    50     This behavior makes sure the actual session data is not loaded until
    50     This behavior makes sure the actual session data is not loaded until
    51     actually accessed.
    51     actually accessed.
    52     """
    52     """
    53 
    53 
    54     def __init__(self, session, *args, **kw):
    54     def __init__(self, session, *args, **kw):
    55         super(Connection, self).__init__(session, *args, **kw)
    55         super(Connection, self).__init__(session._repo, session._user, *args, **kw)
    56         self._session = session
    56         self.session = session
    57         self.lang = session._cached_lang
    57         self.lang = session._cached_lang
    58 
    58 
    59     def _get_session_data(self):
    59     def _get_session_data(self):
    60         return self._session.data
    60         return self.session.data
    61 
    61 
    62     def _set_session_data(self, data):
    62     def _set_session_data(self, data):
    63         pass
    63         pass
    64 
    64 
    65     _session_data = property(_get_session_data, _set_session_data)
    65     _session_data = property(_get_session_data, _set_session_data)
    66 
    66 
    67 
    67 
    68 class Session(cwsession.Session):
    68 class Session(object):
    69     """ A Session that access the session data through a property.
    69     """ A Session that access the session data through a property.
    70 
    70 
    71     Along with :class:`Connection`, it avoid any load of the pyramid session
    71     Along with :class:`Connection`, it avoid any load of the pyramid session
    72     data until it is actually accessed.
    72     data until it is actually accessed.
    73     """
    73     """
    74     def __init__(self, pyramid_request, user, repo):
    74     def __init__(self, pyramid_request, user, repo):
    75         super(Session, self).__init__(user, repo)
       
    76         self._pyramid_request = pyramid_request
    75         self._pyramid_request = pyramid_request
       
    76         self._user = user
       
    77         self._repo = repo
       
    78 
       
    79     @property
       
    80     def anonymous_session(self):
       
    81         # XXX for now, anonymous_user only exists in webconfig (and testconfig).
       
    82         # It will only be present inside all-in-one instance.
       
    83         # there is plan to move it down to global config.
       
    84         if not hasattr(self._repo.config, 'anonymous_user'):
       
    85             # not a web or test config, no anonymous user
       
    86             return False
       
    87         return self._user.login == self._repo.config.anonymous_user()[0]
    77 
    88 
    78     def get_data(self):
    89     def get_data(self):
    79         if not getattr(self, '_protect_data_access', False):
    90         if not getattr(self, '_protect_data_access', False):
    80             self._data_accessed = True
    91             self._data_accessed = True
    81             return self._pyramid_request.session
    92             return self._pyramid_request.session