当前位置: 首页>>代码示例>>Python>>正文


Python Configurator.add_forbidden_view方法代码示例

本文整理汇总了Python中pyramid.config.Configurator.add_forbidden_view方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_forbidden_view方法的具体用法?Python Configurator.add_forbidden_view怎么用?Python Configurator.add_forbidden_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.config.Configurator的用法示例。


在下文中一共展示了Configurator.add_forbidden_view方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]
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
    authn_policy = AuthTktAuthenticationPolicy('sosecret')
    authz_policy = ACLAuthorizationPolicy()
    config = Configurator(
        settings=settings,
        root_factory=Root,
    )
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    config.set_default_permission('view')
    config.add_forbidden_view(view=logout)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_request_method(get_user, 'user', reify=True)
    config.add_route('home', '/')
    config.add_route('search_result', '/search_result')
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.add_route('register', '/register')
    config.add_route('history', '/history')
    config.add_route('history_refresh', '/history_refresh')
    config.add_route('top', '/top')
    config.scan()
    return config.make_wsgi_app()
开发者ID:dawidkostyszak,项目名称:PyramidAplication_6,代码行数:30,代码来源:__init__.py

示例2: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]
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
    authentication = AuthTktAuthenticationPolicy('secretstring')
    authorization = ACLAuthorizationPolicy()
    config = Configurator(
        settings=settings,
        request_factory=MyRequest,
        root_factory=RootFactory
    )
    config.set_default_permission('view')
    config.set_authentication_policy(authentication)
    config.set_authorization_policy(authorization)
    config.add_forbidden_view(view=logout_view)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('result', '/result')
    config.add_route('register', '/register')
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.add_route('history', '/history')
    config.add_route('history_popular', '/history_popular')
    config.scan()
    return config.make_wsgi_app()
开发者ID:krotkiewicz,项目名称:PyramidMako,代码行数:29,代码来源:__init__.py

示例3: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    config = Configurator(
                root_factory=Root,
                settings=settings,
                authentication_policy=FamosoAuthenticationPolicy(),
                authorization_policy=ACLAuthorizationPolicy(),
    )

    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)

    config.set_request_property(get_user, 'user', reify=True)

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

    add_routes(config)

    config.scan('famoso_reports.views')

    config.add_forbidden_view(forbidden)

    return config.make_wsgi_app()
开发者ID:robottaway,项目名称:Famoso-Reports,代码行数:28,代码来源:__init__.py

示例4: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    authentication_policy = AuthenticationPolicy(
        settings['auth.secret'], cookie_name='shike.im')
    authorization_policy = ACLAuthorizationPolicy() 
    config = Configurator(settings=settings)
    config.set_root_factory('hzsxactivitymanagesite.resources.RootFactory')
    config.set_authentication_policy(authentication_policy)
    config.set_authorization_policy(authorization_policy)
    
    jsonp = JSONP(param_name='callback')
    jsonp.add_adapter(ObjectId, objectid_adapter)
    jsonp.add_adapter(DBRef, dbref_adapter)
    jsonp.add_adapter(datetime.datetime, datetime_adapter)
    config.add_renderer('jsonp', jsonp)
    config.add_subscriber(real_ip_hook, NewRequest)
    config.set_request_property(get_db, "db", reify=True)
    config.set_request_property(get_fs, "fs", reify=True)
    config.set_request_property(get_user, "user", reify=True)
    
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.include("hzsxactivitymanagesite.views.home")
    config.add_forbidden_view("hzsxactivitymanagesite.views.forbidden_view",  renderer="json")
    config.add_notfound_view("hzsxactivitymanagesite.views.notfound_view", renderer="json")
    config.add_view("hzsxactivitymanagesite.views.apierror_view", context='hzsxactivitymanagesite.exceptions.APIError', renderer='json')
    config.add_view("hzsxactivitymanagesite.views.pageerror_view", context='hzsxactivitymanagesite.exceptions.PageError', renderer='error.mako')
    return config.make_wsgi_app()
开发者ID:Jonekee,项目名称:bigscreen,代码行数:30,代码来源:__init__.py

