Skip to content

Plugin

SketchfabPlugin

Bases: SingletonPlugin

Resource view for embedding sketchfab models.

Source code in ckanext/sketchfab/plugin.py
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
class SketchfabPlugin(SingletonPlugin):
    """
    Resource view for embedding sketchfab models.
    """

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

    def update_config(self, config):
        toolkit.add_template_directory(config, 'theme/templates')

    def info(self):
        return {
            'name': 'sketchfab',
            'title': 'Sketchfab model',
            'schema': {
                'model_url': [ignore_empty, str, is_valid_sketchfab_url],
                'width': [not_empty, is_positive_integer],
                'height': [not_empty, is_positive_integer],
            },
            'iframed': False,
            'icon': 'asterisk',
        }

    def can_view(self, data_dict):
        # Can be added to all resources, regardless of data type
        return True

    def view_template(self, context, data_dict):
        return 'sketchfab_view.html'

    def form_template(self, context, data_dict):
        return 'sketchfab_form.html'

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

        # Model URL can either be specified in the view,
        # or defaults to use the resource URL
        model_url = data_dict['resource_view'].get('model_url') or data_dict[
            'resource'
        ].get('url')

        # Replace embed if it exists - added in template anyway
        model_url = re.sub('/embed$', '', model_url)

        return {'defaults': {'width': 940, 'height': 600}, 'model_url': model_url}

setup_template_variables(context, data_dict)

Setup variables available to templates.

Source code in ckanext/sketchfab/plugin.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def setup_template_variables(self, context, data_dict):
    """
    Setup variables available to templates.
    """

    # Model URL can either be specified in the view,
    # or defaults to use the resource URL
    model_url = data_dict['resource_view'].get('model_url') or data_dict[
        'resource'
    ].get('url')

    # Replace embed if it exists - added in template anyway
    model_url = re.sub('/embed$', '', model_url)

    return {'defaults': {'width': 940, 'height': 600}, 'model_url': model_url}