def includeme(config): """ This function returns a Pyramid WSGI application. """ # update the settings object from the YAML application config file settings = config.get_settings() settings.update(yaml.load(file(settings.get('app.cfg')))) global srid global schema global parentschema global formalchemy_language global formalchemy_default_zoom global formalchemy_default_x global formalchemy_default_y global formalchemy_available_functionalities config.set_request_property( get_user_from_request, name='user', reify=True) # configure 'locale' dir as the translation dir for c2cgeoportal app config.add_translation_dirs('c2cgeoportal:locale/') # initialize database engine = sqlalchemy.engine_from_config( config.get_settings(), 'sqlalchemy.') sqlahelper.add_engine(engine) config.include(pyramid_tm.includeme) # initialize the dbreflection module dbreflection.init(engine) # dogpile.cache configuration caching.init_region(settings['cache']) caching.invalidate_region() # bind the mako renderer to other file extensions config.add_renderer('.html', mako_renderer_factory) config.add_renderer('.js', mako_renderer_factory) # add the "geojson" renderer config.add_renderer('geojson', GeoJSON()) # add decimal json renderer config.add_renderer('decimaljson', DecimalJSON()) # add the "xsd" renderer config.add_renderer('xsd', XSD( sequence_callback=dbreflection._xsd_sequence_callback)) # add the set_user_validator directive, and set a default user # validator config.add_directive('set_user_validator', set_user_validator) config.set_user_validator(default_user_validator) # add an OGCProxy view config.add_route( 'ogcproxy', '/ogcproxy', custom_predicates=(ogcproxy_route_predicate,)) config.add_view('papyrus_ogcproxy.views:ogcproxy', route_name='ogcproxy') # add routes to the mapserver proxy config.add_route( 'mapserverproxy', '/mapserv_proxy', custom_predicates=(mapserverproxy_route_predicate,), pregenerator=MultiDomainPregenerator()) # add routes to csv view config.add_route('csvecho', '/csv') # add routes to the echo service config.add_route('echo', '/echo') # add routes to the entry view class config.add_route('home', '/') config.add_route('viewer', '/viewer.js') config.add_route('edit', '/edit') config.add_route('edit.js', '/edit.js') config.add_route('routing', '/routing') config.add_route('routing.js', '/routing.js') config.add_route('loginform', '/login.html') config.add_route('login', '/login') config.add_route('logout', '/logout') config.add_route('loginchange', '/loginchange') config.add_route('testi18n', '/testi18n.html') config.add_route('apijs', '/api.js') config.add_route('xapijs', '/xapi.js') config.add_route('apihelp', '/apihelp.html') config.add_route('xapihelp', '/xapihelp.html') config.add_route('themes', '/themes') # permalink theme: recover the theme for generating custom viewer.js url config.add_route('permalinktheme', '/theme/*themes') # checker routes, Checkers are web services to test and assess that # the application is correctly functioning. # These web services are used by tools like (nagios). config.add_route('checker_main', '/checker_main') config.add_route('checker_viewer', '/checker_viewer') config.add_route('checker_edit', '/checker_edit') config.add_route('checker_edit_js', '/checker_edit_js') config.add_route('checker_api', '/checker_api') config.add_route('checker_xapi', '/checker_xapi') config.add_route('checker_printcapabilities', '/checker_printcapabilities') config.add_route('checker_pdf', '/checker_pdf') config.add_route('checker_fts', '/checker_fts') config.add_route('checker_wmscapabilities', '/checker_wmscapabilities') config.add_route('checker_wfscapabilities', '/checker_wfscapabilities') # collector config.add_route('check_collector', '/check_collector') # print proxy routes config.add_route('printproxy', '/printproxy') config.add_route('printproxy_info', '/printproxy/info.json') config.add_route('printproxy_create', '/printproxy/create.json') config.add_route('printproxy_get', '/printproxy/{file}.printout') # full text search routes config.add_route('fulltextsearch', '/fulltextsearch') # Access to raster data config.add_route('raster', '/raster') config.add_route('profile.csv', '/profile.csv') config.add_route('profile.json', '/profile.json') # shortener config.add_route('shortener_create', '/short/create') config.add_route('shortener_get', '/short/{ref}') # add routes for the "layers" web service config.add_route( 'layers_count', '/layers/{layer_id:\\d+}/count', request_method='GET') config.add_route( 'layers_metadata', '/layers/{layer_id:\\d+}/md.xsd', request_method='GET') config.add_route( 'layers_read_many', '/layers/{layer_id:\\d+,?(\\d+,)*\\d*$}', request_method='GET') # supports URLs like /layers/1,2,3 config.add_route( 'layers_read_one', '/layers/{layer_id:\\d+}/{feature_id}', request_method='GET') config.add_route( 'layers_create', '/layers/{layer_id:\\d+}', request_method='POST') config.add_route( 'layers_update', '/layers/{layer_id:\\d+}/{feature_id}', request_method='PUT') config.add_route( 'layers_delete', '/layers/{layer_id:\\d+}/{feature_id}', request_method='DELETE') config.add_route( 'layers_enumerate_attribute_values', '/layers/{layer_name}/values/{field_name}', request_method='GET') # there's no view corresponding to that route, it is to be used from # mako templates to get the root of the "layers" web service config.add_route('layers_root', '/layers/') # pyramid_formalchemy's configuration config.include('pyramid_formalchemy') config.include('fa.jquery') # define the srid, schema and parentschema # as global variables to be usable in the model srid = config.get_settings()['srid'] schema = config.get_settings()['schema'] parentschema = config.get_settings()['parentschema'] settings = config.get_settings() formalchemy_default_zoom = get_setting( settings, ('admin_interface', 'map_zoom'), formalchemy_default_zoom) formalchemy_default_x = get_setting( settings, ('admin_interface', 'map_x'), formalchemy_default_x) formalchemy_default_y = get_setting( settings, ('admin_interface', 'map_y'), formalchemy_default_y) formalchemy_available_functionalities = get_setting( settings, ('admin_interface', 'available_functionalities'), formalchemy_available_functionalities) # scan view decorator for adding routes config.scan(ignore='c2cgeoportal.tests') config.registry.registerUtility( MultiDomainStaticURLInfo(), IStaticURLInfo) # add the static view (for static resources) config.add_static_view( 'static', 'c2cgeoportal:static', cache_max_age=int(settings["default_max_age"]) )
def includeme(config): """ This function returns a Pyramid WSGI application. """ settings = config.get_settings() config.include("c2cgeoportal_commons") call_hook(settings, "after_settings", settings) get_user_from_request = create_get_user_from_request(settings) config.add_request_method(get_user_from_request, name="user", property=True) config.add_request_method(get_user_from_request, name="get_user") # Configure 'locale' dir as the translation dir for c2cgeoportal app config.add_translation_dirs("c2cgeoportal_geoportal:locale/") config.include('c2cwsgiutils.pyramid.includeme') health_check = HealthCheck(config) # Initialise DBSessions init_dbsessions(settings, config, health_check) # Initialize the dbreflection module dbreflection.init() checker.init(config, health_check) check_collector.init(config, health_check) config.include("pyramid_closure") # dogpile.cache configuration if 'cache' in settings: caching.init_region(settings['cache']) from c2cgeoportal_commons.models.main import InvalidateCacheEvent @zope.event.classhandler.handler(InvalidateCacheEvent) def handle(event: InvalidateCacheEvent): del event caching.invalidate_region() # Register a tween to get back the cache buster path. config.add_tween( "c2cgeoportal_geoportal.lib.cacheversion.CachebusterTween") # Bind the mako renderer to other file extensions add_mako_renderer(config, ".html") add_mako_renderer(config, ".js") # Add the "geojson" renderer config.add_renderer("geojson", GeoJSON()) # Add decimal json renderer config.add_renderer("decimaljson", DecimalJSON()) # Add the "xsd" renderer config.add_renderer( "xsd", XSD(sequence_callback=dbreflection.xsd_sequence_callback)) # Add the set_user_validator directive, and set a default user validator config.add_directive("set_user_validator", set_user_validator) config.set_user_validator(default_user_validator) if settings.get("ogcproxy_enable", False): # pragma: no cover # Add an OGCProxy view config.add_route_predicate("ogc_server", OgcproxyRoutePredicate) config.add_route("ogcproxy", "/ogcproxy", ogc_server=True) config.add_view("papyrus_ogcproxy.views:ogcproxy", route_name="ogcproxy") # Add routes to the mapserver proxy config.add_route_predicate("mapserverproxy", MapserverproxyRoutePredicate) config.add_route( "mapserverproxy", "/mapserv_proxy", mapserverproxy=True, pregenerator=C2CPregenerator(role=True), ) # Add route to the tinyows proxy config.add_route( "tinyowsproxy", "/tinyows_proxy", pregenerator=C2CPregenerator(role=True), ) # Add routes to csv view config.add_route("csvecho", "/csv", request_method="POST") # Add route to the export GPX/KML view config.add_route("exportgpxkml", "/exportgpxkml") # Add routes to the echo service config.add_route("echo", "/echo", request_method="POST") # Add routes to the entry view class config.add_route("base", "/", static=True) config.add_route("loginform", "/login.html", request_method="GET") add_cors_route(config, "/login", "login") config.add_route("login", "/login", request_method="POST") add_cors_route(config, "/logout", "login") config.add_route("logout", "/logout", request_method="GET") add_cors_route(config, "/loginchange", "login") config.add_route("loginchange", "/loginchange", request_method="POST") add_cors_route(config, "/loginresetpassword", "login") config.add_route("loginresetpassword", "/loginresetpassword", request_method="POST") add_cors_route(config, "/loginuser", "login") config.add_route("loginuser", "/loginuser", request_method="GET") config.add_route("testi18n", "/testi18n.html", request_method="GET") config.add_route("apijs", "/api.js", request_method="GET") config.add_route("xapijs", "/xapi.js", request_method="GET") config.add_route("apihelp", "/apihelp.html", request_method="GET") config.add_route("xapihelp", "/xapihelp.html", request_method="GET") config.add_route( "themes", "/themes", request_method="GET", pregenerator=C2CPregenerator(role=True), ) config.add_route("invalidate", "/invalidate", request_method="GET") # Print proxy routes config.add_route("printproxy", "/printproxy", request_method="HEAD") add_cors_route(config, "/printproxy/*all", "print") config.add_route( "printproxy_capabilities", "/printproxy/capabilities.json", request_method="GET", pregenerator=C2CPregenerator(role=True), ) config.add_route("printproxy_report_create", "/printproxy/report.{format}", request_method="POST", header=JSON_CONTENT_TYPE) config.add_route("printproxy_status", "/printproxy/status/{ref}.json", request_method="GET") config.add_route("printproxy_cancel", "/printproxy/cancel/{ref}", request_method="DELETE") config.add_route("printproxy_report_get", "/printproxy/report/{ref}", request_method="GET") # For v2 config.add_route( "printproxy_info", "/printproxy/info.json", request_method="GET", pregenerator=C2CPregenerator(role=True), ) config.add_route( "printproxy_create", "/printproxy/create.json", request_method="POST", ) config.add_route( "printproxy_get", "/printproxy/{file}.printout", request_method="GET", ) # Full-text search routes add_cors_route(config, "/fulltextsearch", "fulltextsearch") config.add_route("fulltextsearch", "/fulltextsearch") # Access to raster data add_cors_route(config, "/raster", "raster") config.add_route("raster", "/raster", request_method="GET") add_cors_route(config, "/profile.{ext}", "profile") config.add_route("profile.csv", "/profile.csv", request_method="POST") config.add_route("profile.json", "/profile.json", request_method="POST") # Shortener add_cors_route(config, "/short/create", "shortener") config.add_route("shortener_create", "/short/create", request_method="POST") config.add_route("shortener_get", "/short/{ref}", request_method="GET") # Geometry processing config.add_route("difference", "/difference", request_method="POST") # PDF report tool config.add_route("pdfreport", "/pdfreport/{layername}/{ids}", request_method="GET") # Add routes for the "layers" web service add_cors_route(config, "/layers/*all", "layers") config.add_route("layers_count", "/layers/{layer_id:\\d+}/count", request_method="GET") config.add_route( "layers_metadata", "/layers/{layer_id:\\d+}/md.xsd", request_method="GET", pregenerator=C2CPregenerator(role=True), ) config.add_route("layers_read_many", "/layers/{layer_id:\\d+,?(\\d+,)*\\d*$}", request_method="GET") # supports URLs like /layers/1,2,3 config.add_route("layers_read_one", "/layers/{layer_id:\\d+}/{feature_id}", request_method="GET") config.add_route("layers_create", "/layers/{layer_id:\\d+}", request_method="POST", header=JSON_CONTENT_TYPE) config.add_route("layers_update", "/layers/{layer_id:\\d+}/{feature_id}", request_method="PUT", header=JSON_CONTENT_TYPE) config.add_route("layers_delete", "/layers/{layer_id:\\d+}/{feature_id}", request_method="DELETE") config.add_route( "layers_enumerate_attribute_values", "/layers/{layer_name}/values/{field_name}", request_method="GET", pregenerator=C2CPregenerator(), ) # There is no view corresponding to that route, it is to be used from # mako templates to get the root of the "layers" web service config.add_route("layers_root", "/layers/", request_method="HEAD") # Resource proxy (load external url, useful when loading non https content) config.add_route("resourceproxy", "/resourceproxy", request_method="GET") # Scan view decorator for adding routes config.scan(ignore=[ "c2cgeoportal_geoportal.scripts", "c2cgeoportal_geoportal.wsgi_app" ]) if "subdomains" in settings: # pragma: no cover config.registry.registerUtility(MultiDomainStaticURLInfo(), IStaticURLInfo) # Add the static view (for static resources) _add_static_view(config, "static", "c2cgeoportal_geoportal:static") _add_static_view(config, "project", "c2cgeoportal_geoportal:project") add_admin_interface(config) add_static_view(config) # Handles the other HTTP errors raised by the views. Without that, # the client receives a status=200 without content. config.add_view(error_handler, context=HTTPException)
def includeme(config): """ This function returns a Pyramid WSGI application. """ # update the settings object from the YAML application config file settings = config.get_settings() settings.update(c2c.template.get_config(settings.get("app.cfg"))) call_hook(settings, "after_settings", settings) config.add_request_method(_create_get_user_from_request(settings), name="user", property=True) # configure 'locale' dir as the translation dir for c2cgeoportal app config.add_translation_dirs("c2cgeoportal:locale/") # initialize database engine = sqlalchemy.engine_from_config(settings, "sqlalchemy.") sqlahelper.add_engine(engine) config.include(pyramid_tm.includeme) config.include("pyramid_closure") if "sqlalchemy_slave.url" in settings and \ settings["sqlalchemy.url"] != settings["sqlalchemy_slave.url"]: # pragma: nocover # Setup a slave DB connection and add a tween to switch between it and the default one. log.info("Using a slave DB for reading") engine_slave = sqlalchemy.engine_from_config(config.get_settings(), "sqlalchemy_slave.") sqlahelper.add_engine(engine_slave, name="slave") config.add_tween("c2cgeoportal.models.db_chooser_tween_factory", over="pyramid_tm.tm_tween_factory") # initialize the dbreflection module dbreflection.init(engine) # dogpile.cache configuration caching.init_region(settings["cache"]) caching.invalidate_region() # Register a tween to get back the cache buster path. config.add_tween("c2cgeoportal.lib.cacheversion.CachebusterTween") # bind the mako renderer to other file extensions add_mako_renderer(config, ".html") add_mako_renderer(config, ".js") config.include("pyramid_chameleon") # add the "geojson" renderer config.add_renderer("geojson", GeoJSON()) # add decimal json renderer config.add_renderer("decimaljson", DecimalJSON()) # add the "xsd" renderer config.add_renderer( "xsd", XSD(sequence_callback=dbreflection._xsd_sequence_callback)) # add the set_user_validator directive, and set a default user # validator config.add_directive("set_user_validator", set_user_validator) config.set_user_validator(default_user_validator) if settings.get("ogcproxy_enable", False): # pragma: no cover # add an OGCProxy view config.add_route_predicate("ogc_server", OgcproxyRoutePredicate) config.add_route("ogcproxy", "/ogcproxy", ogc_server=True) config.add_view("papyrus_ogcproxy.views:ogcproxy", route_name="ogcproxy") # add routes to the mapserver proxy config.add_route_predicate("mapserverproxy", MapserverproxyRoutePredicate) config.add_route( "mapserverproxy", "/mapserv_proxy", mapserverproxy=True, pregenerator=C2CPregenerator(role=True), ) # add route to the tinyows proxy config.add_route( "tinyowsproxy", "/tinyows_proxy", pregenerator=C2CPregenerator(role=True), ) # add routes to csv view config.add_route("csvecho", "/csv", request_method="POST") # add route to the export GPX/KML view config.add_route("exportgpxkml", "/exportgpxkml") # add routes to the echo service config.add_route("echo", "/echo", request_method="POST") # add routes to the entry view class config.add_route("base", "/", static=True) config.add_route("loginform", "/login.html", request_method="GET") add_cors_route(config, "/login", "login") config.add_route("login", "/login", request_method="POST") add_cors_route(config, "/logout", "login") config.add_route("logout", "/logout", request_method="GET") add_cors_route(config, "/loginchange", "login") config.add_route("loginchange", "/loginchange", request_method="POST") add_cors_route(config, "/loginresetpassword", "login") config.add_route("loginresetpassword", "/loginresetpassword", request_method="POST") add_cors_route(config, "/loginuser", "login") config.add_route("loginuser", "/loginuser", request_method="GET") config.add_route("testi18n", "/testi18n.html", request_method="GET") config.add_route("apijs", "/api.js", request_method="GET") config.add_route("xapijs", "/xapi.js", request_method="GET") config.add_route("apihelp", "/apihelp.html", request_method="GET") config.add_route("xapihelp", "/xapihelp.html", request_method="GET") config.add_route( "themes", "/themes", request_method="GET", pregenerator=C2CPregenerator(role=True), ) config.add_route("invalidate", "/invalidate", request_method="GET") # checker routes, Checkers are web services to test and assess that # the application is correctly functioning. # These web services are used by tools like (nagios). config.add_route("checker_routes", "/checker_routes", request_method="GET") config.add_route("checker_lang_files", "/checker_lang_files", request_method="GET") config.add_route("checker_pdf3", "/checker_pdf3", request_method="GET") config.add_route("checker_fts", "/checker_fts", request_method="GET") config.add_route("checker_theme_errors", "/checker_theme_errors", request_method="GET") config.add_route("checker_phantomjs", "/checker_phantomjs", request_method="GET") # collector config.add_route("check_collector", "/check_collector", request_method="GET") # print proxy routes config.add_route("printproxy", "/printproxy", request_method="HEAD") add_cors_route(config, "/printproxy/*all", "print") config.add_route( "printproxy_capabilities", "/printproxy/capabilities.json", request_method="GET", pregenerator=C2CPregenerator(role=True), ) config.add_route("printproxy_report_create", "/printproxy/report.{format}", request_method="POST", header=JSON_CONTENT_TYPE) config.add_route("printproxy_status", "/printproxy/status/{ref}.json", request_method="GET") config.add_route("printproxy_cancel", "/printproxy/cancel/{ref}", request_method="DELETE") config.add_route("printproxy_report_get", "/printproxy/report/{ref}", request_method="GET") # full text search routes add_cors_route(config, "/fulltextsearch", "fulltextsearch") config.add_route("fulltextsearch", "/fulltextsearch") # Access to raster data add_cors_route(config, "/raster", "raster") config.add_route("raster", "/raster", request_method="GET") add_cors_route(config, "/profile.{ext}", "profile") config.add_route("profile.csv", "/profile.csv", request_method="POST") config.add_route("profile.json", "/profile.json", request_method="POST") # shortener add_cors_route(config, "/short/create", "shortner") config.add_route("shortener_create", "/short/create", request_method="POST") config.add_route("shortener_get", "/short/{ref}", request_method="GET") # Geometry processing config.add_route("difference", "/difference", request_method="POST") # PDF report tool config.add_route("pdfreport", "/pdfreport/{layername}/{id}", request_method="GET") # add routes for the "layers" web service add_cors_route(config, "/layers/*all", "layers") config.add_route("layers_count", "/layers/{layer_id:\\d+}/count", request_method="GET") config.add_route( "layers_metadata", "/layers/{layer_id:\\d+}/md.xsd", request_method="GET", pregenerator=C2CPregenerator(role=True), ) config.add_route("layers_read_many", "/layers/{layer_id:\\d+,?(\\d+,)*\\d*$}", request_method="GET") # supports URLs like /layers/1,2,3 config.add_route("layers_read_one", "/layers/{layer_id:\\d+}/{feature_id}", request_method="GET") config.add_route("layers_create", "/layers/{layer_id:\\d+}", request_method="POST", header=JSON_CONTENT_TYPE) config.add_route("layers_update", "/layers/{layer_id:\\d+}/{feature_id}", request_method="PUT", header=JSON_CONTENT_TYPE) config.add_route("layers_delete", "/layers/{layer_id:\\d+}/{feature_id}", request_method="DELETE") config.add_route( "layers_enumerate_attribute_values", "/layers/{layer_name}/values/{field_name}", request_method="GET", pregenerator=C2CPregenerator(), ) # there's no view corresponding to that route, it is to be used from # mako templates to get the root of the "layers" web service config.add_route("layers_root", "/layers/", request_method="HEAD") # Resource proxy (load external url, useful when loading non https content) config.add_route("resourceproxy", "/resourceproxy", request_method="GET") # pyramid_formalchemy's configuration config.include("pyramid_formalchemy") config.include("fa.jquery") # define the srid, schema and parentschema # as global variables to be usable in the model c2cgeoportal.srid = settings["srid"] c2cgeoportal.schema = settings["schema"] c2cgeoportal.parentschema = settings["parentschema"] c2cgeoportal.formalchemy_default_zoom = get_setting( settings, ("admin_interface", "map_zoom"), c2cgeoportal.formalchemy_default_zoom) c2cgeoportal.formalchemy_default_x = get_setting( settings, ("admin_interface", "map_x"), c2cgeoportal.formalchemy_default_x) c2cgeoportal.formalchemy_default_y = get_setting( settings, ("admin_interface", "map_y"), c2cgeoportal.formalchemy_default_y) c2cgeoportal.formalchemy_available_functionalities = get_setting( settings, ("admin_interface", "available_functionalities"), c2cgeoportal.formalchemy_available_functionalities) c2cgeoportal.formalchemy_available_metadata = get_setting( settings, ("admin_interface", "available_metadata"), c2cgeoportal.formalchemy_available_metadata) c2cgeoportal.formalchemy_available_metadata = [ e if isinstance(e, basestring) else e.get("name") for e in c2cgeoportal.formalchemy_available_metadata ] config.add_route("checker_all", "/checker_all", request_method="GET") config.add_route("version_json", "/version.json", request_method="GET") stats.init(config) # scan view decorator for adding routes config.scan(ignore=["c2cgeoportal.tests", "c2cgeoportal.scripts"]) if "subdomains" in settings: # pragma: no cover config.registry.registerUtility(MultiDomainStaticURLInfo(), IStaticURLInfo) # add the static view (for static resources) _add_static_view(config, "static", "c2cgeoportal:static") _add_static_view(config, "project", "c2cgeoportal:project") add_admin_interface(config) add_static_view(config) # Handles the other HTTP errors raised by the views. Without that, # the client receives a status=200 without content. config.add_view(error_handler, context=HTTPException) _log_versions(settings)
def _callFUT(self, **kwargs): from papyrus.renderers import XSD fake_info = {} return XSD(**kwargs)(fake_info)
def includeme(config): """ This function returns a Pyramid WSGI application. """ # update the settings object from the YAML application config file settings = config.get_settings() settings.update(yaml.load(file(settings.get("app.cfg")))) global srid global schema global parentschema global formalchemy_language global formalchemy_default_zoom global formalchemy_default_x global formalchemy_default_y global formalchemy_available_functionalities global formalchemy_available_metadata config.add_request_method(_create_get_user_from_request(settings), name="user", property=True) # configure 'locale' dir as the translation dir for c2cgeoportal app config.add_translation_dirs("c2cgeoportal:locale/") # initialize database engine = sqlalchemy.engine_from_config(settings, "sqlalchemy.") sqlahelper.add_engine(engine) config.include(pyramid_tm.includeme) config.include("pyramid_closure") # initialize the dbreflection module dbreflection.init(engine) # dogpile.cache configuration caching.init_region(settings["cache"]) caching.invalidate_region() # bind the mako renderer to other file extensions add_mako_renderer(config, ".html") add_mako_renderer(config, ".js") config.include("pyramid_chameleon") # add the "geojson" renderer config.add_renderer("geojson", GeoJSON()) # add decimal json renderer config.add_renderer("decimaljson", DecimalJSON()) # add the "xsd" renderer config.add_renderer( "xsd", XSD(sequence_callback=dbreflection._xsd_sequence_callback)) # add the set_user_validator directive, and set a default user # validator config.add_directive("set_user_validator", set_user_validator) config.set_user_validator(default_user_validator) if settings.get("ogcproxy_enable", True): # add an OGCProxy view config.add_route("ogcproxy", "/ogcproxy", custom_predicates=(ogcproxy_route_predicate, )) config.add_view("papyrus_ogcproxy.views:ogcproxy", route_name="ogcproxy") # add routes to the mapserver proxy config.add_route( "mapserverproxy", "/mapserv_proxy", custom_predicates=(mapserverproxy_route_predicate, ), pregenerator=C2CPregenerator(role=True), ) # add route to the tinyows proxy config.add_route( "tinyowsproxy", "/tinyows_proxy", pregenerator=C2CPregenerator(role=True), ) # add routes to csv view config.add_route("csvecho", "/csv", request_method="POST") # add route to the export GPX/KML view config.add_route("exportgpxkml", "/exportgpxkml") # add routes to the echo service config.add_route("echo", "/echo", request_method="POST") # add routes to the entry view class config.add_route("loginform", "/login.html", request_method="GET") add_cors_route(config, "/login", "login") config.add_route("login", "/login", request_method=("GET", "POST")) add_cors_route(config, "/logout", "login") config.add_route("logout", "/logout", request_method="GET") add_cors_route(config, "/loginchange", "login") config.add_route("loginchange", "/loginchange", request_method="POST") add_cors_route(config, "/loginresetpassword", "login") config.add_route("loginresetpassword", "/loginresetpassword", request_method="GET") config.add_route("testi18n", "/testi18n.html", request_method="GET") config.add_route("apijs", "/api.js", request_method="GET") config.add_route("xapijs", "/xapi.js", request_method="GET") config.add_route("apihelp", "/apihelp.html", request_method="GET") config.add_route("xapihelp", "/xapihelp.html", request_method="GET") config.add_route( "themes", "/themes", request_method="GET", pregenerator=C2CPregenerator(role=True), ) config.add_route("invalidate", "/invalidate", request_method="GET") # checker routes, Checkers are web services to test and assess that # the application is correctly functioning. # These web services are used by tools like (nagios). config.add_route("checker_main", "/checker_main", request_method="GET") config.add_route("checker_viewer", "/checker_viewer", request_method="GET") config.add_route("checker_edit", "/checker_edit", request_method="GET") config.add_route("checker_edit_js", "/checker_edit_js", request_method="GET") config.add_route("checker_api", "/checker_api", request_method="GET") config.add_route("checker_xapi", "/checker_xapi", request_method="GET") config.add_route("checker_lang_files", "/checker_lang_files", request_method="GET") config.add_route( "checker_printcapabilities", "/checker_printcapabilities", request_method="GET", ) config.add_route("checker_pdf", "/checker_pdf", request_method="GET") config.add_route( "checker_print3capabilities", "/checker_print3capabilities", request_method="GET", ) config.add_route("checker_pdf3", "/checker_pdf3", request_method="GET") config.add_route("checker_fts", "/checker_fts", request_method="GET") config.add_route("checker_wmscapabilities", "/checker_wmscapabilities", request_method="GET") config.add_route("checker_wfscapabilities", "/checker_wfscapabilities", request_method="GET") config.add_route("checker_theme_errors", "/checker_theme_errors", request_method="GET") # collector config.add_route("check_collector", "/check_collector", request_method="GET") # print proxy routes config.add_route("printproxy", "/printproxy", request_method="HEAD") config.add_route( "printproxy_info", "/printproxy/info.json", request_method="GET", pregenerator=C2CPregenerator(role=True), ) config.add_route( "printproxy_create", "/printproxy/create.json", request_method="POST", ) config.add_route( "printproxy_get", "/printproxy/{file}.printout", request_method="GET", ) # V3 add_cors_route(config, "/printproxy/*all", "print") config.add_route( "printproxy_capabilities", "/printproxy/capabilities.json", request_method="GET", pregenerator=C2CPregenerator(role=True), ) config.add_route("printproxy_report_create", "/printproxy/report.{format}", request_method="POST", header=JSON_CONTENT_TYPE) config.add_route("printproxy_status", "/printproxy/status/{ref}.json", request_method="GET") config.add_route("printproxy_cancel", "/printproxy/cancel/{ref}", request_method="DELETE") config.add_route("printproxy_report_get", "/printproxy/report/{ref}", request_method="GET") # full text search routes add_cors_route(config, "/fulltextsearch", "fulltextsearch") config.add_route("fulltextsearch", "/fulltextsearch") # Access to raster data add_cors_route(config, "/raster", "raster") config.add_route("raster", "/raster", request_method="GET") add_cors_route(config, "/profile.{ext}", "profile") config.add_route("profile.csv", "/profile.csv", request_method="POST") config.add_route("profile.json", "/profile.json", request_method="POST") # shortener config.add_route("shortener_create", "/short/create", request_method="POST") config.add_route("shortener_get", "/short/{ref}", request_method="GET") # Geometry processing config.add_route("difference", "/difference", request_method="POST") # PDF report tool config.add_route("pdfreport", "/pdfreport/{layername}/{id}", request_method="GET") # add routes for the "layers" web service add_cors_route(config, "/layers/*all", "layers") config.add_route("layers_count", "/layers/{layer_id:\\d+}/count", request_method="GET") config.add_route( "layers_metadata", "/layers/{layer_id:\\d+}/md.xsd", request_method="GET", pregenerator=C2CPregenerator(role=True), ) config.add_route("layers_read_many", "/layers/{layer_id:\\d+,?(\\d+,)*\\d*$}", request_method="GET") # supports URLs like /layers/1,2,3 config.add_route("layers_read_one", "/layers/{layer_id:\\d+}/{feature_id}", request_method="GET") config.add_route("layers_create", "/layers/{layer_id:\\d+}", request_method="POST", header=JSON_CONTENT_TYPE) config.add_route("layers_update", "/layers/{layer_id:\\d+}/{feature_id}", request_method="PUT", header=JSON_CONTENT_TYPE) config.add_route("layers_delete", "/layers/{layer_id:\\d+}/{feature_id}", request_method="DELETE") config.add_route( "layers_enumerate_attribute_values", "/layers/{layer_name}/values/{field_name}", request_method="GET", pregenerator=C2CPregenerator(), ) # there's no view corresponding to that route, it is to be used from # mako templates to get the root of the "layers" web service config.add_route("layers_root", "/layers/", request_method="HEAD") # pyramid_formalchemy's configuration config.include("pyramid_formalchemy") config.include("fa.jquery") # define the srid, schema and parentschema # as global variables to be usable in the model srid = settings["srid"] schema = settings["schema"] parentschema = settings["parentschema"] formalchemy_default_zoom = get_setting(settings, ("admin_interface", "map_zoom"), formalchemy_default_zoom) formalchemy_default_x = get_setting(settings, ("admin_interface", "map_x"), formalchemy_default_x) formalchemy_default_y = get_setting(settings, ("admin_interface", "map_y"), formalchemy_default_y) formalchemy_available_functionalities = get_setting( settings, ("admin_interface", "available_functionalities"), formalchemy_available_functionalities) formalchemy_available_metadata = get_setting( settings, ("admin_interface", "available_metadata"), formalchemy_available_metadata) config.add_route("checker_all", "/checker_all", request_method="GET") # scan view decorator for adding routes config.scan(ignore="c2cgeoportal.tests") config.registry.registerUtility(MultiDomainStaticURLInfo(), IStaticURLInfo) # add the static view (for static resources) _add_static_view(config, "static", "c2cgeoportal:static") _add_static_view(config, "project", "c2cgeoportal:project") add_admin_interface(config) add_static_view(config) # Handles the other HTTP errors raised by the views. Without that, # the client receives a status=200 without content. config.add_view(error_handler, context=HTTPException)
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 init_model() session_factory = session_factory_from_settings(settings) if 'localization' not in settings: settings['localization'] = 'id_ID.UTF-8' locale.setlocale(locale.LC_ALL, settings['localization']) if 'timezone' not in settings: settings['timezone'] = DefaultTimeZone config = Configurator(settings=settings, root_factory='opensipkd.models.RootFactory', session_factory=session_factory) modules = get_modules(settings) for module in modules: if module=='admin': continue module = module.replace('/','.') mfile = 'opensipkd.'+module m = __import__(mfile,globals(), locals(),'main',0) m.main(global_config, **settings) config.include('pyramid_beaker') config.include('pyramid_chameleon') authn_policy = AuthTktAuthenticationPolicy('sosecret', callback=group_finder, hashalg='sha512') authz_policy = ACLAuthorizationPolicy() config.set_authentication_policy(authn_policy) config.set_authorization_policy(authz_policy) config.add_request_method(get_user, 'user', reify=True) config.add_request_method(get_title, 'title', reify=True) config.add_request_method(get_company, 'company', reify=True) config.add_request_method(get_departement, 'departement', reify=True) config.add_request_method(get_ibukota, 'ibukota', reify=True) config.add_request_method(get_address, 'address', reify=True) config.add_request_method(get_address2, 'address2', reify=True) config.add_request_method(get_app_name, 'app_name', reify=True) config.add_request_method(get_modules, 'modules', reify=True) #config.add_request_method(thousand, 'thousand', reify=True) config.add_notfound_view(RemoveSlashNotFoundViewFactory()) config.add_static_view('static', 'static', cache_max_age=3600) config.add_static_view('deform_static', 'deform:static') config.add_static_view('files', settings['static_files']) config.add_renderer('csv', '.tools.CSVRenderer') routes = DBSession.query(Route.kode, Route.path, Route.nama).\ filter(Route.type==0).all() #standar route for route in routes: config.add_route(route.kode, route.path) if route.nama: titles[route.kode] = route.nama ############################################################################ #Custom JSON json_renderer = JSON() json_renderer.add_adapter(datetime.datetime, lambda v, request: dmy(v)) json_renderer.add_adapter(datetime.date, lambda v, request: dmy(v)) json_renderer.add_adapter(decimal.Decimal, lambda v, request: str(v)) config.add_renderer('json', json_renderer) ############################################################################ # JSON RPC config.include('pyramid_rpc.jsonrpc') json_renderer = JSON() json_renderer.add_adapter(datetime.datetime, lambda v, request: v.isoformat()) json_renderer.add_adapter(datetime.date, lambda v, request: v.isoformat()) config.add_renderer('json_rpc', json_renderer) routes = DBSession.query(Route.kode, Route.path, Route.nama).\ filter(Route.type==1).all() # for route in routes: config.add_jsonrpc_endpoint(route.kode, route.path, default_renderer="json_rpc") ############################################################################ #config.add_jsonrpc_endpoint('ws_pbb', '/pbb/api', default_renderer="json_rpc") #config.add_jsonrpc_endpoint('ws_keuangan', '/ws/keuangan', default_renderer="json_rpc") #config.add_jsonrpc_endpoint('ws_user', '/ws/user', default_renderer="json_rpc") ############################################################################ ########################################### #MAP ########################################### if 'map' in modules: import papyrus from papyrus.renderers import GeoJSON, XSD config.add_request_method(get_gmap_key, 'gmap', reify=True) config.include(papyrus.includeme) config.add_renderer('geojson', GeoJSON()) config.add_renderer('xsd', XSD()) config.add_static_view('static_map', 'map/static', cache_max_age=3600) if 'map/aset' in modules: config.add_static_view('static_map_aset', 'map/aset/static', cache_max_age=3600) if 'map/pbb' in modules: config.add_static_view('static_map_pbb', 'map/pbb/static', cache_max_age=3600) config.scan() app = config.make_wsgi_app() from paste.translogger import TransLogger app = TransLogger(app, setup_console_handler=False) return app