Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: develop
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 53 lines (38 sloc) 1.678 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
from os.path import abspath
from os.path import dirname

from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.config import Configurator
from pyramid.renderers import JSONP

from bookie.lib.access import RequestWithUserAttribute
from bookie.models import initialize_sql
from bookie.models.auth import UserMgr
from bookie.routes import build_routes

from pyramid.security import Allow
from pyramid.security import Everyone
from pyramid.security import ALL_PERMISSIONS


class RootFactory(object):
    __acl__ = [(Allow, Everyone, ALL_PERMISSIONS)]

    def __init__(self, request):
        if request.matchdict:
            self.__dict__.update(request.matchdict)


def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
"""

    # Update the settings with the current app root path
    settings['app_root'] = abspath(dirname(dirname(__file__)))

    initialize_sql(settings)

    authn_policy = AuthTktAuthenticationPolicy(
        settings.get('auth.secret'),
        callback=UserMgr.auth_groupfinder)
    authz_policy = ACLAuthorizationPolicy()

    config = Configurator(settings=settings,
                          root_factory='bookie.RootFactory',
                          authentication_policy=authn_policy,
                          authorization_policy=authz_policy)
    config.set_request_factory(RequestWithUserAttribute)

    config = build_routes(config)
    config.add_static_view('static', 'bookie:static')
    config.add_renderer('jsonp', JSONP(param_name='callback'))
    config.scan('bookie.views')

    return config.make_wsgi_app()
Something went wrong with that request. Please try again.