diff --git a/ckanext/harvest/logic/action/patch.py b/ckanext/harvest/logic/action/patch.py new file mode 100644 index 0000000..9e6d79b --- /dev/null +++ b/ckanext/harvest/logic/action/patch.py @@ -0,0 +1,58 @@ +'''API functions for partial updates of existing data in CKAN''' + +import logging +from ckan.logic import get_action +from ckanext.harvest.plugin import DATASET_TYPE_NAME + +log = logging.getLogger(__name__) + + +def harvest_source_patch(context, data_dict): + ''' + Patch an existing harvest source + + This method just proxies the request to package_patch, + which will update a harvest_source dataset type and the + HarvestSource object. All auth checks and validation will + be done there. We only make sure to set the dataset type. + + Note that the harvest source type (ckan, waf, csw, etc) + is now set via the source_type field. + + All fields that are not provided, will be stay as they were before. + + :param id: the name or id of the harvest source to update + :type id: string + :param url: the URL for the harvest source + :type url: string + :param name: the name of the new harvest source, must be between 2 and 100 + characters long and contain only lowercase alphanumeric characters + :type name: string + :param title: the title of the dataset (optional, default: same as + ``name``) + :type title: string + :param notes: a description of the harvest source (optional) + :type notes: string + :param source_type: the harvester type for this source. This must be one + of the registerd harvesters, eg 'ckan', 'csw', etc. + :type source_type: string + :param frequency: the frequency in wich this harvester should run. See + ``ckanext.harvest.model`` source for possible values. Default is + 'MANUAL' + :type frequency: string + :param config: extra configuration options for the particular harvester + type. Should be a serialized as JSON. (optional) + :type config: string + + :returns: the updated harvest source + :rtype: dictionary + ''' + log.info('Patch harvest source: %r', data_dict) + + data_dict['type'] = DATASET_TYPE_NAME + + context['extras_as_string'] = True + source = get_action('package_patch')(context, data_dict) + + return source + diff --git a/ckanext/harvest/logic/auth/patch.py b/ckanext/harvest/logic/auth/patch.py new file mode 100644 index 0000000..17e297f --- /dev/null +++ b/ckanext/harvest/logic/auth/patch.py @@ -0,0 +1,3 @@ +import ckanext.harvest.logic.auth.update as _update + +harvest_source_patch = _update.harvest_source_update diff --git a/ckanext/harvest/plugin.py b/ckanext/harvest/plugin.py index 30bd814..890a6ce 100644 --- a/ckanext/harvest/plugin.py +++ b/ckanext/harvest/plugin.py @@ -287,7 +287,7 @@ def _add_extra(data_dict, key, value): def _get_logic_functions(module_root, logic_functions = {}): - for module_name in ['get', 'create', 'update','delete']: + for module_name in ['get', 'create', 'update', 'patch', 'delete']: module_path = '%s.%s' % (module_root, module_name,) module = __import__(module_path)