def package_update(context, data_dict): ''' Updates the dataset. Extends ckan's similar method to instantly re-index the SOLR index. Otherwise the changes would only be added during a re-index (a rebuild of search index, to be specific). :type context: dict :param context: context :type data_dict: dict :param data_dict: dataset as dictionary :rtype: dictionary ''' # Get all resources here since we get only 'dataset' resources from WUI. package_context = {'model': model, 'ignore_auth': True, 'validate': True, 'extras_as_string': True} user = model.User.get(context['user']) if not user.name == "harvest": _remove_extras_from_data_dict(data_dict) package_data = package_show(package_context, data_dict) if not 'resources' in data_dict: # When this is reached, we are updating a dataset, not creating a new resource old_resources = package_data.get('resources', []) data_dict['resources'] = old_resources data_dict = utils.dataset_to_resource(data_dict) else: data_dict['accept-terms'] = 'yes' # This is not needed when adding a resource _handle_pids(data_dict) _add_ida_download_url(data_dict) if asbool(data_dict.get('private')) and not data_dict.get('persist_schema'): context['schema'] = Schemas.private_package_schema() data_dict.pop('persist_schema', False) if package_data.get('type') == 'harvest': context['schema'] = Schemas.harvest_source_update_package_schema() pkg_dict1 = ckan.logic.action.update.package_update(context, data_dict) # Logging for production use _log_action('Package', 'update', context['user'], data_dict['id']) context = {'model': model, 'ignore_auth': True, 'validate': False, 'extras_as_string': True} pkg_dict = ckan.logic.action.get.package_show(context, pkg_dict1) index = index_for('package') # update_dict calls index_package, so it would basically be the same index.update_dict(pkg_dict) return pkg_dict1
def package_update(context, data_dict): ''' Updates the dataset. Extends ckan's similar method to instantly re-index the SOLR index. Otherwise the changes would only be added during a re-index (a rebuild of search index, to be specific). :type context: dict :param context: context :type data_dict: dict :param data_dict: dataset as dictionary :rtype: dictionary ''' # Get all resources here since we get only 'dataset' resources from WUI. package_context = {'model': model, 'ignore_auth': True, 'validate': True, 'extras_as_string': True} package_data = package_show(package_context, data_dict) # package_data = ckan.logic.action.get.package_show(package_context, data_dict) old_resources = package_data.get('resources', []) if not 'resources' in data_dict: # When this is reached, we are updating a dataset, not creating a new resource data_dict['resources'] = old_resources data_dict = utils.dataset_to_resource(data_dict) else: data_dict['accept-terms'] = 'yes' # This is not needed when adding a resource _handle_pids(context, data_dict) _add_ida_download_url(context, data_dict) # # Check if data version has changed and if so, generate a new version_PID # if not data_dict['version'] == temp_pkg_dict['version']: # data_dict['pids'].append( # { # u'provider': u'kata', # u'id': utils.generate_pid(), # u'type': u'version', # }) if asbool(data_dict.get('private')) and not data_dict.get('persist_schema'): context['schema'] = Schemas.private_package_schema() data_dict.pop('persist_schema', False) if package_data.get('type') == 'harvest': context['schema'] = Schemas.harvest_source_update_package_schema() pkg_dict1 = ckan.logic.action.update.package_update(context, data_dict) # Logging for production use _log_action('Package', 'update', context['user'], data_dict['id']) context = {'model': model, 'ignore_auth': True, 'validate': False, 'extras_as_string': True} pkg_dict = ckan.logic.action.get.package_show(context, pkg_dict1) index = index_for('package') # update_dict calls index_package, so it would basically be the same index.update_dict(pkg_dict) return pkg_dict1
def package_update(context, data_dict): ''' Updates the dataset. Extends ckan's similar method to instantly re-index the SOLR index. Otherwise the changes would only be added during a re-index (a rebuild of search index, to be specific). :type context: dict :param context: context :type data_dict: dict :param data_dict: dataset as dictionary :rtype: dictionary ''' # Get all resources here since we get only 'dataset' resources from WUI. package_context = {'model': model, 'ignore_auth': True, 'validate': True, 'extras_as_string': True} package_data = package_show(package_context, data_dict) # package_data = ckan.logic.action.get.package_show(package_context, data_dict) old_resources = package_data.get('resources', []) if not 'resources' in data_dict: # When this is reached, we are updating a dataset, not creating a new resource data_dict['resources'] = old_resources data_dict = utils.dataset_to_resource(data_dict) _handle_pids(context, data_dict) _add_ida_download_url(context, data_dict) # # Check if data version has changed and if so, generate a new version_PID # if not data_dict['version'] == temp_pkg_dict['version']: # data_dict['pids'].append( # { # u'provider': u'kata', # u'id': utils.generate_pid(), # u'type': u'version', # }) # This fixes extras fields being cleared when adding a resource. This is be because the extras are not properly # cleared in show_package_schema conversions. Some fields stay in extras and they cause all other fields to be # dropped in package_update(). When updating a dataset via UI or API, the conversion to extras occur in # package_update() and popping extras here should have no effect. data_dict.pop('extras', None) # TODO: MIKKO: Get rid of popping extras here and rather pop the additional extras in converters so we could remove the # popping and the above "context['allow_partial_update'] = True" which causes the extras to be processed in a way # that nothing gets added to extras from the converters and everything not initially present in extras gets removed. # TODO: JUHO: Apply correct schema depending on dataset # This is quick resolution. More robust way would be to check through # model.Package to which harvest source the dataset belongs and then get the # type of the harvester (eg. DDI) # if data_dict['name'].startswith('FSD'): # context['schema'] = schemas.update_package_schema_ddi() if package_data.get('type') == 'harvest': context['schema'] = Schemas.harvest_source_update_package_schema() pkg_dict1 = ckan.logic.action.update.package_update(context, data_dict) # Logging for production use _log_action('Package', 'update', context['user'], data_dict['id']) context = {'model': model, 'ignore_auth': True, 'validate': False, 'extras_as_string': True} pkg_dict = ckan.logic.action.get.package_show(context, pkg_dict1) index = index_for('package') # update_dict calls index_package, so it would basically be the same index.update_dict(pkg_dict) return pkg_dict1