mirror of
https://github.com/ArchiveBox/ArchiveBox
synced 2024-11-10 14:44:18 +00:00
improve sort columns and UI placeholders
This commit is contained in:
parent
178f6ac1a6
commit
c415420f33
3 changed files with 33 additions and 19 deletions
|
@ -1,16 +1,16 @@
|
|||
from django.contrib import admin
|
||||
from django.utils.html import format_html
|
||||
|
||||
from archivebox.util import htmldecode, urldecode
|
||||
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 = ('id_str', 'title_str', 'url_str', 'tags', 'files', 'added', 'updated', 'timestamp')
|
||||
# sort_fields = ('id_str', 'files', 'url_str', 'title_str', 'tags', 'added', 'updated', 'timestamp')
|
||||
list_display = ('title_str', 'url_str', 'tags', 'files', 'added', 'updated')
|
||||
sort_fields = ('title_str', 'url_str', 'tags', 'added', 'updated')
|
||||
readonly_fields = ('id', 'num_outputs', 'is_archived', 'url_hash', 'added', 'updated')
|
||||
search_fields = ('url', 'timestamp', 'title', 'tags')
|
||||
fields = ('url', 'timestamp', 'title', 'tags', *readonly_fields)
|
||||
|
@ -27,14 +27,15 @@ class SnapshotAdmin(admin.ModelAdmin):
|
|||
canon = obj.as_link().canonical_outputs()
|
||||
return format_html(
|
||||
'<a href="/{}">'
|
||||
'<img src="/{}/{}" style="height: 20px; width: 20px;" onerror="this.style.opacity=0">'
|
||||
'<img src="/{}/{}" style="height: 20px; width: 20px;" onerror="this.remove()">'
|
||||
' '
|
||||
'</a>'
|
||||
'<a href="/{}/{}">'
|
||||
' <b>{}</b></a>',
|
||||
'<b>{}</b></a>',
|
||||
obj.archive_path,
|
||||
obj.archive_path, canon['favicon_path'],
|
||||
obj.archive_path, canon['google_favicon_path'],
|
||||
obj.archive_path, canon['wget_path'] or '',
|
||||
(obj.title or '...')[:128],
|
||||
urldecode(htmldecode(obj.latest_title or obj.title or '-'))[:128],
|
||||
)
|
||||
|
||||
def files(self, obj):
|
||||
|
@ -58,14 +59,14 @@ class SnapshotAdmin(admin.ModelAdmin):
|
|||
obj.archive_path, canon['git_path'],
|
||||
obj.archive_path, canon['archive_org_path'],
|
||||
obj.archive_path,
|
||||
printable_filesize(obj.archive_size),
|
||||
printable_filesize(obj.archive_size) if obj.archive_size else 'pending',
|
||||
)
|
||||
|
||||
def url_str(self, obj):
|
||||
return format_html(
|
||||
'<a href="{}"><code>{}</code></a>',
|
||||
obj.url,
|
||||
obj.url.split('://', 1)[-1][:128],
|
||||
obj.url.split('://www.', 1)[-1].split('://', 1)[-1][:64],
|
||||
)
|
||||
|
||||
id_str.short_description = 'ID'
|
||||
|
|
|
@ -3,6 +3,7 @@ __package__ = 'archivebox.core'
|
|||
import uuid
|
||||
|
||||
from django.db import models
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
from ..util import parse_date
|
||||
from ..index.schema import Link
|
||||
|
@ -47,34 +48,48 @@ class Snapshot(models.Model):
|
|||
def as_link(self) -> Link:
|
||||
return Link.from_json(self.as_json())
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def bookmarked(self):
|
||||
return parse_date(self.timestamp)
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def is_archived(self):
|
||||
return self.as_link().is_archived
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def num_outputs(self):
|
||||
return self.as_link().num_outputs
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def url_hash(self):
|
||||
return self.as_link().url_hash
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def base_url(self):
|
||||
return self.as_link().base_url
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def link_dir(self):
|
||||
return self.as_link().link_dir
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def archive_path(self):
|
||||
return self.as_link().archive_path
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def archive_size(self):
|
||||
return self.as_link().archive_size
|
||||
|
||||
@cached_property
|
||||
def history(self):
|
||||
from ..index import load_link_details
|
||||
return load_link_details(self.as_link()).history
|
||||
|
||||
@cached_property
|
||||
def latest_title(self):
|
||||
if ('title' in self.history
|
||||
and self.history['title']
|
||||
and (self.history['title'][-1].status == 'succeeded')
|
||||
and self.history['title'][-1].output.strip()):
|
||||
return self.history['title'][-1].output.strip()
|
||||
return None
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import re
|
||||
import ssl
|
||||
import json as pyjson
|
||||
|
||||
|
||||
|
@ -7,7 +6,6 @@ from typing import List, Optional, Any
|
|||
from inspect import signature
|
||||
from functools import wraps
|
||||
from hashlib import sha256
|
||||
from urllib.request import Request, urlopen
|
||||
from urllib.parse import urlparse, quote, unquote
|
||||
from html import escape, unescape
|
||||
from datetime import datetime
|
||||
|
|
Loading…
Reference in a new issue