utils.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from pathlib import Path
  2. from django.utils.html import format_html
  3. from core.models import Snapshot
  4. def get_icons(snapshot: Snapshot) -> str:
  5. link = snapshot.as_link()
  6. canon = link.canonical_outputs()
  7. out_dir = Path(link.link_dir)
  8. link_tuple = lambda link, method: (link.archive_path, canon[method] or '', canon[method] and (out_dir / (canon[method] or 'notdone')).exists())
  9. return format_html(
  10. '<span class="files-icons" style="font-size: 1.2em; opacity: 0.8">'
  11. '<a href="/{}/{}" class="exists-{}" title="Wget clone">🌐 </a> '
  12. '<a href="/{}/{}" class="exists-{}" title="PDF">📄</a> '
  13. '<a href="/{}/{}" class="exists-{}" title="Screenshot">🖥 </a> '
  14. '<a href="/{}/{}" class="exists-{}" title="HTML dump">🅷 </a> '
  15. '<a href="/{}/{}" class="exists-{}" title="WARC">🆆 </a> '
  16. '<a href="/{}/{}" class="exists-{}" title="SingleFile">&#128476; </a>'
  17. '<a href="/{}/{}/" class="exists-{}" title="Media files">📼 </a> '
  18. '<a href="/{}/{}/" class="exists-{}" title="Git repos">📦 </a> '
  19. '<a href="{}" class="exists-{}" title="Archive.org snapshot">🏛 </a> '
  20. '</span>',
  21. *link_tuple(link, 'wget_path'),
  22. *link_tuple(link, 'pdf_path'),
  23. *link_tuple(link, 'screenshot_path'),
  24. *link_tuple(link, 'dom_path'),
  25. *link_tuple(link, 'warc_path')[:2], any((out_dir / canon['warc_path']).glob('*.warc.gz')),
  26. *link_tuple(link, 'singlefile_path'),
  27. *link_tuple(link, 'media_path')[:2], any((out_dir / canon['media_path']).glob('*')),
  28. *link_tuple(link, 'git_path')[:2], any((out_dir / canon['git_path']).glob('*')),
  29. canon['archive_org_path'], (out_dir / 'archive.org.txt').exists(),
  30. )