Exemple #1
0
def _get_api_auth_data(headers: [tuple], request: IRequest, user: IResource)\
        -> dict:
    token_headers = dict([(x, y) for x, y in headers if x == UserTokenHeader])
    token = token_headers[UserTokenHeader]
    user_url = request.resource_url(user)
    # TODO: use colander schema to create cstruct
    return {'status': 'success',
            'user_path': user_url,
            'user_token': token,
            }
Exemple #2
0
def get_choices_by_interface(interface: IInterface,
                             context: IResource,
                             request: IRequest,
                             ) -> []:
    """Get choices for resource paths by interface."""
    catalogs = find_service(context, 'catalogs')
    query = search_query._replace(interfaces=interface)
    resources = catalogs.search(query).elements
    choices = [(request.resource_url(r,
                                     route_name=API_ROUTE_NAME),
                resource_path(r)) for r in resources]
    return choices
Exemple #3
0
def embed_code_config_adapter(context: IResource,
                              request: IRequest) -> {}:
    """Return mapping to render `adhocracy_core:templates/embed_code.html`."""
    settings = request.registry.settings
    frontend_url = settings.get('adhocracy.frontend_url',
                                'http://localhost:6551')
    sdk_url = os.path.join(frontend_url, 'AdhocracySDK.js')
    path = request.resource_url(context)
    locale = settings.get('pyramid.default_locale_name', 'en')
    return {'sdk_url': sdk_url,
            'frontend_url': frontend_url,
            'path': path,
            'widget': '',
            'autoresize': 'false',
            'locale': locale,
            'autourl': 'false',
            'nocenter': 'true',
            'style': 'height: 650px',
            }
Exemple #4
0
def embed_code_config_adapter(context: IResource, request: IRequest) -> {}:
    """Return mapping to render `adhocracy_core:templates/embed_code.html`."""
    settings = request.registry['config']
    frontend_url = settings.adhocracy.frontend_url
    sdk_url = os.path.join(frontend_url, 'AdhocracySDK.js')
    path = request.resource_url(context, route_name=API_ROUTE_NAME)
    # TODO use frontend.locale instead
    locale = settings.configurator.pyramid.default_locale_name
    return {
        'sdk_url': sdk_url,
        'frontend_url': frontend_url,
        'path': path,
        'widget': '',
        'autoresize': 'false',
        'locale': locale,
        'autourl': 'false',
        'initial_url': '',
        'nocenter': 'true',
        'noheader': 'false',
        'style': 'height: 650px',
    }
Exemple #5
0
def embed_code_config_adapter(context: IResource,
                              request: IRequest) -> {}:
    """Return mapping to render `adhocracy_core:templates/embed_code.html`."""
    settings = request.registry['config']
    frontend_url = settings.adhocracy.frontend_url
    sdk_url = os.path.join(frontend_url, 'AdhocracySDK.js')
    path = request.resource_url(context, route_name=API_ROUTE_NAME)
    # TODO use frontend.locale instead
    locale = settings.configurator.pyramid.default_locale_name
    return {'sdk_url': sdk_url,
            'frontend_url': frontend_url,
            'path': path,
            'widget': '',
            'autoresize': 'false',
            'locale': locale,
            'autourl': 'false',
            'initial_url': '',
            'nocenter': 'true',
            'noheader': 'false',
            'style': 'height: 650px',
            }