def aggregate_archivals_for_a_dataset(archivals): '''Returns aggregated archival info for a dataset, given the archivals for its resources (returned by get_for_package). :param archivals: A list of the archivals for a dataset's resources :type archivals: A list of Archival objects :returns: Archival dict about the dataset, with keys: status_id status reason is_broken ''' archival_dict = {'status_id': None, 'status': None, 'reason': None, 'is_broken': None} for archival in archivals: # status_id takes the highest id i.e. pessimistic # reason matches the status_id if archival_dict['status_id'] is None or \ archival.status_id > archival_dict['status_id']: archival_dict['status_id'] = archival.status_id archival_dict['reason'] = archival.reason if archivals: archival_dict['status'] = Status.by_id(archival_dict['status_id']) archival_dict['is_broken'] = \ Status.is_status_broken(archival_dict['status_id']) return archival_dict