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_create(context, data_dict): """ Creates a new dataset. Extends ckan's similar method to instantly reindex the SOLR index, so that this newly added package emerges in search results instantly instead of during the next timed reindexing. :param context: context :param data_dict: data dictionary (package data) :rtype: dictionary """ user = model.User.get(context['user']) if data_dict.get('type') == 'harvest' and not user.sysadmin: ckan.lib.base.abort(401, _('Unauthorized to add a harvest source')) if not user.name == "harvest": _remove_extras_from_data_dict(data_dict) data_dict = utils.dataset_to_resource(data_dict) if not user.name == 'harvest': _handle_package_id_on_create(data_dict) _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 data_dict.get('type') == 'harvest': context['schema'] = Schemas.harvest_source_create_package_schema() pkg_dict1 = ckan.logic.action.create.package_create(context, data_dict) # Logging for production use _log_action('Package', 'create', context['user'], pkg_dict1['id']) context = {'model': model, 'ignore_auth': True, 'validate': False, 'extras_as_string': False} pkg_dict = ckan.logic.action.get.package_show(context, pkg_dict1) index = index_for('package') index.index_package(pkg_dict) return pkg_dict1
def package_create(context, data_dict): """ Creates a new dataset. Extends ckan's similar method to instantly reindex the SOLR index, so that this newly added package emerges in search results instantly instead of during the next timed reindexing. :param context: context :param data_dict: data dictionary (package data) :rtype: dictionary """ user = model.User.get(context['user']) if data_dict.get('type') == 'harvest' and not user.sysadmin: ckan.lib.base.abort(401, _('Unauthorized to add a harvest source')) data_dict = utils.dataset_to_resource(data_dict) _handle_pids(context, data_dict) _add_ida_download_url(context, 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 data_dict.get('type') == 'harvest': context['schema'] = Schemas.harvest_source_create_package_schema() pkg_dict1 = ckan.logic.action.create.package_create(context, data_dict) # Logging for production use _log_action('Package', 'create', context['user'], pkg_dict1['id']) context = {'model': model, 'ignore_auth': True, 'validate': False, 'extras_as_string': False} pkg_dict = ckan.logic.action.get.package_show(context, pkg_dict1) index = index_for('package') index.index_package(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