diff --git a/ckanext/harvest/helpers.py b/ckanext/harvest/helpers.py index c9e1331..6409445 100644 --- a/ckanext/harvest/helpers.py +++ b/ckanext/harvest/helpers.py @@ -63,3 +63,19 @@ def harvest_frequencies(): return [{'text': p.toolkit._(f.title()), 'value': f} for f in UPDATE_FREQUENCIES] + +def link_for_harvest_object(id=None, guid=None, text=None): + + if not id and not guid: + return None + + if guid: + context = {'model': model, 'user': p.toolkit.c.user or p.toolkit.c.author} + obj =logic.get_action('harvest_object_show')(context, {'id': guid, 'attr': 'guid'}) + id = obj.id + + url = h.url_for('harvest_object_show', id=id) + text = text or guid or id + link = '{text}'.format(url=url, text=text) + + return p.toolkit.literal(link) diff --git a/ckanext/harvest/plugin.py b/ckanext/harvest/plugin.py index bc087a3..690aeef 100644 --- a/ckanext/harvest/plugin.py +++ b/ckanext/harvest/plugin.py @@ -214,7 +214,7 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm): map.connect('harvesting_job_create', '/harvest/refresh/:id',controller=controller, action='create_harvesting_job') - map.connect('/harvest/object/:id', controller=controller, action='show_object') + map.connect('harvest_object_show', '/harvest/object/:id', controller=controller, action='show_object') map.connect('harvest_job_show_last', '/' + DATASET_TYPE_NAME + '/{source}/job/last', controller=controller, action='show_last_job') map.connect('harvest_job_show', '/' + DATASET_TYPE_NAME + '/{source}/job/{id}', controller=controller, action='show_job') @@ -260,6 +260,7 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm): 'harvesters_info': harvest_helpers.harvesters_info, 'harvester_types': harvest_helpers.harvester_types, 'harvest_frequencies': harvest_helpers.harvest_frequencies, + 'link_for_harvest_object': harvest_helpers.link_for_harvest_object, }