Skip to content

Commit

Permalink
[#1183] Remove datapusher_enabled action and move before_show to dats…
Browse files Browse the repository at this point in the history
…tore. Instead of using the action or the template helper, check whether the plugin is enabled. Moved the action so that changing the url works even if the datapusher is disabled.
  • Loading branch information
domoritz committed Aug 25, 2013
1 parent 91f6a38 commit ef7b3e9
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 45 deletions.
4 changes: 3 additions & 1 deletion ckan/templates/package/resource_read.html
Expand Up @@ -27,7 +27,9 @@
<ul>
{% block resource_actions_inner %}
{% if h.check_access('package_update', {'id':pkg.id }) %}
<li>{% snippet 'snippets/datapusher_status.html', resource=res %}</li>
{% if 'datapusher' in g.plugins %}
<li>{% snippet 'snippets/datapusher_status.html', resource=res %}</li>
{% endif %}
<li>{% link_for _('Edit'), controller='package', action='resource_edit', id=pkg.name, resource_id=res.id, class_='btn', icon='wrench' %}</li>
{% endif %}
{% if res.url %}
Expand Down
14 changes: 6 additions & 8 deletions ckan/templates/snippets/datapusher_status.html
Expand Up @@ -4,13 +4,11 @@

#}
{% if resource.datastore_active %}
{% if h.datapusher_enabled() %}
{% set job = h.datapusher_status(resource.id) %}
{% set title = _('Datapusher status: {status}.').format(status=job.status) %}
{% if job.status == 'unknown' %}
<i title="{{ _(title) }}" class="datapusher-status status-{{ job.status }} icon-circle icon-large"></i>
{% else %}
<a href="{{ job.job_url }}" class="datapusher-status-link" title="{{ _(title) }}"><i class="datapusher-status status-{{ job.status }} icon-circle icon-large"></i></a>
{% endif %}
{% set job = h.datapusher_status(resource.id) %}
{% set title = _('Datapusher status: {status}.').format(status=job.status) %}
{% if job.status == 'unknown' %}
<i title="{{ _(title) }}" class="datapusher-status status-{{ job.status }} icon-circle icon-large"></i>
{% else %}
<a href="{{ job.job_url }}" class="datapusher-status-link" title="{{ _(title) }}"><i class="datapusher-status status-{{ job.status }} icon-circle icon-large"></i></a>
{% endif %}
{% endif %}
4 changes: 0 additions & 4 deletions ckanext/datapusher/helpers.py
Expand Up @@ -9,7 +9,3 @@ def datapusher_status(resource_id):
return {
'status': 'unknown'
}


def datapusher_enabled():
return toolkit.get_action('datapusher_enabled')({})
10 changes: 0 additions & 10 deletions ckanext/datapusher/logic/action.py
Expand Up @@ -16,13 +16,6 @@
_validate = ckan.lib.navl.dictization_functions.validate


def datapusher_enabled(context, data_dict):
''' Returns True if the DataPusher is configured '''

datapusher_url = pylons.config.get('datapusher.url')
return True if datapusher_url else False


def datapusher_submit(context, data_dict):
''' Submit a job to the datapusher. The datapusher is a service that
imports tabular data into the datastore.
Expand Down Expand Up @@ -50,9 +43,6 @@ def datapusher_submit(context, data_dict):

p.toolkit.check_access('datapusher_submit', context, data_dict)

if not p.toolkit.get_action('datapusher_enabled')(context):
return False

datapusher_url = pylons.config.get('ckan.datapusher.url')

callback_url = p.toolkit.url_for(
Expand Down
24 changes: 8 additions & 16 deletions ckanext/datapusher/plugin.py
Expand Up @@ -23,7 +23,6 @@ class DatapusherPlugin(p.SingletonPlugin):
p.implements(p.IAuthFunctions)
p.implements(p.IResourceUrlChange)
p.implements(p.IDomainObjectModification, inherit=True)
p.implements(p.IResourceController, inherit=True)
p.implements(p.ITemplateHelpers)

legacy_mode = False
Expand All @@ -32,9 +31,14 @@ class DatapusherPlugin(p.SingletonPlugin):
def configure(self, config):
self.config = config

datapusher_formats = config.get('datapusher.formats', '').split()
datapusher_formats = config.get('ckan.datapusher.formats', '').split()
self.datapusher_formats = datapusher_formats or DEFAULT_FORMATS

datapusher_url = config.get('ckan.datapusher.url')
if not datapusher_url:
raise Exception(
'Config option `ckan.datapusher.url` has to be set.')

def notify(self, entity, operation=None):
if isinstance(entity, model.Resource):
if (operation == model.domain_object.DomainObjectOperation.new
Expand All @@ -54,26 +58,14 @@ def notify(self, entity, operation=None):
})

def get_actions(self):
return {'datapusher_enabled': action.datapusher_enabled,
'datapusher_submit': action.datapusher_submit,
return {'datapusher_submit': action.datapusher_submit,
'datapusher_hook': action.datapusher_hook,
'datapusher_status': action.datapusher_status}

def get_auth_functions(self):
return {'datapusher_submit': auth.datapusher_submit,
'datapusher_status': auth.datapusher_status}

def before_show(self, resource_dict):
''' Modify the resource url of datastore resources so that
they link to the datastore dumps.
'''
if resource_dict['url_type'] == 'datastore':
resource_dict['url'] = p.toolkit.url_for(
controller='ckanext.datastore.controller:DatastoreController',
action='dump', resource_id=resource_dict['id'])
return resource_dict

def get_helpers(self):
return {
'datapusher_status': helpers.datapusher_status,
'datapusher_enabled': helpers.datapusher_enabled}
'datapusher_status': helpers.datapusher_status}
17 changes: 12 additions & 5 deletions ckanext/datastore/logic/action.py
Expand Up @@ -88,20 +88,27 @@ def datastore_create(context, data_dict):

if 'resource' in data_dict:
has_url = 'url' in data_dict['resource']
data_dict['resource'].setdefault('url', '_tmp')
# A datastore only resource does not have a url in the db
data_dict['resource'].setdefault('url', '_datastore_only_resource')
res = p.toolkit.get_action('resource_create')(context,
data_dict['resource'])
data_dict['resource_id'] = res['id']

# create resource from file
if has_url:
p.toolkit.get_action('datapusher_submit')(context, {
'resource_id': res['id'],
'set_url_type': True
})
try:
p.toolkit.get_action('datapusher_submit')(context, {
'resource_id': res['id'],
'set_url_type': True
})
except KeyError:
raise p.toolkit.ValidationError({'resource': [
'The datapusher has to be enabled.']})

# since we'll overwrite the datastore resource anyway, we
# don't need to create it here
return

# create empty resource
else:
# no need to set the full url because it will be set in before_show
Expand Down
13 changes: 12 additions & 1 deletion ckanext/datastore/plugin.py
Expand Up @@ -25,6 +25,7 @@ class DatastorePlugin(p.SingletonPlugin):
p.implements(p.IResourceUrlChange)
p.implements(p.IDomainObjectModification, inherit=True)
p.implements(p.IRoutes, inherit=True)
p.implements(p.IResourceController, inherit=True)

legacy_mode = False
resource_show_action = None
Expand Down Expand Up @@ -250,4 +251,14 @@ def before_map(self, m):
m.connect('/datastore/dump/{resource_id}',
controller='ckanext.datastore.controller:DatastoreController',
action='dump')
return m
return m

def before_show(self, resource_dict):
''' Modify the resource url of datastore resources so that
they link to the datastore dumps.
'''
if resource_dict['url_type'] == 'datastore':
resource_dict['url'] = p.toolkit.url_for(
controller='ckanext.datastore.controller:DatastoreController',
action='dump', resource_id=resource_dict['id'])
return resource_dict

0 comments on commit ef7b3e9

Please sign in to comment.