def after_dataset_show(self, context, pkg_dict): # Insert the archival info into the package_dict so that it is # available on the API. # When you edit the dataset, these values will not show in the form, # it they will be saved in the resources (not the dataset). I can't see # and easy way to stop this, but I think it is harmless. It will get # overwritten here when output again. archivals = Archival.get_for_package(pkg_dict['id']) if not archivals: return # dataset dataset_archival = aggregate_archivals_for_a_dataset(archivals) pkg_dict['archiver'] = dataset_archival # resources archivals_by_res_id = dict((a.resource_id, a) for a in archivals) for res in pkg_dict['resources']: archival = archivals_by_res_id.get(res['id']) if archival: archival_dict = archival.as_dict() del archival_dict['id'] del archival_dict['package_id'] del archival_dict['resource_id'] res['archiver'] = archival_dict
def archiver_dataset_show(context, data_dict=None): '''Return a details of the archival of a dataset, aggregated across its resources. :param id: the name or id of the dataset :type id: string :rtype: dictionary ''' id_ = _get_or_bust(data_dict, 'id') dataset = model.Package.get(id_) if not dataset: raise ObjectNotFound archivals = Archival.get_for_package(dataset.id) archival_dict = aggregate_archivals_for_a_dataset(archivals) p.toolkit.check_access('archiver_dataset_show', context, data_dict) return archival_dict
def after_show(self, context, pkg_dict): # Insert the archival info into the package_dict so that it is # available on the API. # When you edit the dataset, these values will not show in the form, # it they will be saved in the resources (not the dataset). I can't see # and easy way to stop this, but I think it is harmless. It will get # overwritten here when output again. archivals = Archival.get_for_package(pkg_dict['id']) if not archivals: return # dataset dataset_archival = aggregate_archivals_for_a_dataset(archivals) pkg_dict['archiver'] = dataset_archival # resources archivals_by_res_id = dict((a.resource_id, a) for a in archivals) for res in pkg_dict['resources']: archival = archivals_by_res_id.get(res['id']) if archival: archival_dict = archival.as_dict() del archival_dict['id'] del archival_dict['package_id'] del archival_dict['resource_id'] res['archiver'] = archival_dict