pyramid_cubicweb/bwcompat.py
changeset 11496 500615e26063
parent 11492 b0b8942cdb80
child 11499 60a504740951
equal deleted inserted replaced
11495:f936708c6ea2 11496:500615e26063
     1 from pyramid import security
     1 from pyramid import security
       
     2 from pyramid import tweens
     2 from pyramid.httpexceptions import HTTPSeeOther
     3 from pyramid.httpexceptions import HTTPSeeOther
     3 from pyramid import httpexceptions
     4 from pyramid import httpexceptions
     4 
     5 
     5 import cubicweb
     6 import cubicweb
     6 import cubicweb.web
     7 import cubicweb.web
   103         # XXX I don't think it makes sens to catch this ex here (cdevienne)
   104         # XXX I don't think it makes sens to catch this ex here (cdevienne)
   104 
   105 
   105         return request.response
   106         return request.response
   106 
   107 
   107 
   108 
       
   109 class TweenHandler(object):
       
   110     def __init__(self, handler, registry):
       
   111         self.handler = handler
       
   112         self.cwhandler = registry['cubicweb.handler']
       
   113 
       
   114     def __call__(self, request):
       
   115         try:
       
   116             response = self.handler(request)
       
   117         except httpexceptions.HTTPNotFound:
       
   118             response = self.cwhandler(request)
       
   119         return response
       
   120 
       
   121 
   108 def includeme(config):
   122 def includeme(config):
   109     # Set up a defaut route to handle non-catched urls.
   123     # Set up a tween app that will handle the request if the main application
       
   124     # raises a HTTPNotFound exception.
   110     # This is to keep legacy compatibility for cubes that makes use of the
   125     # This is to keep legacy compatibility for cubes that makes use of the
   111     # cubicweb controllers.
   126     # cubicweb controllers.
   112     cwconfig = config.registry['cubicweb.config']
   127     cwconfig = config.registry['cubicweb.config']
   113     repository = config.registry['cubicweb.repository']
   128     repository = config.registry['cubicweb.repository']
   114     cwappli = CubicWebPublisher(
   129     cwappli = CubicWebPublisher(
   115         repository, cwconfig,
   130         repository, cwconfig,
   116         session_handler_fact=PyramidSessionHandler)
   131         session_handler_fact=PyramidSessionHandler)
   117     handler = CubicWebPyramidHandler(cwappli)
   132     cwhandler = CubicWebPyramidHandler(cwappli)
   118 
   133 
   119     config.registry['cubicweb.appli'] = cwappli
   134     config.registry['cubicweb.appli'] = cwappli
   120     config.registry['cubicweb.handler'] = handler
   135     config.registry['cubicweb.handler'] = cwhandler
   121 
   136 
   122     config.add_route('catchall', pattern='*path')
   137     config.add_tween(
   123     config.add_view(handler, route_name='catchall')
   138         'pyramid_cubicweb.bwcompat.TweenHandler', under=tweens.EXCVIEW)