model_1.py 1.1 KB

123456789101112131415161718192021222324252627
  1. def aggregate_archivals_for_a_dataset(archivals):
  2. '''Returns aggregated archival info for a dataset, given the archivals for
  3. its resources (returned by get_for_package).
  4. :param archivals: A list of the archivals for a dataset's resources
  5. :type archivals: A list of Archival objects
  6. :returns: Archival dict about the dataset, with keys:
  7. status_id
  8. status
  9. reason
  10. is_broken
  11. '''
  12. archival_dict = {'status_id': None, 'status': None,
  13. 'reason': None, 'is_broken': None}
  14. for archival in archivals:
  15. # status_id takes the highest id i.e. pessimistic
  16. # reason matches the status_id
  17. if archival_dict['status_id'] is None or \
  18. archival.status_id > archival_dict['status_id']:
  19. archival_dict['status_id'] = archival.status_id
  20. archival_dict['reason'] = archival.reason
  21. if archivals:
  22. archival_dict['status'] = Status.by_id(archival_dict['status_id'])
  23. archival_dict['is_broken'] = \
  24. Status.is_status_broken(archival_dict['status_id'])
  25. return archival_dict