[#5] Add helper function for generating a link to a harvest object

This commit is contained in:
amercader 2013-01-24 18:21:05 +00:00
parent daa9a385ff
commit d4b6dcb7f6
2 changed files with 18 additions and 1 deletions

View File

@ -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 = '<a href="{url}">{text}</a>'.format(url=url, text=text)
return p.toolkit.literal(link)

View File

@ -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,
}