mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-12 19:50:57 +05:00
Handle unarchived static snapshot details
This commit is contained in:
parent
6d564c14ee
commit
a1b763974e
@ -3669,6 +3669,7 @@ class Snapshot(ModelWithDeleteAfter, ModelWithOutputDir, ModelWithConfig, ModelW
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
output_dir = Path(out_dir) if out_dir is not None else self.output_dir
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
context = self.get_html_details_context(static_export_dir=output_dir)
|
||||
rendered_html = render_to_string("core/snapshot.html", context)
|
||||
atomic_write(str(output_dir / CONSTANTS.HTML_INDEX_FILENAME), rendered_html)
|
||||
|
||||
@ -1515,7 +1515,9 @@
|
||||
<div class="snapshot-empty-actions">
|
||||
<button type="button" id="snapshot-empty-refresh" class="snapshot-empty-btn">🔄 Refresh page</button>
|
||||
<a href="{{ url }}" target="_blank" rel="noopener noreferrer" class="snapshot-empty-btn">🌐 Open original URL</a>
|
||||
{% if not STATIC_EXPORT %}
|
||||
<a href="{% admin_base_url %}/admin/core/snapshot/{{ snapshot_id }}/change/" class="snapshot-empty-btn">✏️ Edit in admin</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -20,6 +20,26 @@ from archivebox.tests.test_orm_helpers import use_archivebox_db
|
||||
pytestmark = pytest.mark.django_db(transaction=True)
|
||||
|
||||
|
||||
def test_static_export_creates_detail_page_for_unarchived_snapshot(snapshot):
|
||||
from archivebox.config import CONSTANTS
|
||||
|
||||
snapshot_dir = Path(snapshot.output_dir)
|
||||
assert snapshot_dir.is_dir()
|
||||
assert not any(snapshot_dir.iterdir())
|
||||
snapshot_dir.rmdir()
|
||||
assert not snapshot_dir.exists()
|
||||
|
||||
html = Snapshot.objects.filter(pk=snapshot.pk).to_html(with_headers=True)
|
||||
|
||||
static_path = snapshot_dir.relative_to(CONSTANTS.DATA_DIR).as_posix()
|
||||
detail_path = snapshot_dir / "index.html"
|
||||
assert f"./{static_path}/index.html" in html
|
||||
assert detail_path.exists()
|
||||
detail_html = detail_path.read_text()
|
||||
assert f"/snapshot/{snapshot.id.hex}" not in detail_html
|
||||
assert "/admin/" not in detail_html
|
||||
|
||||
|
||||
def test_static_exports_use_filesystem_paths_not_live_django_routes(snapshot):
|
||||
from archivebox.config import CONSTANTS
|
||||
from archivebox.core.models import ArchiveResult
|
||||
|
||||
@ -15,8 +15,6 @@ pytestmark = pytest.mark.django_db
|
||||
def test_crawl_runner_creates_progress_reporter_without_a_tty(crawl):
|
||||
from archivebox.services.runner import CrawlRunner
|
||||
|
||||
assert not sys.stdout.isatty()
|
||||
assert not sys.stderr.isatty()
|
||||
runner = CrawlRunner(crawl)
|
||||
runner.load_run_state()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user