示例5: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]
def main():
    """Construct and return a WSGI app for the luckynumber service."""

    settings = {
        # The pyramid_persona plugin needs a master secret to use for
        # signing login cookies, and the expected hostname of your website
        # to prevent fradulent login attempts.
        "persona.secret": "TED KOPPEL IS A ROBOT",
        "persona.audiences": "localhost:8080",
        # The pyramid_macauth plugin needs a master secret to use for signing
        # its access tokens.  We could use the same secret as above, but it's
        # generally a good idea to use different secrets for different things.
        "macauth.master_secret": "V8 JUICE IS 1/8TH GASOLINE",
        # The pyramid_multiauth plugin needs to be told what sub-policies to
        # load, and the order in which they should be tried.
        "multiauth.policies": "pyramid_persona pyramid_macauth",
    }

    config = Configurator(settings=settings)
    config.add_route("number", "/")
    config.add_view(lucky_number, route_name="number")

    # Including pyramid_multiauth magically enables authentication, loading
    # both of the policies we specified in the settings.
    config.include("pyramid_multiauth")

    # Both of our chosen policies configure a "forbidden view" to handle
    # unauthenticated access.  We have to resolve this conflict by explicitly
    # picking which one we want to use.
    config.add_forbidden_view("pyramid_persona.views.forbidden")

    config.add_route("provision", "/provision")
    config.add_view(provision_creds, route_name="provision", renderer="json")

    return config.make_wsgi_app()
开发者ID:seattle,项目名称:rest_toolkit,代码行数:37,代码来源:macauth_demo.py

示例6: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]
def main(global_config, **settings):
    # defaults
    if 'mako.directories' not in settings:
        settings['mako.directories'] = 'marteauweb:templates'

    session_factory = session_factory_from_settings(settings)

    # configure the waitress logger
    logger = logging.getLogger('waitress')
    logger.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    logger.addHandler(ch)

    # creating the config and the queue
    config = Configurator(settings=settings, session_factory=session_factory)
    config.registry['queue'] = queue.Queue()

    # Use our custom Request class
    config.set_request_factory(Request)

    # Both of our chosen policies configure a "forbidden view" to handle
    # unauthenticated access.  We have to resolve this conflict by explicitly
    # picking which one we want to use.
    config.add_forbidden_view("pyramid_persona.views.forbidden")

    # routing
    config.add_route('index', '/')
    config.add_route('profile', '/profile')
    config.add_route('purge', '/purge')
    config.add_route('reset', '/reset')
    config.add_route('test', '/test')
    config.add_route('cancel', '/test/{jobid}/cancel')
    config.add_route('delete', '/test/{jobid}/delete')
    config.add_route('replay', '/test/{jobid}/replay')
    config.add_route('job', '/test/{jobid}')
    config.add_route('nodes', '/nodes')
    config.add_route('node_enable', '/nodes/{name}/enable')
    config.add_route('node_test', '/nodes/{name}/test')
    config.add_route('node', '/nodes/{name}')
    config.add_route('report_index', '/report/{jobid}')
    config.add_route('report_file', '/report/{jobid}/{filename:.*}')
    config.add_route('docs_file', '/docs/{file:.*}')
    config.add_route('docs_index', '/docs')
    config.add_route('addjob', '/addjob')
    config.add_route('fixture_options', '/fixture_options/{fixture:.*}')
    config.add_route('project_options', '/project_options/{project:.*}')
    config.add_route('hosts', '/hosts')
    config.add_route('verify_host', '/hosts/{host:.*}/verify')
    config.add_route('host', '/hosts/{host:.*}')
    config.add_static_view('media', 'marteauweb:media/')
    config.add_route('karaoke', '/media/marteau.kar')
    config.add_route('socket_io', 'socket.io/*remaining')

    config.scan("marteauweb.views")
    config.scan("marteauweb.socketio_service")
    return config.make_wsgi_app()
开发者ID:mozilla-services,项目名称:marteau-web,代码行数:59,代码来源:wsgiapp.py

示例7: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]
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

    authn_policy = AuthTktAuthenticationPolicy(settings['authn_secret'],
                                               hashalg='sha512')
    authz_policy = ACLAuthorizationPolicy()

    config = Configurator(settings=settings)
    config.set_root_factory('uptrack.resources.get_root')
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    config.add_request_method(get_user, 'user', reify=True)

    config.add_subscriber(add_base_template, BeforeRender)

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

    # Public views, status
    config.add_route('overview', '/')
    config.add_view('uptrack.views.status.overview', route_name='overview',
                    renderer='templates/overview.pt')
    config.add_view('uptrack.views.status.uptodate',
                    context='uptrack.models.Distro', name='uptodate',
                    renderer='templates/status.pt')
    config.add_view('uptrack.views.status.outofdate',
                    context='uptrack.models.Distro', name='outofdate',
                    renderer='templates/status.pt')
    config.add_view('uptrack.views.status.problems',
                    context='uptrack.models.Distro', name='problems',
                    renderer='templates/status.pt')

    # Log in and log out
    config.add_route('login', '/login')
    config.add_view('uptrack.views.login', route_name='login',
                    renderer='templates/login.pt')
    config.add_route('logout', '/logout')
    config.add_view('uptrack.views.logout', route_name='logout')
    config.add_forbidden_view('uptrack.views.login',
                              renderer='templates/login.pt')

    # Admin interfaces
    config.add_view('uptrack.views.admin', permission='admin',
                    context='uptrack.resources.BaseResource',
                    renderer='templates/admin.pt')
    config.add_view('uptrack.views.save', permission='admin',
                    context='uptrack.resources.BaseResource', name='save',
                    renderer='json')
    config.add_view('uptrack.views.remove', permission='admin',
                    context='uptrack.models.BaseModel', name='remove',
                    renderer='json')

    return config.make_wsgi_app()
