diff --git a/ckanext/example_idatasetform/plugin.py b/ckanext/example_idatasetform/plugin.py index 3da5dbf391d..2127c948b3c 100644 --- a/ckanext/example_idatasetform/plugin.py +++ b/ckanext/example_idatasetform/plugin.py @@ -4,6 +4,16 @@ import ckan.plugins.toolkit as tk +def country_codes(): + '''Return the list of country codes from the country codes vocabulary.''' + try: + country_codes = tk.get_action('tag_list')( + data_dict={'vocabulary_id': 'country_codes'}) + return country_codes + except tk.ObjectNotFound: + return None + + class ExampleIDatasetFormPlugin(plugins.SingletonPlugin, tk.DefaultDatasetForm): '''An example IDatasetForm CKAN plugin. @@ -13,6 +23,7 @@ class ExampleIDatasetFormPlugin(plugins.SingletonPlugin, ''' plugins.implements(plugins.IConfigurer, inherit=False) plugins.implements(plugins.IDatasetForm, inherit=False) + plugins.implements(plugins.ITemplateHelpers, inherit=False) # These record how many times methods that this plugin's methods are # called, for testing purposes. @@ -54,6 +65,9 @@ def update_config(self, config): # that CKAN will use this plugin's custom templates. tk.add_template_directory(config, 'templates') + def get_helpers(self): + return {'country_codes': country_codes} + def is_fallback(self): # Return True to register this plugin as the default handler for # package types not handled by any other IDatasetForm plugin. @@ -65,6 +79,10 @@ def package_types(self): return [] def form_to_db_schema(self): + + # Create the country_codes vocab and tags, if they don't already exist. + self.create_country_codes() + schema = super(ExampleIDatasetFormPlugin, self).form_to_db_schema() # Add our custom country_code metadata field to the schema. @@ -104,21 +122,6 @@ def db_to_form_schema(self): return schema - def setup_template_variables(self, context, data_dict=None): - super(ExampleIDatasetFormPlugin, self).setup_template_variables( - context, data_dict) - - # Create the country_codes vocab and tags, if they don't already exist. - self.create_country_codes() - - # Add the list of available country codes, from the country_codes - # vocab, to the template context. - try: - tk.c.country_codes = tk.get_action('tag_list')( - context, {'vocabulary_id': 'country_codes'}) - except tk.ObjectNotFound: - tk.c.country_codes = None - # These methods just record how many times they're called, for testing # purposes. # TODO: It might be better to test that custom templates returned by diff --git a/ckanext/example_idatasetform/templates/package/new_package_metadata.html b/ckanext/example_idatasetform/templates/package/new_package_metadata.html deleted file mode 100644 index dbe6af6871b..00000000000 --- a/ckanext/example_idatasetform/templates/package/new_package_metadata.html +++ /dev/null @@ -1,6 +0,0 @@ -{% ckan_extends %} - - -{% block form %}{{ h.snippet('package/snippets/package_metadata_form.html', data=data, errors=errors, include_metadata=false, pkg_name=pkg_name, country_codes=c.country_codes) }}{% endblock %} diff --git a/ckanext/example_idatasetform/templates/package/snippets/package_form.html b/ckanext/example_idatasetform/templates/package/snippets/package_form.html deleted file mode 100644 index 573f1333cbc..00000000000 --- a/ckanext/example_idatasetform/templates/package/snippets/package_form.html +++ /dev/null @@ -1,8 +0,0 @@ -{% ckan_extends %} - - -{% block metadata_fields %} - {% snippet 'package/snippets/package_metadata_fields.html', data=data, errors=errors, country_codes=c.country_codes %} -{% endblock %} diff --git a/ckanext/example_idatasetform/templates/package/snippets/package_metadata_fields.html b/ckanext/example_idatasetform/templates/package/snippets/package_metadata_fields.html index a5f82e2cc32..3232a60f6c6 100644 --- a/ckanext/example_idatasetform/templates/package/snippets/package_metadata_fields.html +++ b/ckanext/example_idatasetform/templates/package/snippets/package_metadata_fields.html @@ -27,7 +27,7 @@
diff --git a/ckanext/example_idatasetform/templates/package/snippets/package_metadata_form.html b/ckanext/example_idatasetform/templates/package/snippets/package_metadata_form.html deleted file mode 100644 index da95a2347bb..00000000000 --- a/ckanext/example_idatasetform/templates/package/snippets/package_metadata_form.html +++ /dev/null @@ -1,21 +0,0 @@ -{% import "macros/form.html" as form %} - -{% set data = data or {} %} -{% set errors = errors or {} %} - -
- {{ h.snippet('package/snippets/stages.html', stages=['complete', 'complete', 'active'], pkg_name=pkg_name) }} - {{ form.errors(error_summary) }} - - - {% snippet 'package/snippets/package_metadata_fields.html', data=data, errors=errors, groups_available=groups_available, country_codes=country_codes %} - -
- {# TODO: Go back to previous resource form #} - - -
- -