def includeme(config): """ :type config: pyramid.config.Configurator """ config.include('restfw') config.include('storage.users') from restfw.utils import scan_ignore config.scan(ignore=scan_ignore(config.registry))
def includeme(config: Configurator): config.include('restfw') settings = config.get_settings() prefix = settings.get('restfw_admin.prefix', 'admin').strip('/') settings['restfw_admin.prefix'] = prefix from .resources import Admin def add_to_root(event): root = event.root root[prefix] = Admin() from restfw.interfaces import IRootCreated config.add_subscriber(add_to_root, IRootCreated) from .views import admin_ui, redirect_to_admin_ui ui_url = f'/{prefix}/ui' config.add_route('admin_ui_ts', f'{ui_url}/') config.add_view(admin_ui, route_name='admin_ui_ts', request_method='GET') config.add_route('admin_ui', ui_url) config.add_view(redirect_to_admin_ui, route_name='admin_ui', request_method='GET') config.add_route('admin_ui_index', f'{ui_url}/index.html') config.add_view(redirect_to_admin_ui, route_name='admin_ui_index', request_method='GET') import os from pathlib import Path admin_ui_dir = Path(__file__).parent / 'admin_ui' config.add_static_view(name=ui_url, path=os.fspath(admin_ui_dir)) import re from .config import get_admin_ui_settings index_html = (admin_ui_dir / 'index.html').read_text('utf-8') index_html_tpl = re.sub( r'<script>window\.__RESTFW_ADMIN_PARAMS__.+?</script>', '__ADMIN_PARAMS__', index_html, ) ui_settings = get_admin_ui_settings(config.registry) ui_settings.index_html_tpl = index_html_tpl from .config import add_resource_admin config.add_directive('add_resource_admin', add_resource_admin) from .fields import add_field_converter config.add_directive('add_field_converter', add_field_converter) from restfw.utils import scan_ignore config.scan(ignore=scan_ignore(config.registry))
def includeme(config: Configurator): config.include('restfw') config.include('storage.authentication') from restfw.interfaces import IRootCreated from .resources import Users def add_to_root(event): event.root['users'] = Users() config.add_subscriber(add_to_root, IRootCreated) from restfw.utils import scan_ignore config.scan(ignore=scan_ignore(config.registry))
def includeme(config: Configurator): config.include('restfw') config.include('restfw_admin') config.include('example_app.users') from .resources import Docs def add_to_root(event): docs = event.root['docs'] = Docs() docs.http_post(event.request, params={ 'user_id': 1, 'data': 'It is a document data.' }) from restfw.interfaces import IRootCreated config.add_subscriber(add_to_root, IRootCreated) from restfw.utils import scan_ignore config.scan(ignore=scan_ignore(config.registry))
def includeme(config): """ :type config: pyramid.config.Configurator """ from .resources import check_credentials from .policy import ExampleSecurityPolicy config.set_security_policy(ExampleSecurityPolicy()) config.include('restfw') config.include('restfw_admin') from .resources import Users def add_to_root(event): users = Users() users.create_user('Admin', 'Root', age=39, current_work={ 'title': 'Administrator', 'address': 'Yellow st.' }) users.create_user('Ivan', 'Petrov', age=25) event.root['users'] = users from restfw.interfaces import IRootCreated config.add_subscriber(add_to_root, IRootCreated) from pathlib import Path from restfw_admin.config import add_restfw_admin_auth_provider, add_restfw_admin_http_client static_dir = Path(__file__).parent / 'static' auth_provider = static_dir / 'auth_provider.js' add_restfw_admin_auth_provider(config, 'getBasicAuthProvider', auth_provider.read_text('utf-8')) http_client = static_dir / 'http_client.js' add_restfw_admin_http_client(config, 'getHttpClient', http_client.read_text('utf-8')) from restfw.utils import scan_ignore config.scan(ignore=scan_ignore(config.registry))
def includeme(config: Configurator): from .policy import ExampleSecurityPolicy config.set_security_policy(ExampleSecurityPolicy()) from restfw.utils import scan_ignore config.scan(ignore=scan_ignore(config.registry))