Add a make_cubicweb_application function
authorChristophe de Vienne <christophe@unlish.com>
Thu, 21 Aug 2014 21:55:58 +0200
changeset 11501 fcf7f99fad4a
parent 11500 8e4935a1848b
child 11502 e4682c567e86
Add a make_cubicweb_application function This function will be used by the 'pyramid' cubicweb-ctl command. Related to #4291173
pyramid_cubicweb/__init__.py
--- a/pyramid_cubicweb/__init__.py	Thu Aug 21 22:26:42 2014 +0200
+++ b/pyramid_cubicweb/__init__.py	Thu Aug 21 21:55:58 2014 +0200
@@ -0,0 +1,28 @@
+from pyramid.config import Configurator
+
+
+def make_cubicweb_application(cwconfig):
+    """
+    Create a pyramid-based CubicWeb instance from a cubicweb configuration.
+
+    It is initialy meant to be used by the 'pyramid' command of cubicweb-ctl.
+    """
+    settings = {
+        'session.secret': '11',  # XXX
+    }
+    if cwconfig.debugmode:
+        settings.update({
+            'pyramid.debug_authorization': True,
+            'pyramid.debug_notfound': True,
+            'pyramid.debug_routematch': True,
+        })
+    config = Configurator(settings=settings)
+    if cwconfig.debugmode:
+        config.include('pyramid_debugtoolbar')
+    config.registry['cubicweb.config'] = cwconfig
+    config.registry['cubicweb.repository'] = repo = cwconfig.repository()
+    config.registry['cubicweb.registry'] = repo.vreg
+    config.include('pyramid_cubicweb.defaults')
+    config.include('pyramid_cubicweb.core')
+    config.include('pyramid_cubicweb.bwcompat')
+    return config