Skip to content

Commit

Permalink
[#2750] Add DefaultDatasetForm to plugins toolkit
Browse files Browse the repository at this point in the history
At DefaultDatasetForm to the plugins toolkit. This means that
IDatasetForm plugins based on DefaultDatasetForm no longer need to
import ckan.lib.plugins.

Also change ExampleIDatasetForm to no longer import ckan.lib.plugins.
  • Loading branch information
Sean Hammond committed Mar 15, 2013
1 parent 1198007 commit 0221455
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions ckan/plugins/toolkit.py
Expand Up @@ -51,6 +51,7 @@ class _Toolkit(object):
'UnknownValidator', # validator not found exception
'ValidationError', # model update validation error
'CkanCommand', # class for providing cli interfaces
'DefaultDatasetForm', # base class for IDatasetForm plugins

## Fully defined in this file ##
'add_template_directory',
Expand All @@ -72,6 +73,7 @@ def _initialize(self):
import ckan.lib.base as base
import ckan.logic as logic
import ckan.lib.cli as cli
import ckan.lib.plugins as lib_plugins

# Allow class access to these modules
self.__class__.ckan = ckan
Expand Down Expand Up @@ -101,6 +103,7 @@ def _initialize(self):
t['UnknownValidator'] = logic.UnknownValidator

t['CkanCommand'] = cli.CkanCommand
t['DefaultDatasetForm'] = lib_plugins.DefaultDatasetForm

# class functions
t['render_snippet'] = self._render_snippet
Expand Down
17 changes: 8 additions & 9 deletions ckanext/example_idatasetform/plugin.py
Expand Up @@ -2,11 +2,10 @@

import ckan.plugins as plugins
import ckan.plugins.toolkit as tk
import ckan.lib.plugins as lib_plugins


class ExampleIDatasetFormPlugin(plugins.SingletonPlugin,
lib_plugins.DefaultDatasetForm):
tk.DefaultDatasetForm):
'''An example IDatasetForm CKAN plugin.
Uses a tag vocabulary to add a custom metadata field to datasets.
Expand Down Expand Up @@ -128,31 +127,31 @@ def setup_template_variables(self, context, data_dict=None):

def new_template(self):
ExampleIDatasetFormPlugin.num_times_new_template_called += 1
return lib_plugins.DefaultDatasetForm.new_template(self)
return tk.DefaultDatasetForm.new_template(self)

def read_template(self):
ExampleIDatasetFormPlugin.num_times_read_template_called += 1
return lib_plugins.DefaultDatasetForm.read_template(self)
return tk.DefaultDatasetForm.read_template(self)

def edit_template(self):
ExampleIDatasetFormPlugin.num_times_edit_template_called += 1
return lib_plugins.DefaultDatasetForm.edit_template(self)
return tk.DefaultDatasetForm.edit_template(self)

def comments_template(self):
ExampleIDatasetFormPlugin.num_times_comments_template_called += 1
return lib_plugins.DefaultDatasetForm.comments_template(self)
return tk.DefaultDatasetForm.comments_template(self)

def search_template(self):
ExampleIDatasetFormPlugin.num_times_search_template_called += 1
return lib_plugins.DefaultDatasetForm.search_template(self)
return tk.DefaultDatasetForm.search_template(self)

def history_template(self):
ExampleIDatasetFormPlugin.num_times_history_template_called += 1
return lib_plugins.DefaultDatasetForm.history_template(self)
return tk.DefaultDatasetForm.history_template(self)

def package_form(self):
ExampleIDatasetFormPlugin.num_times_package_form_called += 1
return lib_plugins.DefaultDatasetForm.package_form(self)
return tk.DefaultDatasetForm.package_form(self)

# check_data_dict() is deprecated, this method is only here to test that
# legacy support for the deprecated method works.
Expand Down

0 comments on commit 0221455

Please sign in to comment.