def sql_app(global_conf, name, url, zcml_file=None, **kwargs): """A factory used to bootstrap the TrajectApplication. As the TrajectApplication will use SQL, we use this 'once and for all' kind of factory to configure the SQL connection and inject the demo datas. """ # We register our SQLengine under a given name if zcml_file: load_zcml(zcml_file) engine = create_and_register_engine(url, name) # We bind out SQLAlchemy definition to the engine engine.bind(Library) # We now instanciate the TrajectApplication # The name and engine are passed, to be used for the querying. app = TrajectApplication(name, engine) # We register our Traject patterns. # As we have 2 models, we register 2 resolvers. #PATTERNS.register(Site, author_req, author_resolve(name)) #PATTERNS.register(Site, book_req, book_resolve(name)) # To finish the initialization process, we inject # some test data, to start with something concrete. try: with transaction.manager: with SQLAlchemySession(engine): Library.metadata.create_all() #inject_data(app) except IntegrityError: # data already exists, skipping. pass return app
def admin(global_conf, dburl, dbkey, pkey, session_key, layer=None, **kwargs): engine = create_and_register_engine(dburl, dbkey) engine.bind(Admin) Admin.metadata.create_all() root = AdminRoot(pkey, dbkey) publisher = DawnlightPublisher(view_lookup=view_lookup) @cooper.basicauth(users=admins, realm=REALM) def app(environ, start_response): session = environ[session_key].session setSession(session) setLanguage('de') request = Request(environ) alsoProvides(request, IBootstrapRequest) if layer: skin_layer = eval_loader(layer) alsoProvides(request, skin_layer) with Interaction(): with transaction.manager as tm: with SQLAlchemySession(engine, transaction_manager=tm): response = publisher.publish( request, root, handle_errors=True) result = response(environ, start_response) setSession() return result return app
def app_factory(global_conf, url, zcml, langs): # load the ZCML load_zcml(zcml) # register the allowed languages register_allowed_languages([lang.strip() for lang in langs.split(',')]) # create, register and populate the base DB/Engine engine = create_and_register_engine(url, DB_KEY) engine.bind(Base) Base.metadata.create_all() return Application(engine)