def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ with Configurator(settings=settings) as config: config.include('.models') config.include('pyramid_jinja2') config.include('.routes') config.scan() pj = pyramid_jsonapi.PyramidJSONAPI(config, models) pj.create_jsonapi_using_magic_and_pixie_dust() return config.make_wsgi_app()
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ config = Configurator(settings=settings) config.include('pyramid_jinja2') config.include('.models') config.include('.routes') config.scan() pj = pyramid_jsonapi.PyramidJSONAPI(config, models) pj.create_jsonapi_using_magic_and_pixie_dust() pj.append_callback_set_to_all_views('access_control_serialised_objects') pj.metadata.JSONSchema.build_definitions() return config.make_wsgi_app()
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ # The usual stuff from the pyramid alchemy scaffold. engine = engine_from_config(settings, 'sqlalchemy.') models.DBSession.configure(bind=engine) models.Base.metadata.bind = engine config = Configurator(settings=settings) config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') config.add_route('echo', '/echo/{type}') config.scan(views) # Set up the renderer. renderer = JSON() renderer.add_adapter(datetime.date, datetime_adapter) config.add_renderer('json', renderer) # Lines specific to pyramid_jsonapi. # Create an API instance. pj = pyramid_jsonapi.PyramidJSONAPI( config, test_settings['models_iterable'][settings.get( 'pyramid_jsonapi_tests.models_iterable', 'module')], lambda view: models.DBSession) # Register a bad filter operator for test purposes. pj.filter_registry.register('bad_op') # Create the routes and views automagically. pj.create_jsonapi_using_magic_and_pixie_dust() person_view = pj.view_classes[models.Person] person_view.callbacks['after_serialise_object'].appendleft( person_callback_add_information) person_view.allowed_fields = property(person_allowed_fields) person_view.allowed_object = person_allowed_object pj.append_callback_set_to_all_views('access_control_serialised_objects') permission_class_view = pj.view_classes[models.PermissionClass] permission_class_view.callbacks['request_headers'].appendleft( authenticate_access) # Back to the usual pyramid stuff. return config.make_wsgi_app()
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ set_cache_regions_from_settings(settings) session_factory = session_factory_from_settings(settings) engine = engine_from_config(settings, 'sqlalchemy.') mymodels.DBSession.configure(bind=engine) mymodels.Base.metadata.bind = engine config = Configurator(settings=settings) config.include('pyramid_chameleon') config.include('pyramid_jinja2') config.set_session_factory(session_factory) config.include('pyramid_beaker') config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') config.add_route('nearest', '/nearest') config.add_route('search', '/search') pj = pyramid_jsonapi.PyramidJSONAPI(config, mymodels, lambda view: mymodels.DBSession) pj.create_jsonapi_using_magic_and_pixie_dust() config.scan() return config.make_wsgi_app()
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ config = Configurator(settings=settings) config.include('pyramid_jinja2') config.include('pyramid_mako') config.include('cornice') config.include('.models') config.include('.routes') renderer = JSON() renderer.add_adapter(datetime.date, lambda obj, request: obj.isoformat()) config.add_renderer('json', renderer) use_pj = asbool(settings.get('api.use_pyramid_jsonapi', False)) if use_pj: pj = pyramid_jsonapi.PyramidJSONAPI(config, mymodel) ep = pj.endpoint_data.endpoints pj.create_jsonapi() # FIXME make tests JWT_SECRET = os.environ.get('JWT_SECRET', 'secret') config.set_jwt_authentication_policy(JWT_SECRET, callback=groupfinder) authz_policy = ACLAuthorizationPolicy() config.set_authorization_policy(authz_policy) config.add_route('home', '/') config.add_route('apps', '/app/{appname}') config.add_route('admin', '/admin') config.add_route('login', '/login') config.add_route('auth_refresh', '/auth/refresh') config.add_view('.views.userauth.login', route_name='login', request_method='POST', renderer='json') config.add_view('.views.userauth.refresh', route_name='auth_refresh', request_method='GET', renderer='json') #scan_views = ['notfound', 'sitecontent', 'userauth', 'todos'] # FIXME jsonapi has "notfound" view scan_views = [ 'sitecontent', 'userauth', 'todos', 'client', 'ebcsv', 'wikipages', ] if not use_pj: scan_views.append('notfound') for view in scan_views: config.scan('.views.%s' % view) #config.add_route('clzcore', '/clzcore/*path') #config.add_view('.views.wikipages.get_clzpage', route_name='clzcore') config.set_request_property('.util.get_user', 'user', reify=True) application = config.make_wsgi_app() # add wsgi middleware here return application