开发者ID:herlo,项目名称:uptrack,代码行数:58,代码来源:__init__.py

示例8: base_configure

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]
def base_configure(global_config, **settings):

    for key, value in conf_defaults.items():
        settings.setdefault(key, value)

    _resolve_dotted(settings)

    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    
    authentication_policy = AuthTktAuthenticationPolicy(settings['leirirekkari.secret'], callback=groupfinder)
    authorization_policy = ACLAuthorizationPolicy()
    
    config = Configurator(settings=settings, root_factory=Root)

    config.set_request_property(get_user, 'user', reify=True)

    config.set_authentication_policy(authentication_policy)
    config.set_authorization_policy(authorization_policy)
    config.set_default_permission('view')

#    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view(name=settings['leirirekkari.static_name'], path=settings['leirirekkari.static_path'], cache_max_age=3600)
    config.add_forbidden_view(forbidden)
    config.add_notfound_view(notfound, append_slash=True)
    
    config.add_translation_dirs('leirirekkari:locale/')

    config.set_locale_negotiator(leirirekkari_locale_negotiator)
    
    config.add_subscriber('leirirekkari.subscribers.add_localizer', 'pyramid.events.NewRequest')
    config.add_subscriber('leirirekkari.subscribers.add_renderer_globals', 'pyramid.events.BeforeRender')
    config.add_subscriber('leirirekkari.subscribers.breadcrumb_subscriber', 'pyramid.events.NewRequest')
    
    config.include('pyramid_mailer')
    
    session_factory = settings['leirirekkari.session_factory'][0](**settings)
    config.set_session_factory(session_factory)
    
    # Include modules listed in 'leirirekkari.base_includes':
    for module in settings['leirirekkari.base_includes']:
        config.include(module)
    config.commit()
    
    config.scan()

    return config
开发者ID:netblade,项目名称:saraste_leirirekkari,代码行数:49,代码来源:__init__.py

示例9: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]
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
	config = Configurator(settings=settings, root_factory='.resources.Root')

	authentication_policy = SessionAuthenticationPolicy()
	authorization_policy = ACLAuthorizationPolicy()

	config.set_default_csrf_options(require_csrf=True)
	config.set_authentication_policy(authentication_policy)
	config.set_authorization_policy(authorization_policy)
	config.add_forbidden_view(redirect_login)
	config.include('pyramid_chameleon')
	config.include("pyramid_beaker")
	config.add_static_view('static', 'static', cache_max_age=3600)
	config.add_route('home', '/')
	config.add_route('login', '/login')
	config.add_route('contact', '/contact')
	config.add_route('logout', '/logout')
	config.add_route('register', '/register')
	config.add_route('recover', '/recover')
	config.add_route('reset_password', '/recover/{key}')
	config.add_route('shows', '/shows')
	config.add_route('search', '/search')
	config.add_route('profile', '/profile')
	config.add_route('settings_feed', '/settings/feeds')
	config.add_route('settings_pw', '/settings/password')
	config.add_route('settings_token', '/settings/token')
	config.add_route('episodes', '/episodes')
	config.add_route('feed', '/atom/{user}/{token}')
	config.add_route('ical', '/ical/{user}/{token}')
	config.add_route('html', '/episodes/{user}/{token}')
	config.add_route('subscribe', '/subscribe')
	config.add_route('unsubscribe', '/unsubscribe')
	config.add_route('setup', '/setup') # TODO remove this
	config.scan()
	return config.make_wsgi_app()
开发者ID:cockroach,项目名称:webisoder,代码行数:43,代码来源:__init__.py

