mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-13 06:34:25 -04:00
switch to django admin snapshots list as new homepage
This commit is contained in:
parent
9f440c2cf8
commit
178f6ac1a6
2 changed files with 78 additions and 14 deletions
|
@ -1,17 +1,79 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.utils.html import format_html
|
||||||
|
|
||||||
from core.models import Snapshot
|
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):
|
class SnapshotAdmin(admin.ModelAdmin):
|
||||||
list_display = ('timestamp', 'short_url', 'title', 'is_archived', 'num_outputs', 'added', 'updated', 'url_hash')
|
list_display = ('id_str', 'title_str', 'url_str', 'tags', 'files', 'added', 'updated', 'timestamp')
|
||||||
readonly_fields = ('num_outputs', 'is_archived', 'added', 'updated', 'bookmarked')
|
# 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)
|
fields = ('url', 'timestamp', 'title', 'tags', *readonly_fields)
|
||||||
|
list_filter = ('added', 'updated', 'tags')
|
||||||
|
ordering = ['-added']
|
||||||
|
|
||||||
def short_url(self, obj):
|
def id_str(self, obj):
|
||||||
return obj.url[:64]
|
return format_html(
|
||||||
|
'<code style="font-size: 10px">{}</code>',
|
||||||
|
obj.url_hash[:8],
|
||||||
|
)
|
||||||
|
|
||||||
def updated(self, obj):
|
def title_str(self, obj):
|
||||||
return obj.isoformat()
|
canon = obj.as_link().canonical_outputs()
|
||||||
|
return format_html(
|
||||||
|
'<a href="/{}">'
|
||||||
|
'<img src="/{}/{}" style="height: 20px; width: 20px;" onerror="this.style.opacity=0">'
|
||||||
|
'</a>'
|
||||||
|
'<a href="/{}/{}">'
|
||||||
|
' <b>{}</b></a>',
|
||||||
|
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(
|
||||||
|
'<span style="font-size: 1.2em; opacity: 0.8">'
|
||||||
|
'<a href="/{}/{}">🌐 </a> '
|
||||||
|
'<a href="/{}/{}">📄</a> '
|
||||||
|
'<a href="/{}/{}">🖥 </a> '
|
||||||
|
'<a href="/{}/{}">🅷 </a> '
|
||||||
|
'<a href="/{}/{}">📼 </a> '
|
||||||
|
'<a href="/{}/{}">📦 </a> '
|
||||||
|
'<a href="/{}/{}">🏛 </a> '
|
||||||
|
'</span>'
|
||||||
|
'<a href="/{}">{}</a>',
|
||||||
|
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(
|
||||||
|
'<a href="{}"><code>{}</code></a>',
|
||||||
|
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)
|
admin.site.register(Snapshot, SnapshotAdmin)
|
||||||
|
|
|
@ -8,12 +8,12 @@ from django.views.generic.base import RedirectView
|
||||||
|
|
||||||
from core.views import MainIndex, AddLinks, LinkDetails
|
from core.views import MainIndex, AddLinks, LinkDetails
|
||||||
|
|
||||||
admin.site.site_header = 'ArchiveBox Admin'
|
admin.site.site_header = 'ArchiveBox'
|
||||||
admin.site.index_title = 'Archive Administration'
|
admin.site.index_title = 'Links'
|
||||||
|
admin.site.site_title = 'Index'
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
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('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'}),
|
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/login/', RedirectView.as_view(url='/admin/login/')),
|
||||||
path('accounts/logout/', RedirectView.as_view(url='/admin/logout/')),
|
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('accounts/', include('django.contrib.auth.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
|
||||||
|
path('old.html', MainIndex.as_view(), name='OldHome'),
|
||||||
path('', MainIndex.as_view(), name='Home'),
|
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'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue