action.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import logging
  2. import ckan.plugins as p
  3. from ckan import model
  4. from ckanext.archiver.model import Archival, aggregate_archivals_for_a_dataset
  5. ObjectNotFound = p.toolkit.ObjectNotFound
  6. _get_or_bust = p.toolkit.get_or_bust
  7. log = logging.getLogger(__name__)
  8. @p.toolkit.side_effect_free
  9. def archiver_resource_show(context, data_dict=None):
  10. '''Return a details of the archival of a resource
  11. :param id: the id of the resource
  12. :type id: string
  13. :rtype: dictionary
  14. '''
  15. id_ = _get_or_bust(data_dict, 'id')
  16. archival = Archival.get_for_resource(id_)
  17. if archival is None:
  18. raise ObjectNotFound
  19. archival_dict = archival.as_dict()
  20. p.toolkit.check_access('archiver_resource_show', context, data_dict)
  21. return archival_dict
  22. @p.toolkit.side_effect_free
  23. def archiver_dataset_show(context, data_dict=None):
  24. '''Return a details of the archival of a dataset, aggregated across its
  25. resources.
  26. :param id: the name or id of the dataset
  27. :type id: string
  28. :rtype: dictionary
  29. '''
  30. id_ = _get_or_bust(data_dict, 'id')
  31. dataset = model.Package.get(id_)
  32. if not dataset:
  33. raise ObjectNotFound
  34. archivals = Archival.get_for_package(dataset.id)
  35. archival_dict = aggregate_archivals_for_a_dataset(archivals)
  36. p.toolkit.check_access('archiver_dataset_show', context, data_dict)
  37. return archival_dict