示例10: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]
def main (global_config, **settings):
	flowah.data.init(engine_from_config(settings, 'sqlalchemy.'))

	config = Configurator(
		settings = settings,
		root_factory = RootFactory,
		session_factory = pyramid.session.UnencryptedCookieSessionFactoryConfig(
			settings.get('session.secret', 'test'),
			cookie_name = settings.get('session.cookie.name', 's'),
			timeout = 60*60*24*3,
			cookie_max_age = 60*60*24*3,
		),
		authentication_policy = pyramid.authentication.SessionAuthenticationPolicy(
			prefix = 'auth.',
			callback = group_finder,
			debug = False),
		authorization_policy = pyramid.authorization.ACLAuthorizationPolicy(),
	)

	config.set_request_property(
		lambda request: lambda permission: has_permission(permission, request.root, request),
		'has_permission'
	)

	config.add_tween('sapyens.db.notfound_tween_factory', under = pyramid.tweens.EXCVIEW)

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

	config.add_route('login', '/login')
	login_view = sapyens.views.LoginView(lambda _, request: request.registry.settings['password'])
	config.add_view(login_view, route_name = 'login', renderer = 'sapyens.views:templates/login.mako')
	config.add_forbidden_view(login_view, renderer = 'sapyens.views:templates/login.mako')
	config.add_route('logout', '/logout')
	config.add_view(sapyens.views.LogoutView('root'), route_name = 'logout', permission = 'view')

	config.scan()

	return config.make_wsgi_app()
开发者ID:fillest,项目名称:flowah,代码行数:40,代码来源:__init__.py

示例11: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]
def main(global_config, **settings):
    """This function returns a Pyramid WSGI application.

    Args:
        global_config: (dict) config parameters
        **settings: (dict) extra settings

    Returns:
        (WSGI app)
    """
    del global_config
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    config = Configurator(settings=settings,
                          root_factory='seeweb.models.RootFactory')
    config.include('pyramid_jinja2')
    config.include('pyramid_beaker')

    # Security policies
    authn_policy = SessionAuthenticationPolicy(callback=groupfinder)
    authz_policy = ACLAuthorizationPolicy()
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    config.add_forbidden_view(forbidden)

    # static
    config.add_static_view(name='static', path='static', cache_max_age=3600)

    config.add_static_view(name='avatar',
                           path="seeweb:data/avatar",
                           cache_max_age=3600)
    config.add_static_view(name='gallery',
                           path="seeweb:data/gallery",
                           cache_max_age=3600)

    # public
    config.add_route('home', '/')
    config.add_route('documentation', 'documentation')
    config.add_route('user_list', 'users')
    config.add_route('team_list', 'teams')
    config.add_route('ro_list', 'ros')

    # admin
    config.add_route('admin_users', "admin/users")
    config.add_route('admin_teams', "admin/teams")
    config.add_route('admin_ros', "admin/ros")

    # # user auth
    config.add_route('user_login', 'user_login')
    config.add_route('user_logout', 'user_logout')
    config.add_route('user_register', 'user_register')

    # actor
    config.add_route('actor_view_home', 'actor/{uid}/home')
    config.add_route('actor_view_home_default', 'actor/{uid}')

    # team
    for tab_title, tab_id in team_tabs:
        config.add_route('team_edit_%s' % tab_id, 'team/{uid}/edit/%s' % tab_id)
        config.add_route('team_view_%s' % tab_id, 'team/{uid}/%s' % tab_id)

    config.add_route('team_view_home_default', 'team/{uid}')

    # user
    for tab_title, tab_id in user_tabs:
        config.add_route('user_edit_%s' % tab_id, 'user/{uid}/edit/%s' % tab_id)
        config.add_route('user_view_%s' % tab_id, 'user/{uid}/%s' % tab_id)

    config.add_route('user_view_home_default', 'user/{uid}')

    # research objects
    for tab_title, tab_id in ro_tabs:
        config.add_route('ro_edit_%s' % tab_id, 'ro/{uid}/edit/%s' % tab_id)
        config.add_route('ro_view_%s' % tab_id, 'ro/{uid}/%s' % tab_id)

    config.add_route('ro_create', 'ro/create')
    config.add_route('ro_view_home_default', 'ro/{uid}')

    for dname in glob("seeweb/ro/*/"):
        dname = dname.replace("\\", "/")
        ro_type = basename(dirname(dname))
        static_pth = dname + "static"
        if exists(static_pth):
            config.add_static_view(name='static_%s' % ro_type,
                                   path='seeweb:%s' % static_pth[7:],
                                   cache_max_age=3600)

        for view_pth in glob(dname + "views/*.py"):
            view_name = splitext(basename(view_pth))[0]
            if view_name != "__init__":
                modname = splitext(view_pth)[0].replace("/", ".")
                mod = import_module(modname)
                config.add_route(mod.route_name, mod.route_url)

    # RO data objects
    for dname in glob("seeweb/rodata/*/"):
        dname = dname.replace("\\", "/")
        ro_type = basename(dirname(dname))
