def qa_package_openness_show(context, data_dict): ''' Returns the QA score for a package, aggregating the scores of its resources. ''' model = context['model'] session = context['session'] p.toolkit.check_access('qa_package_openness_show', context, data_dict) dataset_id = p.toolkit.get_or_bust(data_dict, 'id') dataset = session.query(model.Package).get(dataset_id) if not dataset: raise p.toolkit.ObjectNotFound qa_objs = QA.get_for_package(dataset.id) qa_dict = aggregate_qa_for_a_dataset(qa_objs) return qa_dict
def qa_package_openness_show(context, data_dict): ''' Returns the QA score for a package, aggregating the scores of its resources. ''' model = context['model'] session = context['session'] p.toolkit.check_access('qa_package_openness_show', context, data_dict) dataset_id = p.toolkit.get_or_bust(data_dict, 'id') dataset = session.query(model.Package).get(dataset_id) if not dataset: raise p.toolkit.ObjectNotFound qa_objs = QA.get_for_package(dataset.id) qa_dict = aggregate_qa_for_a_dataset(qa_objs) return qa_dict
def after_show(self, context, pkg_dict): # Insert the qa 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. qa_objs = QA.get_for_package(pkg_dict['id']) if not qa_objs: return # dataset dataset_qa = aggregate_qa_for_a_dataset(qa_objs) pkg_dict['qa'] = dataset_qa # resources qa_by_res_id = dict((a.resource_id, a) for a in qa_objs) for res in pkg_dict['resources']: qa = qa_by_res_id.get(res['id']) if qa: qa_dict = qa.as_dict() del qa_dict['id'] del qa_dict['package_id'] del qa_dict['resource_id'] res['qa'] = qa_dict
def after_show(self, context, pkg_dict): # Insert the qa 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. qa_objs = QA.get_for_package(pkg_dict['id']) if not qa_objs: return # dataset dataset_qa = aggregate_qa_for_a_dataset(qa_objs) pkg_dict['qa'] = dataset_qa # resources qa_by_res_id = dict((a.resource_id, a) for a in qa_objs) for res in pkg_dict['resources']: qa = qa_by_res_id.get(res['id']) if qa: qa_dict = qa.as_dict() del qa_dict['id'] del qa_dict['package_id'] del qa_dict['resource_id'] res['qa'] = qa_dict