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 qa_package_broken_show(context, data_dict): ''' Returns the Archival is_broken information for a package, aggregating across its resources. is_broken - True (all), 'some', False or None (not sure) ''' model = context['model'] session = context['session'] #user = context.get('user') #p.toolkit.check_access('qa_package_broken_show', context, data_dict) pkg_id = p.toolkit.get_or_bust(data_dict, 'id') pkg = session.query(model.Package).get(pkg_id) if not pkg: raise p.toolkit.ObjectNotFound if pkg.resources: # Are any broken? any_resources_broken = False any_resources_ok = False for archival in Archival.get_for_package(pkg_id): if archival.is_broken is True: any_resources_broken = True elif archival.is_broken is False: any_resources_ok = True if any_resources_broken and any_resources_ok: is_broken = 'some' # i.e. some broken elif any_resources_broken: is_broken = True # all broken elif any_resources_ok: is_broken = False # all ok else: is_broken = None # not sure / not recorded else: is_broken = False return {'name': pkg.name, 'title': pkg.title, 'id': pkg.id, 'archival_is_broken': is_broken, }
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