#.........这里部分代码省略.........
开发者ID:revesansparole,项目名称:seeweb,代码行数:103,代码来源:__init__.py

示例12: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]

#.........这里部分代码省略.........

    # Read one history
    config.add_route("stakeholders_read_one_history", "/stakeholders/history/{output}/{uid}")

    """
    Comments
    """
    # Returns a JSON representation of comments to an object
    config.add_route("comments_sitekey", "/comments/sitekey/{uid}")
    config.add_route("comments_all", "/comments/{object}/{uid}")
    # Adds a comment
    config.add_route("comment_add", "/comments/add")
    # Deletes a comment
    config.add_route("comment_delete", "/comments/delete")

    """
    Moderation
    """
    # Moderation overview
    config.add_route("moderation_html", "/moderation")

    """
    Files
    """
    # Embedded form to upload a file
    config.add_route("file_upload_form_embedded", "/files/form")
    config.add_route("file_upload_json_response", "/files/form/json", request_method="POST")
    # Show or download a file
    config.add_route("file_view", "/files/{action}/{identifier}")

    """
    Download
    """
    config.add_route("download", "/download")

    """
    Translation
    """
    # A controller that returns the translation needed in the ExtJS user
    # interface
    config.add_route("ui_translation", "/lang")
    # Return a json with all available languages from DB
    config.add_route("language_store", "/lang/all")
    # Try to add or edit a translation
    config.add_route("edit_translation", "/lang/edit")
    # Scan the directory of translation files
    config.add_route("translation_files", "/translation/files")
    # Do a batch translation based on a file
    config.add_route("translation_batch", "/translation/batch")
    # Extract the translatable strings of the database
    config.add_route("extractDatabaseTranslation", "/translation/extract/{type}")

    config.add_route("context_layers", "/app/view/layers.js")
    # Return a json with all available profiles from disk
    config.add_route("profile_store", "/profiles/all")

    # An user profile page (maybe not needed anymore?)
    # [inserted ../profile/.. to link, otherwise could be conflicting with
    # some usernames ('update', 'json')]
    # A json representation of user information
    config.add_route("user_profile_json", "/users/json/{userid}")
    # Updates the information of a user
    config.add_route("user_update", "/users/update", request_method="POST")
    # Add a new user
    config.add_route("add_user", "/users/add", request_method="POST")

    config.add_route("user_self_registration", "/users/register")
    config.add_route("user_activation", "/users/activate")
    config.add_route("user_account", "/users/account")
    config.add_route("user_approve", "/users/approve")

    config.add_route("form_clear_session", "/form/clearsession/{item}/{attr}")

    # A WMS proxy
    config.add_route("wms_proxy", "/geoserver/lo/wms", request_method="GET")
    config.add_route("simple_proxy", "/proxy", request_method="GET")

    # Changeset protocol, query the changeset
    config.add_route("changesets_read", "/changesets")

    # Show a list of latest changesets
    config.add_route("changesets_read_latest", "/changesets/latest/{output}")
    # Show a list of changesets by a user
    config.add_route("changesets_read_byuser", "/changesets/{username}/{output}")

    # A route to the sitemap.xml
    config.add_route("sitemap", "/sitemap.xml")

    # Add a route to search locations
    config.add_route("location_search", "/search")

    # A route for ajax queries to get values for a given key
    config.add_route("filterValues", "/json/filtervalues")

    # Error views
    config.add_forbidden_view(forbidden_view)
    config.add_notfound_view(notfound_view)

    config.scan()
    return config.make_wsgi_app()
开发者ID:CDE-UNIBE,项目名称:lokp,代码行数:104,代码来源:__init__.py

