From 178f6ac1a6cf94ae2e8d9edf68c6720ccebf1f2d Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 30 Jun 2020 05:56:17 -0400 Subject: [PATCH] switch to django admin snapshots list as new homepage --- archivebox/core/admin.py | 74 ++++++++++++++++++++++++++++++++++++---- archivebox/core/urls.py | 18 +++++----- 2 files changed, 78 insertions(+), 14 deletions(-) diff --git a/archivebox/core/admin.py b/archivebox/core/admin.py index 526d0602..39482c4c 100644 --- a/archivebox/core/admin.py +++ b/archivebox/core/admin.py @@ -1,17 +1,79 @@ from django.contrib import admin +from django.utils.html import format_html from core.models import Snapshot +from cli.logging import printable_filesize + + +# TODO: https://stackoverflow.com/questions/40760880/add-custom-button-to-django-admin-panel class SnapshotAdmin(admin.ModelAdmin): - list_display = ('timestamp', 'short_url', 'title', 'is_archived', 'num_outputs', 'added', 'updated', 'url_hash') - readonly_fields = ('num_outputs', 'is_archived', 'added', 'updated', 'bookmarked') + list_display = ('id_str', 'title_str', 'url_str', 'tags', 'files', 'added', 'updated', 'timestamp') + # sort_fields = ('id_str', 'files', 'url_str', 'title_str', 'tags', 'added', 'updated', 'timestamp') + readonly_fields = ('id', 'num_outputs', 'is_archived', 'url_hash', 'added', 'updated') + search_fields = ('url', 'timestamp', 'title', 'tags') fields = ('url', 'timestamp', 'title', 'tags', *readonly_fields) + list_filter = ('added', 'updated', 'tags') + ordering = ['-added'] - def short_url(self, obj): - return obj.url[:64] + def id_str(self, obj): + return format_html( + '{}', + obj.url_hash[:8], + ) - def updated(self, obj): - return obj.isoformat() + def title_str(self, obj): + canon = obj.as_link().canonical_outputs() + return format_html( + '' + '' + '' + '' + '     {}', + obj.archive_path, + obj.archive_path, canon['favicon_path'], + obj.archive_path, canon['wget_path'] or '', + (obj.title or '...')[:128], + ) + + def files(self, obj): + canon = obj.as_link().canonical_outputs() + return format_html( + '' + '🌐 ' + '📄 ' + '🖥 ' + '🅷 ' + '📼 ' + '📦 ' + '🏛 ' + '' + '{}', + obj.archive_path, canon['wget_path'] or '', + obj.archive_path, canon['pdf_path'], + obj.archive_path, canon['screenshot_path'], + obj.archive_path, canon['dom_path'], + obj.archive_path, canon['media_path'], + obj.archive_path, canon['git_path'], + obj.archive_path, canon['archive_org_path'], + obj.archive_path, + printable_filesize(obj.archive_size), + ) + + def url_str(self, obj): + return format_html( + '{}', + obj.url, + obj.url.split('://', 1)[-1][:128], + ) + + id_str.short_description = 'ID' + title_str.short_description = 'Title' + url_str.short_description = 'URL' + + id_str.admin_order_field = 'id' + title_str.admin_order_field = 'title' + url_str.admin_order_field = 'url' admin.site.register(Snapshot, SnapshotAdmin) diff --git a/archivebox/core/urls.py b/archivebox/core/urls.py index 9b4af5a5..7bbaf479 100644 --- a/archivebox/core/urls.py +++ b/archivebox/core/urls.py @@ -8,12 +8,12 @@ from django.views.generic.base import RedirectView from core.views import MainIndex, AddLinks, LinkDetails -admin.site.site_header = 'ArchiveBox Admin' -admin.site.index_title = 'Archive Administration' +admin.site.site_header = 'ArchiveBox' +admin.site.index_title = 'Links' +admin.site.site_title = 'Index' + urlpatterns = [ - path('index.html', RedirectView.as_view(url='/')), - path('index.json', static.serve, {'document_root': settings.OUTPUT_DIR, 'path': 'index.json'}), path('robots.txt', static.serve, {'document_root': settings.OUTPUT_DIR, 'path': 'robots.txt'}), path('favicon.ico', static.serve, {'document_root': settings.OUTPUT_DIR, 'path': 'favicon.ico'}), @@ -26,11 +26,13 @@ urlpatterns = [ path('accounts/login/', RedirectView.as_view(url='/admin/login/')), path('accounts/logout/', RedirectView.as_view(url='/admin/logout/')), + path('admin/core/snapshot/add/', RedirectView.as_view(url='/add/')), + path('accounts/', include('django.contrib.auth.urls')), path('admin/', admin.site.urls), - - path('', MainIndex.as_view(), name='Home'), + path('old.html', MainIndex.as_view(), name='OldHome'), + path('index.html', RedirectView.as_view(url='/')), + path('index.json', static.serve, {'document_root': settings.OUTPUT_DIR, 'path': 'index.json'}), + path('', RedirectView.as_view(url='/admin/core/snapshot/'), name='Home'), ] - -