Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
 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
Beispiel #4
0
 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
Beispiel #5
0
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']
    #user = context.get('user')
    #p.toolkit.check_access('qa_package_openness_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:
        # Aggregate openness score
        best_score = None
        best_score_reason = None
        latest_update = None
        for qa in QA.get_for_package(pkg_id):
            if best_score is None or qa.openness_score > best_score:
                best_score = qa.openness_score
                best_score_reason = qa.openness_score_reason
            if not latest_update or qa.updated > latest_update:
                latest_update = qa.updated
    else:
        best_score = 0
        best_score_reason = 'Dataset has no resources.'
        latest_update = None
    return {'name': pkg.name,
            'title': pkg.title,
            'id': pkg.id,
            'openness_score': best_score,
            'openness_score_reason': best_score_reason,
            'updated': latest_update.isoformat() if latest_update else None,
            }