Skip to content

Query doi

action_stats()

Returns action statistics in JSON format depending on the request parameters. The return will be a list with a dict representing the QueryDOIStat as each element.

Returns:

Type Description

a JSON stringified list of dicts

Source code in ckanext/query_dois/routes/query_doi.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
@blueprint.route('/stats')
def action_stats():
    """
    Returns action statistics in JSON format depending on the request parameters. The
    return will be a list with a dict representing the QueryDOIStat as each element.

    :returns: a JSON stringified list of dicts
    """
    query = model.Session.query(QueryDOIStat)

    # by default order by id desc to get the latest first
    query = query.order_by(QueryDOIStat.id.desc())

    # apply any parameters as filters
    for param_name, column in _helpers.column_param_mapping:
        param_value = toolkit.request.params.get(param_name, None)
        if param_value:
            query = query.filter(column == param_value)

    resource_id = toolkit.request.params.get('resource_id', None)
    if resource_id:
        query = query.join(QueryDOI, QueryDOI.doi == QueryDOIStat.doi).filter(
            QueryDOI.on_resource(resource_id)
        )

    # apply the offset and limit, with sensible defaults
    query = query.offset(toolkit.request.params.get('offset', 0))
    query = query.limit(toolkit.request.params.get('limit', 100))

    # return the data as a JSON dumped list of dicts
    return jsonify([stat.as_dict() for stat in query])

doi_stats()

Returns statistics in JSON format depending on the request parameters. The return will be a list with a dict representing the QueryDOI as each element.

This endpoint currently only supports filtering on the resource_id.

Returns:

Type Description

a JSON stringified list of dicts

Source code in ckanext/query_dois/routes/query_doi.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@blueprint.route('')
def doi_stats():
    """
    Returns statistics in JSON format depending on the request parameters. The return
    will be a list with a dict representing the QueryDOI as each element.

    This endpoint currently only supports filtering on the resource_id.

    :returns: a JSON stringified list of dicts
    """
    query = model.Session.query(QueryDOI)

    # by default order by id desc to get the latest first
    query = query.order_by(QueryDOI.id.desc())

    resource_id = toolkit.request.params.get('resource_id', None)
    if resource_id:
        query = query.filter(QueryDOI.on_resource(resource_id))

    # apply the offset and limit, with sensible defaults
    query = query.offset(toolkit.request.params.get('offset', 0))
    query = query.limit(toolkit.request.params.get('limit', 100))

    # return the data as a JSON dumped list of dicts
    return jsonify([stat.as_dict() for stat in query])

landing_page(data_centre, identifier)

Renders the landing page for the given DOI.

Parameters:

Name Type Description Default
data_centre

the data centre prefix

required
identifier

the DOI identifier

required

Returns:

Type Description

the rendered landing page

Source code in ckanext/query_dois/routes/query_doi.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@blueprint.route('/<data_centre>/<identifier>')
def landing_page(data_centre, identifier):
    """
    Renders the landing page for the given DOI.

    :param data_centre: the data centre prefix
    :param identifier: the DOI identifier
    :returns: the rendered landing page
    """
    doi = '{}/{}'.format(data_centre, identifier)
    query_doi = _helpers.get_query_doi(doi)
    if query_doi is None:
        raise toolkit.abort(404, toolkit._('DOI not recognised'))

    if query_doi.query_version is not None and query_doi.query_version != 'v0':
        return _helpers.render_multisearch_doi_page(query_doi)
    else:
        return _helpers.render_datastore_search_doi_page(query_doi)