示例13: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]
def main(global_config, **settings):
    """
    Creates wsgi app
    """
    global config
    config = settings
    global memcache
    memcache = MemcachedCache([config['MEMCACHE_URI']])

    from intranet3.models import DBSession, Base, User
    from intranet3.utils import request
    from intranet3.views.auth import forbidden_view

    def groupfinder(userid, request):
        if userid == 0: ## cron userid
            perm = ['g:cron']
        else:
            user = User.query.get(userid)
            perm = [ 'g:%s' % g for g in user.groups ]
            if user.freelancer:
                perm.append('g:freelancer')
        return perm

    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    session_factory = session_factory_from_settings(settings)
    authn_policy = CustomAuthenticationPolicy(config['SESSION_KEY'], callback=groupfinder)
    authz_policy = ACLAuthorizationPolicy()
    pyramid_config = Configurator(
        settings=settings,
        authentication_policy=authn_policy,
        authorization_policy=authz_policy,
        session_factory=session_factory,
        request_factory=request.Request,
        default_permission='view',
        root_factory=Root,
    )
    pyramid_config.add_forbidden_view(forbidden_view)

    pyramid_config.add_static_view('static', 'static', cache_max_age=3600)

    #beta:
    #pyramid_config.add_route('api_my_bugs', '/api/bugs')
    #pyramid_config.add_route('api_time_collection', '/api/times')
    #pyramid_config.add_route('api_time', '/api/times/{id:\d+}')

    pyramid_config.add_route('api_team', '/api/teams/{team_id:\d+}')
    pyramid_config.add_route('api_teams', '/api/teams')
    pyramid_config.add_route('api_users', '/api/users')
    pyramid_config.add_route('api_preview', '/api/preview')
    pyramid_config.add_route('api_images', '/api/images/{type:\w+}/{id:\d+}')
    pyramid_config.add_route('api_presence', 'api/presence')
    pyramid_config.add_route('api_blacklist', 'api/blacklist')
    pyramid_config.add_route('api_lateness', '/api/lateness')
    pyramid_config.add_route('api_absence', '/api/absence')
    pyramid_config.add_route('api_absence_days', '/api/absence_days')

    pyramid_config.add_renderer('.html', 'pyramid_jinja2.renderer_factory')
    pyramid_config.add_renderer(None, 'intranet3.utils.renderer.renderer_factory')
    pyramid_config.add_translation_dirs('intranet3:locale/')

    jinja2_env = pyramid_config.get_jinja2_environment()
    from intranet3.utils import filters

    jinja2_env.filters['slugify'] = filters.slugify
    jinja2_env.filters['parse_datetime_to_miliseconds'] = filters.parse_datetime_to_miliseconds
    jinja2_env.filters['parse_user_email'] = filters.parse_user_email
    jinja2_env.filters['timedelta_to_minutes'] = filters.timedelta_to_minutes
    jinja2_env.filters['format_time'] = filters.format_time
    jinja2_env.filters['dictsort2'] = filters.do_dictsort
    jinja2_env.filters['tojson'] = filters.tojson
    jinja2_env.filters['comma_number'] = filters.comma_number
    jinja2_env.filters['first_words'] = filters.first_words
    jinja2_env.filters['first_words'] = filters.first_words

    jinja2_env.filters['is_true'] = filters.is_true
    jinja2_env.filters['is_false'] = filters.is_false
    jinja2_env.filters['initials'] = filters.initials
    jinja2_env.filters['int_or_float'] = filters.int_or_float
    jinja2_env.filters['markdown'] = filters.markdown_filter
    jinja2_env.globals.update(zip=zip)

    pyramid_config.include('pyramid_autoroute')
    if 'venusian.ignore' in settings:
        venusian_ingore = settings.get('venusian.ignore')
    else:
        venusian_ingore = None
    pyramid_config.scan(ignore=venusian_ingore)

    pyramid_config.add_settings({
        'TEMPLATE_DIR': os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates'),
    })


    app = pyramid_config.make_wsgi_app()
    return app
开发者ID:avalanchy,项目名称:intranet,代码行数:99,代码来源:__init__.py

示例14: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]

