From b676fb02e1d3b33afad367d24188e19339cb5faf Mon Sep 17 00:00:00 2001 From: kindly Date: Thu, 21 Mar 2013 02:31:34 +0000 Subject: [PATCH] only get out harvest items in interface and when indexing --- ckanext/harvest/plugin.py | 41 +++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/ckanext/harvest/plugin.py b/ckanext/harvest/plugin.py index 64c8ee7..868a9a0 100644 --- a/ckanext/harvest/plugin.py +++ b/ckanext/harvest/plugin.py @@ -54,16 +54,28 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm): # Delete the actual HarvestSource object _delete_harvest_source_object(context, package_dict) + def before_view(self, data_dict): + + if not 'type' in data_dict or data_dict['type'] != DATASET_TYPE_NAME: + # This is a normal dataset, check if it was harvested and if so, add + # info about the HarvestObject and HarvestSource + harvest_object = model.Session.query(HarvestObject) \ + .filter(HarvestObject.package_id==data_dict['id']) \ + .filter(HarvestObject.current==True) \ + .first() + + if harvest_object: + for key, value in [ + ('harvest_object_id', harvest_object.id), + ('harvest_source_id', harvest_object.source.id), + ('harvest_source_title', harvest_object.source.title), + ]: + _add_extra(data_dict, key, value) + return data_dict + + def after_show(self, context, data_dict): - def add_extra(data_dict, key, value): - if not 'extras' in data_dict: - data_dict['extras'] = [] - - data_dict['extras'].append({ - 'key': key, 'value': value, 'state': u'active' - }) - if 'type' in data_dict and data_dict['type'] == DATASET_TYPE_NAME: # This is a harvest source dataset, add extra info from the # HarvestSource object @@ -83,13 +95,14 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm): .filter(HarvestObject.current==True) \ .first() - if harvest_object: + # validate is false is passed only on indexing. + if harvest_object and not context.get('validate', True): for key, value in [ ('harvest_object_id', harvest_object.id), ('harvest_source_id', harvest_object.source.id), ('harvest_source_title', harvest_object.source.title), ]: - add_extra(data_dict, key, value) + _add_extra(data_dict, key, value) return data_dict @@ -272,6 +285,14 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm): ('source_type','Type'), ]) +def _add_extra(data_dict, key, value): + if not 'extras' in data_dict: + data_dict['extras'] = [] + + data_dict['extras'].append({ + 'key': key, 'value': value, 'state': u'active' + }) + def _get_logic_functions(module_root, logic_functions = {}): for module_name in ['get', 'create', 'update','delete']: