Skip to content

Plugin

TwitterPlugin ΒΆ

Bases: SingletonPlugin

Automatically send tweets when a dataset is updated or created.

Source code in ckanext/twitter/plugin.py
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
class TwitterPlugin(SingletonPlugin):
    """
    Automatically send tweets when a dataset is updated or created.
    """

    implements(interfaces.IConfigurable, inherit=True)
    implements(interfaces.IConfigurer)
    implements(interfaces.IPackageController, inherit=True)
    implements(interfaces.ITemplateHelpers, inherit=True)
    implements(interfaces.IBlueprint, inherit=True)

    # IConfigurable
    def configure(self, config):
        cache_regions.update(
            {
                'twitter': {
                    'expire': ckanext.twitter.lib.config_helpers.twitter_hours_between_tweets(),
                    'type': 'memory',
                    'enabled': True,
                    'key_length': 250,
                }
            }
        )

    # IConfigurer
    def update_config(self, config):
        # Add templates
        toolkit.add_template_directory(config, 'theme/templates')
        # Add resources
        toolkit.add_resource('theme/assets', 'ckanext-twitter')

    # IPackageController
    def after_update(self, context, pkg_dict):
        is_suitable = twitter_helpers.twitter_pkg_suitable(context, pkg_dict['id'])
        if is_suitable:
            session.setdefault('twitter_is_suitable', pkg_dict['id'])
            session.save()

    # ITemplateHelpers
    def get_helpers(self):
        js_helpers = twitter_helpers.TwitterJSHelpers()
        return {
            'tweet_ready': js_helpers.tweet_ready,
            'get_tweet': js_helpers.get_tweet,
            'disable_edit': config_helpers.twitter_disable_edit,
        }

    ## IBlueprint
    def get_blueprint(self):
        return routes.blueprints