#.........这里部分代码省略.........
    config.add_view(view=ServerTopPlayers, route_name="server_top_active", attr="json",
                    renderer="json", accept="application/json")

    config.add_route("server_top_active_json", "/server/{id:\d+}/topactive.json")
    config.add_view(view=ServerTopPlayers, route_name="server_top_active_json", attr="json",
                    renderer="json")

    config.add_route("server_top_scorers", "/server/{id:\d+}/topscorers")
    config.add_view(view=ServerTopScorers, route_name="server_top_scorers", attr="html",
                    renderer="server_top_scorers.mako", accept="text/html")
    config.add_view(view=ServerTopScorers, route_name="server_top_scorers", attr="json",
                    renderer="json", accept="application/json")

    config.add_route("server_top_scorers_json", "/server/{id:\d+}/topscorers.json")
    config.add_view(view=ServerTopScorers, route_name="server_top_scorers_json", attr="json",
                    renderer="json")

    config.add_route("server_info", "/server/{id:\d+}")
    config.add_view(view=ServerInfo, route_name="server_info", attr="html",
                    renderer="server_info.mako", accept="text/html")
    config.add_view(view=ServerInfo, route_name="server_info", attr="json", renderer="json",
                    accept="application/json")

    config.add_route("server_info_json", "/server/{id:\d+}.json")
    config.add_view(view=ServerInfo, route_name="server_info_json", attr="json", renderer="json")

    # MAP ROUTES
    config.add_route("map_index", "/maps")
    config.add_view(view=MapIndex, route_name="map_index", attr="html",
                    renderer="map_index.mako", accept="text/html")
    config.add_view(view=MapIndex, route_name="map_index", attr="json", renderer="json",
                    accept="application/json")

    config.add_route("map_index_json", "/maps.json")
    config.add_view(view=MapIndex, route_name="map_index_json", attr="json", renderer="json")

    config.add_route("map_top_scorers", "/map/{id:\d+}/topscorers")
    config.add_view(view=MapTopScorers, route_name="map_top_scorers", attr="html",
                    renderer="map_top_scorers.mako", accept="text/html")
    config.add_view(view=MapTopScorers, route_name="map_top_scorers_json", attr="json",
                    renderer="json", accept="application/json")

    config.add_route("map_top_scorers_json", "/map/{id:\d+}/topscorers.json")
    config.add_view(view=MapTopScorers, route_name="map_top_scorers", attr="json", renderer="json")

    config.add_route("map_top_active", "/map/{id:\d+}/topactive")
    config.add_view(view=MapTopPlayers, route_name="map_top_active", attr="html",
                    renderer="map_top_active.mako", accept="text/html")
    config.add_view(view=MapTopPlayers, route_name="map_top_active", attr="json",
                    renderer="json", accept="application/json")

    config.add_route("map_top_active_json", "/map/{id:\d+}/topactive.json")
    config.add_view(view=MapTopPlayers, route_name="map_top_active_json", attr="json",
                    renderer="json")

    config.add_route("map_top_servers", "/map/{id:\d+}/topservers")
    config.add_view(view=MapTopServers, route_name="map_top_servers", attr="html",
                    renderer="map_top_servers.mako", accept="text/html")
    config.add_view(view=MapTopServers, route_name="map_top_servers", attr="json",
                    renderer="json", accept="application/json")

    config.add_route("map_top_servers_json", "/map/{id:\d+}/topservers.json")
    config.add_view(view=MapTopServers, route_name="map_top_servers_json", attr="json",
                    renderer="json")

    config.add_route("map_info", "/map/{id:\d+}")
    config.add_view(map_info, route_name="map_info", accept="text/html", renderer="map_info.mako")
    config.add_view(map_info_json, route_name="map_info", accept="application/json",
                    renderer="json")

    config.add_route("map_info_json", "/map/{id:\d+}.json")
    config.add_view(map_info_json, route_name="map_info_json", renderer="jsonp")

    config.add_route("map_captimes", "/map/{id:\d+}/captimes")
    config.add_view(map_captimes, route_name="map_captimes", accept="text/html",
                    renderer="map_captimes.mako")
    config.add_view(map_captimes_json, route_name="map_captimes", accept="application/json",
                    renderer="json")

    config.add_route("map_captimes_json", "/map/{id:\d+}/captimes.json")
    config.add_view(map_captimes_json, route_name="map_captimes_json", renderer="jsonp")

    # SEARCH ROUTES
    config.add_route("search", "search")
    config.add_view(search, route_name="search", accept="text/html", renderer="search.mako")
    config.add_view(search_json, route_name="search", accept="application/json", renderer="jsonp")

    config.add_route("search_json", "search.json")
    config.add_view(search_json, route_name="search_json", renderer="jsonp")

    # ADMIN ROUTES
    config.add_forbidden_view(forbidden, renderer="forbidden.mako")

    config.add_route("login", "/login")
    config.add_view(login, route_name="login", check_csrf=True, renderer="json")

    config.add_route("merge", "/admin/merge")
    config.add_view(merge, route_name="merge", renderer="merge.mako", permission="merge")

    return config.make_wsgi_app()
开发者ID:xonotic,项目名称:xonstat,代码行数:104,代码来源:__init__.py

