def _get_storage(self): settings = self.config.registry.settings storage = get_storage_factory(settings)() trxn = transaction.begin() trxn.join(storage) return storage
def main(global_config, **settings): """Constructs a WSGI application.""" settings['paste_config'] = global_config ### Settings # Set up SQLAlchemy stuff engine = engine_from_config(settings, 'sqlalchemy.') floof.model.initialize(engine, extension=ZopeTransactionExtension()) # floof debug panel settings['debug'] = asbool(settings.get('floof.debug', False)) # Misc other crap settings['rating_radius'] = int(settings['rating_radius']) settings['filestore_factory'] = filestore.get_storage_factory(settings) ### Configuratify # Session factory needs to subclass our mixin above. Beaker's # verbosely-named function just returns a class, so do some MI FloofSessionFactory = type( 'FloofSessionFactory', (_RichSessionFlashMixin, session_factory_from_settings(settings)), {}) config = Configurator( settings=settings, root_factory=FloofRoot, request_factory=FloofRequest, session_factory=FloofSessionFactory, authentication_policy=FloofAuthnPolicy(), authorization_policy=ACLAuthorizationPolicy(), ) # PySCSS support config.include('pyramid_scss') config.add_route('pyscss', '/css/{css_path:[^/]+}.css') config.add_view(route_name='pyscss', view='pyramid_scss.controller.get_scss', renderer='scss', request_method='GET') # Added manually because @subscriber only works with a # scan, and we don't want to scan ourselves config.add_subscriber(prevent_csrf, NewRequest) config.add_subscriber(manage_stashes, NewRequest) config.add_subscriber(auto_privilege_escalation, ContextFound) config.add_subscriber(add_renderer_globals, BeforeRender) floof.routing.configure_routing(config) config.scan(floof.views) if not settings['debug']: from floof.views.errors import error500 config.add_view(error500, context=Exception) app = config.make_wsgi_app() app = HTTPOnlyCookieMiddleware(app) return app
def main(global_config, **settings): """Constructs a WSGI application.""" settings['paste_config'] = global_config ### Settings # Set up SQLAlchemy stuff engine = engine_from_config(settings, 'sqlalchemy.') floof.model.initialize( engine, extension=ZopeTransactionExtension()) # floof debug panel settings['debug'] = asbool(settings.get('floof.debug', False)) # Misc other crap settings['rating_radius'] = int(settings['rating_radius']) settings['filestore_factory'] = filestore.get_storage_factory(settings) ### Configuratify # Session factory needs to subclass our mixin above. Beaker's # verbosely-named function just returns a class, so do some MI FloofSessionFactory = type('FloofSessionFactory', (_RichSessionFlashMixin, session_factory_from_settings(settings)), {}) config = Configurator( settings=settings, root_factory=FloofRoot, request_factory=FloofRequest, session_factory=FloofSessionFactory, authentication_policy=FloofAuthnPolicy(), authorization_policy=ACLAuthorizationPolicy(), ) # PySCSS support config.include('pyramid_scss') config.add_route('pyscss', '/css/{css_path:[^/]+}.css') config.add_view(route_name='pyscss', view='pyramid_scss.controller.get_scss', renderer='scss', request_method='GET') # Added manually because @subscriber only works with a # scan, and we don't want to scan ourselves config.add_subscriber(prevent_csrf, NewRequest) config.add_subscriber(manage_stashes, NewRequest) config.add_subscriber(auto_privilege_escalation, ContextFound) config.add_subscriber(add_renderer_globals, BeforeRender) floof.routing.configure_routing(config) config.scan(floof.views) if not settings['debug']: from floof.views.errors import error500 config.add_view(error500, context=Exception) app = config.make_wsgi_app() app = HTTPOnlyCookieMiddleware(app) return app
def test_get_factory(self): tempdir = tempfile.gettempdir() settings = {'filestore.directory': tempdir} with pytest.raises(ImportError): settings['filestore'] = 'floof.model.filestore.ocal.FileStorage' get_storage_factory(settings) settings['filestore'] = 'foo' get_storage_factory(settings) settings['filestore'] = 'floof.model.filestore.local.FileStorage' get_storage_factory(settings) settings['filestore'] = 'local' get_storage_factory(settings)
def _get_storage(self): settings = { 'filestore': 'local', 'filestore.directory': self.directory } storage = get_storage_factory(settings)() assert hasattr(storage, 'put') assert hasattr(storage, 'url') trxn = transaction.begin() trxn.join(storage) return storage
def main(global_config, **settings): """Constructs a WSGI application.""" settings['paste_config'] = global_config # Compile stylesheets with Sass # This env var is only set from a convenient dev-mode launcher script # XXX uh this could just be in the .ini if 'FLOOF_SKIP_SASS_COMPILATION' not in os.environ: # XXX consult pyramid for the location? compile_sass(global_config['here'] + '/floof') ### Settings # Set up SQLAlchemy stuff engine = engine_from_config(settings, 'sqlalchemy.') floof.model.initialize( engine, extension=ZopeTransactionExtension()) # floof debug panel settings['super_debug'] = asbool(settings.get('super_debug', False)) # Listeners to record query time, et al. # XXX disable this normally; nobody cares about these stats but devs. just # show the stats to devs and make the debug thing optional. (can these # listeners even be enabled per-request? if not, should we log the stats?) floof.lib.debugging.attach_sqlalchemy_listeners(engine, settings['super_debug']) # Misc other crap settings['rating_radius'] = int(settings['rating_radius']) settings['filestore_factory'] = filestore.get_storage_factory(settings) ### Configuratify # Session factory needs to subclass our mixin above. Beaker's # verbosely-named function just returns a class, so do some MI FloofSessionFactory = type('FloofSessionFactory', (_RichSessionFlashMixin, session_factory_from_settings(settings)), {}) config = Configurator( settings=settings, root_factory=FloofRoot, request_factory=FloofRequest, session_factory=FloofSessionFactory, authentication_policy=FloofAuthnPolicy(), authorization_policy=ACLAuthorizationPolicy(), ) # Added manually because @subscriber only works with a # scan, and we don't want to scan ourselves config.add_subscriber(prevent_csrf, NewRequest) config.add_subscriber(manage_stashes, NewRequest) config.add_subscriber(auto_privilege_escalation, ContextFound) config.add_subscriber(start_template_timer, BeforeRender) config.add_subscriber(add_renderer_globals, BeforeRender) config.add_subscriber(flush_everything, NewResponse) config.add_subscriber(log_timers, NewResponse) floof.routing.configure_routing(config) config.scan(floof.views) app = config.make_wsgi_app() app = HTTPOnlyCookieMiddleware(app) return app