def archive_children_of_cube(key, data, errors, context): """ Apply archive date and status to children of the cube for which ID is provided """ if errors[key]: return if key != (u'archive_status_code',): return dataset_type = _data_lookup((u'type',), data) if dataset_type != 'cube': return cube_archive_status_code = _data_lookup((u'archive_status_code',), data) if cube_archive_status_code is missing or not cube_archive_status_code: return cube_id = _data_lookup((u'product_id_new',), data) child_list = h.get_child_datasets(cube_id) lc = ckanapi.LocalCKAN(context=context) for child in child_list: update = False child_archive_status_code = child.get(u'archive_status_code') if child_archive_status_code != cube_archive_status_code: child[u'archive_status_code'] = cube_archive_status_code update = True cube_archive_date = _data_lookup((u'archive_date',), data) if cube_archive_date and cube_archive_date is not missing: child_archive_date = child.get(u'archive_date') if child_archive_date is missing or not child_archive_date: child[u'archive_date'] = cube_archive_date update = True if update: lc.action.package_update(**child)
def archive_children_of_cube(key, data, errors, context): """ Apply archive date and status to children of the cube for which ID is provided """ if errors[key]: return if key != (u'archive_status_code', ): return dataset_type = _data_lookup((u'type', ), data) if dataset_type != 'cube': return cube_archive_status_code = _data_lookup((u'archive_status_code', ), data) if cube_archive_status_code is missing or not cube_archive_status_code: return cube_id = _data_lookup((u'product_id_new', ), data) child_list = h.get_child_datasets(cube_id) lc = ckanapi.LocalCKAN(context=context) for child in child_list: update = False child_archive_status_code = child.get(u'archive_status_code') if child_archive_status_code != cube_archive_status_code: child[u'archive_status_code'] = cube_archive_status_code update = True cube_archive_date = _data_lookup((u'archive_date', ), data) if cube_archive_date and cube_archive_date is not missing: child_archive_date = child.get(u'archive_date') if child_archive_date is missing or not child_archive_date: child[u'archive_date'] = cube_archive_date update = True if update: lc.action.package_update(**child)
def ndm_child_inherits_value(key, data, errors, context): """ Children of the dataset inherit the value of the given field :param key: :param data: :param errors: :param context: :return: """ if errors[key]: return product_name = _data_lookup(('name',), data) if not product_name: product_create_name(('name',), data, errors, context) if errors[('name',)]: return else: product_name = _data_lookup(('name',), data) product_id = _data_lookup(('product_id_new',), data) if not product_id or product_id is missing: create_product_id(('product_id_new',), data, errors, context) if errors[('product_id_new',)]: return else: product_id = _data_lookup(('product_id_new',), data) dataset_type = _data_lookup((u'type',), data) if not dataset_type: errors[key].append(u'{name}: missing dataset_type'.format( name=product_name )) return lc = ckanapi.LocalCKAN(context=context) if dataset_type in [u'publication', u'cube']: children = h.get_child_datasets(product_id) for child in children: if child.get(u'type') == u'format': continue child[unicode(key[0])] = data[key] lc.action.package_update(**child)
def ndm_child_inherits_value(key, data, errors, context): """ Children of the dataset inherit the value of the given field :param key: :param data: :param errors: :param context: :return: """ if errors[key]: return product_name = _data_lookup(('name', ), data) if not product_name: product_create_name(('name', ), data, errors, context) if errors[('name', )]: return else: product_name = _data_lookup(('name', ), data) product_id = _data_lookup(('product_id_new', ), data) if not product_id or product_id is missing: create_product_id(('product_id_new', ), data, errors, context) if errors[('product_id_new', )]: return else: product_id = _data_lookup(('product_id_new', ), data) dataset_type = _data_lookup((u'type', ), data) if not dataset_type: errors[key].append( u'{name}: missing dataset_type'.format(name=product_name)) return lc = ckanapi.LocalCKAN(context=context) if dataset_type in [u'publication', u'cube']: children = h.get_child_datasets(product_id) for child in children: if child.get(u'type') == u'format': continue child[unicode(key[0])] = data[key] lc.action.package_update(**child)