pyramid_cubicweb/__init__.py
changeset 11586 c7a25122af4d
parent 11567 4f8aa5fcd5da
child 11601 23a62d151382
equal deleted inserted replaced
11585:7d6d4edc0ed0 11586:c7a25122af4d
    42             cp.read(fname)
    42             cp.read(fname)
    43             settings.update(cp.items('main'))
    43             settings.update(cp.items('main'))
    44             break
    44             break
    45 
    45 
    46     config = Configurator(settings=settings)
    46     config = Configurator(settings=settings)
    47     if cwconfig.debugmode:
       
    48         try:
       
    49             config.include('pyramid_debugtoolbar')
       
    50         except ImportError:
       
    51             warn('pyramid_debugtoolbar package not available, install it to '
       
    52                  'get UI debug features', RuntimeWarning)
       
    53     config.registry['cubicweb.config'] = cwconfig
    47     config.registry['cubicweb.config'] = cwconfig
    54     config.registry['cubicweb.repository'] = repo = cwconfig.repository()
    48     config.include('pyramid_cubicweb')
    55     config.registry['cubicweb.registry'] = repo.vreg
       
    56 
    49 
    57     if asbool(config.registry.settings.get('cubicweb.defaults', True)):
       
    58         config.include('pyramid_cubicweb.defaults')
       
    59 
       
    60     for name in aslist(config.registry.settings.get('cubicweb.includes', [])):
       
    61         config.include(name)
       
    62 
       
    63     config.include('pyramid_cubicweb.tools')
       
    64     config.include('pyramid_cubicweb.core')
       
    65 
       
    66     if asbool(config.registry.settings.get('cubicweb.bwcompat', True)):
       
    67         config.include('pyramid_cubicweb.bwcompat')
       
    68     return config
    50     return config
    69 
    51 
    70 
    52 
    71 def wsgi_application_from_cwconfig(
    53 def wsgi_application_from_cwconfig(
    72         cwconfig,
    54         cwconfig,
   149         debug = 'CW_DEBUG' in os.environ
   131         debug = 'CW_DEBUG' in os.environ
   150 
   132 
   151     cwconfig = cwcfg.config_for(instance_name, debugmode=debug)
   133     cwconfig = cwcfg.config_for(instance_name, debugmode=debug)
   152 
   134 
   153     return wsgi_application_from_cwconfig(cwconfig)
   135     return wsgi_application_from_cwconfig(cwconfig)
       
   136 
       
   137 
       
   138 def includeme(config):
       
   139     """Set-up a CubicWeb instance.
       
   140 
       
   141     The CubicWeb instance can be set in several ways:
       
   142 
       
   143     -   Provide an already loaded CubicWeb config instance in the registry:
       
   144 
       
   145         .. code-block:: python
       
   146 
       
   147             config.registry['cubicweb.config'] = your_config_instance
       
   148 
       
   149     -   Provide an instance name in the pyramid settings with
       
   150         :confval:`cubicweb.instance`.
       
   151 
       
   152     """
       
   153     cwconfig = config.registry.get('cubicweb.config')
       
   154 
       
   155     if cwconfig is None:
       
   156         debugmode = asbool(
       
   157             config.registry.settings.get('cubicweb.debug', False))
       
   158         cwconfig = cwcfg.config_for(
       
   159             config.registry.settings['cubicweb.instance'], debugmode=debugmode)
       
   160         config.registry['cubicweb.config'] = cwconfig
       
   161 
       
   162     if cwconfig.debugmode:
       
   163         try:
       
   164             config.include('pyramid_debugtoolbar')
       
   165         except ImportError:
       
   166             warn('pyramid_debugtoolbar package not available, install it to '
       
   167                  'get UI debug features', RuntimeWarning)
       
   168 
       
   169     config.registry['cubicweb.repository'] = repo = cwconfig.repository()
       
   170     config.registry['cubicweb.registry'] = repo.vreg
       
   171 
       
   172     if asbool(config.registry.settings.get('cubicweb.defaults', True)):
       
   173         config.include('pyramid_cubicweb.defaults')
       
   174 
       
   175     for name in aslist(config.registry.settings.get('cubicweb.includes', [])):
       
   176         config.include(name)
       
   177 
       
   178     config.include('pyramid_cubicweb.tools')
       
   179     config.include('pyramid_cubicweb.core')
       
   180 
       
   181     if asbool(config.registry.settings.get('cubicweb.bwcompat', True)):
       
   182         config.include('pyramid_cubicweb.bwcompat')