Beispiel #1
0
def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    Session.configure(bind=engine)
    Base.metadata.create_all(engine)
Beispiel #2
0
def request_db(request):
    db = Session()

    @request.add_finished_callback
    def close_db(request):
        db.close()

    return db
Beispiel #3
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, "sqlalchemy.")
    Session.configure(bind=engine)
    Base.metadata.bind = engine
    config = Configurator(
        settings=settings,
        authentication_policy=LogCabinAuthenticationPolicy(callback=authentication_callback),
        authorization_policy=ACLAuthorizationPolicy(),
        default_permission="view",
        root_factory=LogCabinRootFactory,
    )
    config.include("pyramid_mako")

    config.add_request_method(request_db, 'db', reify=True)
    config.add_request_method(request_user, 'user', reify=True)

    config.include("logcabin.lib.formats")

    config.add_static_view("static", "static", cache_max_age=3600)

    config.add_route("home", "/")

    config.add_route("account.register", "/account/register")
    config.add_route("account.log_in", "/account/log_in")
    config.add_route("account.log_out", "/account/log_out")
    config.add_route("account.forgot_password", "/account/forgot_password")
    config.add_route("account.reset_password", "/account/reset_password")
    config.add_route("account.verify_email", "/account/verify_email")
    config.add_route("account.settings", "/account/settings")
    config.add_route("account.change_password", "/account/change_password")
    config.add_route("account.change_email", "/account/change_email")
    config.add_route("account.tumblr", "/account/tumblr")
    config.add_route("account.tumblr.callback", "/account/tumblr/callback")

    config.add_route("users.profile", "/users/{username}", factory=get_user)
    config.add_ext_route("users.logs", "/users/{username}/logs", factory=get_user)
    config.add_ext_route("users.favorites", "/users/{username}/favorites", factory=get_user)
    config.add_ext_route("users.subscriptions", "/users/{username}/subscriptions", factory=get_user)

    config.add_ext_route("logs.new", "/logs/new")
    config.add_ext_route("logs.log", "/logs/{log_id:\d+}", factory=get_log)
    config.add_ext_route("logs.chapters", "/logs/{log_id:\d+}/chapters", factory=get_log)
    config.add_ext_route("logs.chapter", "/logs/{log_id:\d+}/chapters/{number:\d+}", factory=get_chapter)
    config.add_ext_route("logs.chapter.message", "/logs/{log_id:\d+}/chapters/{number:\d+}/messages/{message_id:\d+}", factory=get_chapter)
    config.add_ext_route("logs.favorite", "/logs/{log_id:\d+}/favorite", factory=get_log)
    config.add_ext_route("logs.unfavorite", "/logs/{log_id:\d+}/unfavorite", factory=get_log)

    """
    config.add_ext_route("upload", "/upload")
    config.add_ext_route("upload.cherubplay", "/upload/cherubplay/{username}/{url}")
    config.add_ext_route("upload.msparp", "/upload/msparp/{username}/{url}")
    """

    config.add_ext_route("fandoms.categories", "/fandoms")
    config.add_ext_route("fandoms.category", "/fandoms/{category_url_name}", factory=get_fandom_category)
    config.add_ext_route("fandoms.fandom", "/fandoms/{category_url_name}/{fandom_url_name}", factory=get_fandom)

    config.scan()
    return config.make_wsgi_app()
Beispiel #4
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, "sqlalchemy.")
    Session.configure(bind=engine)
    Base.metadata.bind = engine
    config = Configurator(
        settings=settings,
        authentication_policy=LogCabinAuthenticationPolicy(
            callback=authentication_callback),
        authorization_policy=ACLAuthorizationPolicy(),
        default_permission="view",
        root_factory=LogCabinRootFactory,
    )
    config.include("pyramid_mako")

    config.add_request_method(request_db, 'db', reify=True)
    config.add_request_method(request_user, 'user', reify=True)

    config.include("logcabin.lib.formats")

    config.add_static_view("static", "static", cache_max_age=3600)

    config.add_route("home", "/")

    config.add_route("account.register", "/account/register")
    config.add_route("account.log_in", "/account/log_in")
    config.add_route("account.log_out", "/account/log_out")
    config.add_route("account.forgot_password", "/account/forgot_password")
    config.add_route("account.reset_password", "/account/reset_password")
    config.add_route("account.verify_email", "/account/verify_email")
    config.add_route("account.settings", "/account/settings")
    config.add_route("account.change_password", "/account/change_password")
    config.add_route("account.change_email", "/account/change_email")
    config.add_route("account.tumblr", "/account/tumblr")
    config.add_route("account.tumblr.callback", "/account/tumblr/callback")

    config.add_route("users.profile", "/users/{username}", factory=get_user)
    config.add_ext_route("users.logs",
                         "/users/{username}/logs",
                         factory=get_user)
    config.add_ext_route("users.favorites",
                         "/users/{username}/favorites",
                         factory=get_user)
    config.add_ext_route("users.subscriptions",
                         "/users/{username}/subscriptions",
                         factory=get_user)

    config.add_ext_route("logs.new", "/logs/new")
    config.add_ext_route("logs.log", "/logs/{log_id:\d+}", factory=get_log)
    config.add_ext_route("logs.chapters",
                         "/logs/{log_id:\d+}/chapters",
                         factory=get_log)
    config.add_ext_route("logs.chapter",
                         "/logs/{log_id:\d+}/chapters/{number:\d+}",
                         factory=get_chapter)
    config.add_ext_route(
        "logs.chapter.message",
        "/logs/{log_id:\d+}/chapters/{number:\d+}/messages/{message_id:\d+}",
        factory=get_chapter)
    config.add_ext_route("logs.favorite",
                         "/logs/{log_id:\d+}/favorite",
                         factory=get_log)
    config.add_ext_route("logs.unfavorite",
                         "/logs/{log_id:\d+}/unfavorite",
                         factory=get_log)
    """
    config.add_ext_route("upload", "/upload")
    config.add_ext_route("upload.cherubplay", "/upload/cherubplay/{username}/{url}")
    config.add_ext_route("upload.msparp", "/upload/msparp/{username}/{url}")
    """

    config.add_ext_route("fandoms.categories", "/fandoms")
    config.add_ext_route("fandoms.category",
                         "/fandoms/{category_url_name}",
                         factory=get_fandom_category)
    config.add_ext_route("fandoms.fandom",
                         "/fandoms/{category_url_name}/{fandom_url_name}",
                         factory=get_fandom)

    config.scan()
    return config.make_wsgi_app()