Skip to content

Plugin

ListPlugin

Bases: SingletonPlugin

Summary dataset view.

Provides a summary view of records, to replace the grid.

Source code in ckanext/list/plugin.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class ListPlugin(SingletonPlugin):
    """
    Summary dataset view.

    Provides a summary view of records, to replace the grid.
    """

    implements(interfaces.IConfigurer, inherit=True)
    implements(interfaces.IResourceView, inherit=True)

    ## IConfigurer
    def update_config(self, config):
        """
        Add our template directories to the list of available templates.

        :param config:
        """
        toolkit.add_template_directory(config, 'theme/templates')
        toolkit.add_public_directory(config, 'theme/public')
        toolkit.add_resource('theme/assets', 'ckanext-list')

    def view_template(self, context, data_dict):
        return 'list/list_view.html'

    def form_template(self, context, data_dict):
        return 'list/list_form.html'

    def can_view(self, data_dict):
        """
        Specify which resources can be viewed by this plugin.

        :param data_dict: return: boolean
        :returns: boolean
        """
        # Check that we have a datastore for this resource
        if data_dict['resource'].get('datastore_active', False):
            return True
        return False

    ## IResourceView
    def info(self):
        return {
            'name': 'list',
            'title': 'List',
            'schema': {
                'title_field': [is_datastore_field],
                'secondary_title_field': [ignore_empty, is_datastore_field],
                'fields': [ignore_empty, is_datastore_field],
                'image_field': [ignore_empty, is_datastore_field],
                'image_delimiter': [ignore_empty],
            },
            'icon': 'list-alt',
            'iframed': True,
            'filterable': True,
            'preview_enabled': True,
            'full_page_edit': False,
        }

    def setup_template_variables(self, context, data_dict):
        """
        Setup variables available to templates.

        :param context:
        :param data_dict:
        """
        datastore_fields = get_datastore_fields(data_dict['resource']['id'], context)
        return {
            'resource_json': json.dumps(data_dict['resource']),
            'resource_view_json': json.dumps(data_dict['resource_view']),
            # Fields - used in the form display options
            'fields': [{'text': f, 'value': f} for f in datastore_fields],
        }

can_view(data_dict)

Specify which resources can be viewed by this plugin.

Parameters:

Name Type Description Default
data_dict

return: boolean

required

Returns:

Type Description

boolean

Source code in ckanext/list/plugin.py
46
47
48
49
50
51
52
53
54
55
56
def can_view(self, data_dict):
    """
    Specify which resources can be viewed by this plugin.

    :param data_dict: return: boolean
    :returns: boolean
    """
    # Check that we have a datastore for this resource
    if data_dict['resource'].get('datastore_active', False):
        return True
    return False

setup_template_variables(context, data_dict)

Setup variables available to templates.

Parameters:

Name Type Description Default
context
required
data_dict
required
Source code in ckanext/list/plugin.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def setup_template_variables(self, context, data_dict):
    """
    Setup variables available to templates.

    :param context:
    :param data_dict:
    """
    datastore_fields = get_datastore_fields(data_dict['resource']['id'], context)
    return {
        'resource_json': json.dumps(data_dict['resource']),
        'resource_view_json': json.dumps(data_dict['resource_view']),
        # Fields - used in the form display options
        'fields': [{'text': f, 'value': f} for f in datastore_fields],
    }

update_config(config)

Add our template directories to the list of available templates.

Parameters:

Name Type Description Default
config
required
Source code in ckanext/list/plugin.py
30
31
32
33
34
35
36
37
38
def update_config(self, config):
    """
    Add our template directories to the list of available templates.

    :param config:
    """
    toolkit.add_template_directory(config, 'theme/templates')
    toolkit.add_public_directory(config, 'theme/public')
    toolkit.add_resource('theme/assets', 'ckanext-list')