helpers.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from ckan.plugins import toolkit as tk
  2. def archiver_resource_show(resource_id):
  3. data_dict = {'id': resource_id}
  4. return tk.get_action('archiver_resource_show')(data_dict)
  5. def archiver_is_resource_broken_html(resource):
  6. archival = resource.get('archiver')
  7. if not archival:
  8. return tk.literal('<!-- No archival info for this resource -->')
  9. extra_vars = {'resource': resource}
  10. extra_vars.update(archival)
  11. return tk.literal(
  12. tk.render('archiver/is_resource_broken.html',
  13. extra_vars=extra_vars))
  14. def archiver_is_resource_cached_html(resource):
  15. archival = resource.get('archiver')
  16. if not archival:
  17. return tk.literal('<!-- No archival info for this resource -->')
  18. extra_vars = {'resource': resource}
  19. extra_vars.update(archival)
  20. return tk.literal(
  21. tk.render('archiver/is_resource_cached.html',
  22. extra_vars=extra_vars))
  23. # Replacement for the core ckan helper 'format_resource_items'
  24. # but with our own blacklist
  25. def archiver_format_resource_items(items):
  26. blacklist = ['archiver', 'qa']
  27. items_ = [item for item in items
  28. if item[0] not in blacklist]
  29. import ckan.lib.helpers as ckan_helpers
  30. return ckan_helpers.format_resource_items(items_)