示例15: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_forbidden_view [as 别名]
def main(global_config, **settings):
    config = Configurator(
        settings=settings,
        root_factory=factory,
        authentication_policy=AuthenticationPolicy(settings['auth.file'], __name__),
        authorization_policy=AuthorizationPolicy(),
        route_prefix=ROUTE_PREFIX,
    )
    config.add_forbidden_view(forbidden)
    config.add_request_method(authenticated_role, reify=True)
    config.add_renderer('prettyjson', JSON(indent=4))
    config.add_renderer('jsonp', JSONP(param_name='opt_jsonp'))
    config.add_renderer('prettyjsonp', JSONP(indent=4, param_name='opt_jsonp'))
    config.add_subscriber(add_logging_context, NewRequest)
    config.add_subscriber(set_logging_context, ContextFound)
    config.add_subscriber(set_renderer, NewRequest)
    config.add_subscriber(beforerender, BeforeRender)
    config.include('pyramid_exclog')
    config.include("cornice")
    config.scan("openprocurement.api.views")

    # CouchDB connection
    db_name = os.environ.get('DB_NAME', settings['couchdb.db_name'])
    server = Server(settings.get('couchdb.url'), session=Session(retry_delays=range(10)))
    if 'couchdb.admin_url' not in settings and server.resource.credentials:
        try:
            server.version()
        except Unauthorized:
            server = Server(extract_credentials(settings.get('couchdb.url'))[0])
    config.registry.couchdb_server = server
    if 'couchdb.admin_url' in settings and server.resource.credentials:
        aserver = Server(settings.get('couchdb.admin_url'), session=Session(retry_delays=range(10)))
        users_db = aserver['_users']
        if SECURITY != users_db.security:
            LOGGER.info("Updating users db security", extra={'MESSAGE_ID': 'update_users_security'})
            users_db.security = SECURITY
        username, password = server.resource.credentials
        user_doc = users_db.get('org.couchdb.user:{}'.format(username), {'_id': 'org.couchdb.user:{}'.format(username)})
        if not user_doc.get('derived_key', '') or PBKDF2(password, user_doc.get('salt', ''), user_doc.get('iterations', 10)).hexread(int(len(user_doc.get('derived_key', '')) / 2)) != user_doc.get('derived_key', ''):
            user_doc.update({
                "name": username,
                "roles": [],
                "type": "user",
                "password": password
            })
            LOGGER.info("Updating api db main user", extra={'MESSAGE_ID': 'update_api_main_user'})
            users_db.save(user_doc)
        security_users = [username, ]
        if 'couchdb.reader_username' in settings and 'couchdb.reader_password' in settings:
            reader_username = settings.get('couchdb.reader_username')
            reader = users_db.get('org.couchdb.user:{}'.format(reader_username), {'_id': 'org.couchdb.user:{}'.format(reader_username)})
            if not reader.get('derived_key', '') or PBKDF2(settings.get('couchdb.reader_password'), reader.get('salt', ''), reader.get('iterations', 10)).hexread(int(len(reader.get('derived_key', '')) / 2)) != reader.get('derived_key', ''):
                reader.update({
                    "name": reader_username,
                    "roles": ['reader'],
                    "type": "user",
                    "password": settings.get('couchdb.reader_password')
                })
                LOGGER.info("Updating api db reader user", extra={'MESSAGE_ID': 'update_api_reader_user'})
                users_db.save(reader)
            security_users.append(reader_username)
        if db_name not in aserver:
            aserver.create(db_name)
        db = aserver[db_name]
        SECURITY[u'members'][u'names'] = security_users
        if SECURITY != db.security:
            LOGGER.info("Updating api db security", extra={'MESSAGE_ID': 'update_api_security'})
            db.security = SECURITY
        auth_doc = db.get(VALIDATE_DOC_ID, {'_id': VALIDATE_DOC_ID})
        if auth_doc.get('validate_doc_update') != VALIDATE_DOC_UPDATE % username:
            auth_doc['validate_doc_update'] = VALIDATE_DOC_UPDATE % username
            LOGGER.info("Updating api db validate doc", extra={'MESSAGE_ID': 'update_api_validate_doc'})
            db.save(auth_doc)
        # sync couchdb views
        sync_design(db)
        db = server[db_name]
    else:
        if db_name not in server:
            server.create(db_name)
        db = server[db_name]
        # sync couchdb views
        sync_design(db)
    config.registry.db = db

    # migrate data
    migrate_data(config.registry.db)

    # S3 connection
    if 'aws.access_key' in settings and 'aws.secret_key' in settings and 'aws.s3_bucket' in settings:
        connection = S3Connection(settings['aws.access_key'], settings['aws.secret_key'])
        config.registry.s3_connection = connection
        bucket_name = settings['aws.s3_bucket']
        if bucket_name not in [b.name for b in connection.get_all_buckets()]:
            connection.create_bucket(bucket_name, location=Location.EU)
        config.registry.bucket_name = bucket_name
    config.registry.server_id = settings.get('id', '')
    return config.make_wsgi_app()
开发者ID:spaceship-labs,项目名称:openprocurement.api,代码行数:99,代码来源:__init__.py


注:本文中的pyramid.config.Configurator.add_forbidden_view方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。