views.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import os
  2. import sys
  3. from pathlib import Path
  4. from django.views import View
  5. from django.shortcuts import render
  6. from django.db.models import Q
  7. from core.models import Snapshot
  8. # from archivebox.config import PUBLIC_SNAPSHOTS
  9. PUBLIC_SNAPSHOTS = True
  10. class ReplayWebPageViewer(View):
  11. template_name = 'plugin_replaywebpage__viewer.html'
  12. # render static html index from filesystem archive/<timestamp>/index.html
  13. def get_context_data(self, **kwargs):
  14. return {
  15. # **super().get_context_data(**kwargs),
  16. # 'VERSION': VERSION,
  17. # 'COMMIT_HASH': COMMIT_HASH,
  18. # 'FOOTER_INFO': FOOTER_INFO,
  19. }
  20. def get(self, request, path):
  21. if not request.user.is_authenticated and not PUBLIC_SNAPSHOTS:
  22. return redirect(f'/admin/login/?next={request.path}')
  23. try:
  24. timestamp, warc_filename = path.split('/', 1)
  25. except (IndexError, ValueError):
  26. timestamp, warc_filename = path.split('/', 1)[0], ''
  27. snapshot = Snapshot.objects.get(Q(timestamp=timestamp) | Q(id__startswith=timestamp))
  28. context = self.get_context_data()
  29. context.update({
  30. "snapshot": snapshot,
  31. "timestamp": timestamp,
  32. "warc_filename": warc_filename,
  33. })
  34. return render(template_name=self.template_name, request=self.request, context=context)