pyramid_cubicweb/bwcompat.py
changeset 11537 caf268942436
parent 11511 13e0f569684c
child 11539 ff581d66f682
equal deleted inserted replaced
11536:6618408c0629 11537:caf268942436
    13 from pyramid_cubicweb.core import cw_to_pyramid
    13 from pyramid_cubicweb.core import cw_to_pyramid
    14 
    14 
    15 
    15 
    16 class PyramidSessionHandler(object):
    16 class PyramidSessionHandler(object):
    17     """A CW Session handler that rely on the pyramid API to fetch the needed
    17     """A CW Session handler that rely on the pyramid API to fetch the needed
    18     informations"""
    18     informations.
       
    19 
       
    20     It implements the :class:`cubicweb.web.application.CookieSessionHandler`
       
    21     API.
       
    22     """
    19 
    23 
    20     def __init__(self, appli):
    24     def __init__(self, appli):
    21         self.appli = appli
    25         self.appli = appli
    22 
    26 
    23     def get_session(self, req):
    27     def get_session(self, req):
    26     def logout(self, req, goto_url):
    30     def logout(self, req, goto_url):
    27         raise LogOut(url=goto_url)
    31         raise LogOut(url=goto_url)
    28 
    32 
    29 
    33 
    30 class CubicWebPyramidHandler(object):
    34 class CubicWebPyramidHandler(object):
       
    35     """ A Pyramid request handler that rely on a cubicweb instance to do the
       
    36     whole job
       
    37 
       
    38     :param appli: A CubicWeb 'Application' object.
       
    39     """
    31     def __init__(self, appli):
    40     def __init__(self, appli):
    32         self.appli = appli
    41         self.appli = appli
    33 
    42 
    34     def __call__(self, request):
    43     def __call__(self, request):
    35         """
    44         """
   105 
   114 
   106         return request.response
   115         return request.response
   107 
   116 
   108 
   117 
   109 class TweenHandler(object):
   118 class TweenHandler(object):
       
   119     """ A Pyramid tween handler that submit unhandled requests to a Cubicweb
       
   120     handler.
       
   121 
       
   122     The CubicWeb handler to use is expected to be in the pyramid registry, at
       
   123     key ``'cubicweb.handler'``.
       
   124     """
   110     def __init__(self, handler, registry):
   125     def __init__(self, handler, registry):
   111         self.handler = handler
   126         self.handler = handler
   112         self.cwhandler = registry['cubicweb.handler']
   127         self.cwhandler = registry['cubicweb.handler']
   113 
   128 
   114     def __call__(self, request):
   129     def __call__(self, request):
   122             response = self.cwhandler(request)
   137             response = self.cwhandler(request)
   123         return response
   138         return response
   124 
   139 
   125 
   140 
   126 def includeme(config):
   141 def includeme(config):
   127     # Set up a tween app that will handle the request if the main application
   142     """ Set up a tween app that will handle the request if the main application
   128     # raises a HTTPNotFound exception.
   143     raises a HTTPNotFound exception.
   129     # This is to keep legacy compatibility for cubes that makes use of the
   144 
   130     # cubicweb controllers.
   145     This is to keep legacy compatibility for cubes that makes use of the
       
   146     cubicweb urlresolvers.
       
   147 
       
   148     It provides, for now, support for cubicweb controllers, but this feature
       
   149     will be reimplemented separatly in a less compatible way.
       
   150 
       
   151     It is automatically included by the configuration system, but can be
       
   152     disabled in the :ref:`pyramid_settings`:
       
   153 
       
   154     .. code-block:: ini
       
   155 
       
   156         cubicweb.bwcompat = no
       
   157     """
   131     cwconfig = config.registry['cubicweb.config']
   158     cwconfig = config.registry['cubicweb.config']
   132     repository = config.registry['cubicweb.repository']
   159     repository = config.registry['cubicweb.repository']
   133     cwappli = CubicWebPublisher(
   160     cwappli = CubicWebPublisher(
   134         repository, cwconfig,
   161         repository, cwconfig,
   135         session_handler_fact=PyramidSessionHandler)
   162         session_handler_fact=PyramidSessionHandler)