Skip to content

Plugin

IIIFPlugin

Bases: SingletonPlugin

Source code in ckanext/iiif/plugin.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
63
64
65
66
67
68
69
70
71
72
73
class IIIFPlugin(plugins.SingletonPlugin):
    plugins.implements(plugins.IActions)
    plugins.implements(plugins.IAuthFunctions)
    plugins.implements(plugins.IBlueprint)
    plugins.implements(plugins.IConfigurable)

    try:
        # hook if we can
        from ckanext.versioned_datastore.interfaces import IVersionedDatastore

        plugins.implements(IVersionedDatastore, inherit=True)
    except ImportError:
        pass

    def get_actions(self):
        """
        IActions hook.
        """
        return create_actions(actions)

    def get_auth_functions(self):
        """
        IAuthFunctions hook.
        """
        return create_auth(auth)

    def configure(self, ckan_config):
        """
        IConfigurable hook. Here, the builders from other plugins are added to the
        BUILDERS list.

        :param ckan_config:
        """
        for plugin in plugins.PluginImplementations(interfaces.IIIIF):
            plugin.register_iiif_builders(actions.BUILDERS)

    def get_blueprint(self):
        """
        IBlueprint hook.
        """
        return routes.blueprints

    def vds_after_multi_query(self, response, result):
        """
        IVersionedDatastore hook.

        Only used if ckanext-versioned-datastore is installed.
        """
        resource_cache = {}
        resource_show = toolkit.get_action('resource_show')

        for record in result['records']:
            resource_id = record['resource']
            if resource_id not in resource_cache:
                resource_cache[resource_id] = resource_show({}, {'id': resource_id})
            with suppress(Exception):
                record['iiif'] = RecordManifestBuilder.build_record_manifest(
                    resource_cache[resource_id], record['data']
                )

configure(ckan_config)

IConfigurable hook. Here, the builders from other plugins are added to the BUILDERS list.

Parameters:

Name Type Description Default
ckan_config
required
Source code in ckanext/iiif/plugin.py
41
42
43
44
45
46
47
48
49
def configure(self, ckan_config):
    """
    IConfigurable hook. Here, the builders from other plugins are added to the
    BUILDERS list.

    :param ckan_config:
    """
    for plugin in plugins.PluginImplementations(interfaces.IIIIF):
        plugin.register_iiif_builders(actions.BUILDERS)

get_actions()

IActions hook.

Source code in ckanext/iiif/plugin.py
29
30
31
32
33
def get_actions(self):
    """
    IActions hook.
    """
    return create_actions(actions)

get_auth_functions()

IAuthFunctions hook.

Source code in ckanext/iiif/plugin.py
35
36
37
38
39
def get_auth_functions(self):
    """
    IAuthFunctions hook.
    """
    return create_auth(auth)

get_blueprint()

IBlueprint hook.

Source code in ckanext/iiif/plugin.py
51
52
53
54
55
def get_blueprint(self):
    """
    IBlueprint hook.
    """
    return routes.blueprints

vds_after_multi_query(response, result)

IVersionedDatastore hook.

Only used if ckanext-versioned-datastore is installed.

Source code in ckanext/iiif/plugin.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def vds_after_multi_query(self, response, result):
    """
    IVersionedDatastore hook.

    Only used if ckanext-versioned-datastore is installed.
    """
    resource_cache = {}
    resource_show = toolkit.get_action('resource_show')

    for record in result['records']:
        resource_id = record['resource']
        if resource_id not in resource_cache:
            resource_cache[resource_id] = resource_show({}, {'id': resource_id})
        with suppress(Exception):
            record['iiif'] = RecordManifestBuilder.build_record_manifest(
                resource_cache[resource_id], record['data']
            )