Exemplo n.º 1
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
    cache.configure_from_config(settings, 'dogpile.cache.')
    authn_policy = AuthTktAuthenticationPolicy(settings['auth_secret'],
                                               hashalg='sha512',
                                               callback=userfinder)
    authz_policy = ACLAuthorizationPolicy()
    config = Configurator(settings=settings,
                          root_factory='miniblog.models.RootFactory',
                          session_factory=get_session,
                          )
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('home_paged', '/page/{page}')
    config.add_route('add_entry', '/add')
    config.add_route('manage_categories', '/edit_categories')
    config.add_route('delete_category', '/categories/delete/{name_}')
    config.add_route('view_entry', '/entry/{id_}')
    config.add_route('delete_entry', '/entry/{id_}/delete')
    config.add_route('edit_entry', '/entry/{id_}/edit')
    config.add_route('view_category', '/category/{id_}')
    config.add_route('view_categories', '/categories')
    config.add_route('about', '/about')
    config.add_route('search', '/search')
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.scan()
    return config.make_wsgi_app()
Exemplo n.º 2
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
Exemplo n.º 3
0
 def setUp(self):
     self.config = testing.setUp()
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from miniblog.models import Category, Base, DBSession, cache
     from tempfile import mktemp
     try:
         cache.configure_from_config({'cache.backend': 'dogpile.cache.dbm',
                      'cache.arguments.filename': mktemp()},
                     'cache.')
     except Exception:
         pass
     DBSession.configure(bind=engine)
     Base.metadata.create_all(engine)
     with transaction.manager:
         for i in range(3):
             category = Category('Category {0}'.format(i))
             DBSession.add(category)