[ckan-dev] 2.2 extension not working in 2.4
    David Hernández Gutiérrez 
    davisoski at gmail.com
       
    Thu Nov  5 23:50:12 UTC 2015
    
    
  
Fixed.
The code is no longer valid in 2.4.
Used The code in the last docs, which is a liittle bit diferent.
Thanks
---------- Mensaje reenviado ----------
De: "David" <davisoski at gmail.com>
Fecha: 5/11/2015 20:14
Asunto: 2.2 extension not working in 2.4
Para: <ckan-dev at lists.okfn.org>
Cc:
Hi.
I have been using this piece of code to show most popular groups in version
2.2
Now I have updated to 2.4 and it seems not work properly
*plugin.py*
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
def most_popular_groups():
    '''Return a sorted list of the groups with the most datasets.'''
    # Get a list of all the site's groups from CKAN, sorted by number of
    # datasets.
    groups = toolkit.get_action('group_list')(
            data_dict={'sort': 'packages desc', 'all_fields': True})
    # Truncate the list to the 10 most popular groups only.
    # groups = groups[:10]
    return groups
class MyPlugin(plugins.SingletonPlugin):
    '''
    # Declare that this class implements IConfigurer.
    plugins.implements(plugins.IConfigurer)
    # Declare that this plugin will implement ITemplateHelpers.
    plugins.implements(plugins.ITemplateHelpers)
    def update_config(self, config):
        # Add this plugin's templates dir to CKAN's extra_template_paths, so
        # that CKAN will use this plugin's custom templates.
        toolkit.add_template_directory(config, 'templates')
        # Add this plugin's public dir to CKAN's extra_public_paths, so
        # that CKAN will use this plugin's custom static files.
        toolkit.add_public_directory(config, 'public')
    def get_helpers(self):
        '''Register the most_popular_groups() function above as a template
        helper function.
        '''
        # Template helper function names should begin with the name of the
        # extension they belong to, to avoid clashing with functions from
        # other extensions.
        return {'my_most_popular_groups': most_popular_groups}
---------------------------------------------------------------------------------------------------------------------------------
*Now in version 2.4*
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
def most_popular_groups():
    '''Return a sorted list of the groups with the most datasets.'''
    # Get a list of all the site's groups from CKAN, sorted by number of
    # datasets.
    groups = toolkit.get_action('group_list')(
            data_dict={'sort': 'packages desc', 'all_fields': True})
    # Truncate the list to the 10 most popular groups only.
    # groups = groups[:10]
    return groups
class MyPlugin(plugins.SingletonPlugin):
    # IConfigurer
    plugins.implements(plugins.IConfigurer)
    # Declare that this plugin will implement ITemplateHelpers.
    plugins.implements(plugins.ITemplateHelpers)
    def update_config(self, config_):
        toolkit.add_template_directory(config_, 'templates')
        toolkit.add_public_directory(config_, 'public')
    def get_helpers(self):
        '''Register the most_popular_groups() function above (arriba) as
           a template  helper function.
        '''
        # Template helper function names should begin with the name of the
        # extension they belong to, to avoid clashing with functions from
        # other extensions.
        return {'my_most_popular_groups': most_popular_groups}
Setup.py have changed in version 2.4, but I can't understand where is the
problem. The rest of the installation works ok .
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20151105/5d3c1923/attachment-0003.html>
    
    
More information about the ckan-dev
mailing list