コード例 #1
0
ファイル: views.py プロジェクト: turtle321/inspire-next
def _get_base_url():
    """Return base URL for generated URLs for remote reference."""
    base_url = current_app.config.get(
        "LEGACY_ROBOTUPLOAD_URL",
        current_app.config["SERVER_NAME"],
    )
    return ensure_scheme(base_url)
コード例 #2
0
ファイル: views.py プロジェクト: harunurhan/inspire-next
def _get_base_url():
    """Return base URL for generated URLs for remote reference."""
    base_url = current_app.config.get(
        "LEGACY_ROBOTUPLOAD_URL",
        current_app.config["SERVER_NAME"],
    )
    return ensure_scheme(base_url)
コード例 #3
0
ファイル: views.py プロジェクト: theleestarr/inspire-next
def _continue_workflow(workflow_id, recid, result=None):
    """Small wrapper to continue a workflow.

    Will prepare the needed data from the record id and the result data if
    passed.

    :return: True if succeeded, False if the specified workflow id does not
        exist.
    """
    result = result if result is not None else {}
    base_url = ensure_scheme(current_app.config["SERVER_NAME"])
    try:
        workflow_object = workflow_object_class.get(workflow_id)
    except WorkflowsMissingObject:
        current_app.logger.error(
            'No workflow object with the id %s could be found.',
            workflow_id,
        )
        return False

    workflow_object.extra_data['url'] = join(base_url, 'record', str(recid))
    workflow_object.extra_data['recid'] = recid
    workflow_object.data['control_number'] = recid
    workflow_object.extra_data['callback_result'] = result
    workflow_object.save()
    db.session.commit()
    workflow_object.continue_workflow(delayed=True)

    return True
コード例 #4
0
ファイル: utils.py プロジェクト: Glignos/inspire-next
def _get_api_url_for_recid(server_name, api_endpoint, recid):
    """Return API url for record

    Args:
        server_name (string): server authority
        api_endpoint (string): api path
        recid (string): record ID

    Returns:
        string: API URL for the record
    """
    if not api_endpoint.endswith('/'):
        api_endpoint = api_endpoint + '/'

    api_url = urljoin(ensure_scheme(server_name), api_endpoint)
    return urljoin(api_url, recid)
コード例 #5
0
ファイル: utils.py プロジェクト: david-caro/inspire-next
def _get_api_url_for_recid(server_name, api_endpoint, recid):
    """Return API url for record

    Args:
        server_name (string): server authority
        api_endpoint (string): api path
        recid (string): record ID

    Returns:
        string: API URL for the record
    """
    if not api_endpoint.endswith('/'):
        api_endpoint = api_endpoint + '/'

    api_url = urljoin(ensure_scheme(server_name), api_endpoint)
    return urljoin(api_url, recid)
コード例 #6
0
    def get_remote_json(self, uri, **kwargs):
        parsed_uri = url_parse(uri)
        # Add http:// protocol so uri.netloc is correctly parsed.
        server_name = current_app.config.get('SERVER_NAME')
        parsed_server = url_parse(ensure_scheme(server_name))

        if parsed_uri.netloc and parsed_uri.netloc != parsed_server.netloc:
            return super(AbstractRecordLoader, self).get_remote_json(uri,
                                                                     **kwargs)
        path_parts = parsed_uri.path.strip('/').split('/')
        if len(path_parts) < 2:
            current_app.logger.error('Bad JSONref URI: {0}'.format(uri))
            return None

        endpoint = path_parts[-2]
        pid_type = get_pid_type_from_endpoint(endpoint)
        recid = path_parts[-1]
        res = self.get_record(pid_type, recid)
        return res
コード例 #7
0
    def get_remote_json(self, uri, **kwargs):
        parsed_uri = url_parse(uri)
        # Add http:// protocol so uri.netloc is correctly parsed.
        server_name = current_app.config.get('SERVER_NAME')
        parsed_server = url_parse(ensure_scheme(server_name))

        if parsed_uri.netloc and parsed_uri.netloc != parsed_server.netloc:
            return super(AbstractRecordLoader,
                         self).get_remote_json(uri, **kwargs)
        path_parts = parsed_uri.path.strip('/').split('/')
        if len(path_parts) < 2:
            current_app.logger.error('Bad JSONref URI: {0}'.format(uri))
            return None

        endpoint = path_parts[-2]
        pid_type = get_pid_type_from_endpoint(endpoint)
        recid = path_parts[-1]
        res = self.get_record(pid_type, recid)
        return res