Skip to content

Commit

Permalink
[#2750] example_idatasetform use toolkit not logic
Browse files Browse the repository at this point in the history
Use ckan.plugins.toolkit instead of ckan.logic in ckanext/example_idatasetform
  • Loading branch information
Sean Hammond committed Feb 26, 2013
1 parent d1f557c commit 9808ed4
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions ckanext/example_idatasetform/plugin.py
Expand Up @@ -4,7 +4,6 @@
import ckan.plugins.toolkit as toolkit
import ckan.lib.plugins as lib_plugins
import ckan.lib.navl.validators as validators
import ckan.logic as logic
import ckan.logic.converters as converters


Expand Down Expand Up @@ -36,21 +35,21 @@ def create_country_codes(self):
possible dataset country code values) using the API.
'''
user = logic.get_action('get_site_user')({'ignore_auth': True}, {})
user = toolkit.get_action('get_site_user')({'ignore_auth': True}, {})
context = {'user': user['name']}
try:
data = {'id': 'country_codes'}
logic.get_action('vocabulary_show')(context, data)
toolkit.get_action('vocabulary_show')(context, data)
logging.info("Example genre vocabulary already exists, skipping.")
except logic.NotFound:
except toolkit.ObjectNotFound:
logging.info("Creating vocab 'country_codes'")
data = {'name': 'country_codes'}
vocab = logic.get_action('vocabulary_create')(context, data)
vocab = toolkit.get_action('vocabulary_create')(context, data)
for tag in (u'uk', u'ie', u'de', u'fr', u'es'):
logging.info(
"Adding tag {0} to vocab 'country_codes'".format(tag))
data = {'name': tag, 'vocabulary_id': vocab['id']}
logic.get_action('tag_create')(context, data)
toolkit.get_action('tag_create')(context, data)

def update_config(self, config):
# Add this plugin's templates dir to CKAN's extra_template_paths, so
Expand Down Expand Up @@ -83,7 +82,7 @@ def db_to_form_schema(self):

# Don't show vocab tags mixed in with normal 'free' tags
# (e.g. on dataset pages, or on the search page)
schema['tags']['__extras'].append(logic.converters.free_tags_only)
schema['tags']['__extras'].append(converters.free_tags_only)

# Add our custom country_code metadata field to the schema.
schema.update({
Expand All @@ -104,9 +103,9 @@ def setup_template_variables(self, context, data_dict=None):
# Add the list of available country codes, from the country_codes
# vocab, to the template context.
try:
toolkit.c.country_codes = logic.get_action('tag_list')(
toolkit.c.country_codes = toolkit.get_action('tag_list')(
context, {'vocabulary_id': 'country_codes'})
except logic.NotFound:
except toolkit.ObjectNotFound:
toolkit.c.country_codes = None

# These methods just record how many times they're called, for testing
Expand Down

0 comments on commit 9808ed4

Please sign in to comment.