mirror of
https://github.com/ArchiveBox/ArchiveBox
synced 2024-11-22 12:13:05 +00:00
django admin to view links now working
This commit is contained in:
parent
f489dd96a9
commit
354895aef1
4 changed files with 40 additions and 3 deletions
|
@ -1,3 +1,11 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
from .models import Page
|
||||
|
||||
class PageAdmin(admin.ModelAdmin):
|
||||
list_display = ('timestamp', 'short_url', 'title', 'is_archived', 'num_outputs', 'added', 'updated', 'url_hash')
|
||||
|
||||
def short_url(self, obj):
|
||||
return obj.url[:64]
|
||||
|
||||
admin.site.register(Page, PageAdmin)
|
||||
|
|
|
@ -4,6 +4,8 @@ import uuid
|
|||
|
||||
from django.db import models
|
||||
|
||||
from legacy.schema import Link
|
||||
|
||||
|
||||
class Page(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
|
@ -20,6 +22,13 @@ class Page(models.Model):
|
|||
|
||||
keys = ('url', 'timestamp', 'title', 'tags', 'updated')
|
||||
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'[{self.timestamp}] {self.url[:64]} ({self.title[:64]})'
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f'[{self.timestamp}] {self.url[:64]} ({self.title[:64]})'
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, info: dict):
|
||||
info = {k: v for k, v in info.items() if k in cls.keys}
|
||||
|
@ -31,3 +40,22 @@ class Page(models.Model):
|
|||
key: getattr(self, key)
|
||||
for key in args
|
||||
}
|
||||
|
||||
def as_link(self) -> Link:
|
||||
return Link.from_json(self.as_json())
|
||||
|
||||
@property
|
||||
def is_archived(self):
|
||||
return self.as_link().is_archived
|
||||
|
||||
@property
|
||||
def num_outputs(self):
|
||||
return self.as_link().num_outputs
|
||||
|
||||
@property
|
||||
def url_hash(self):
|
||||
return self.as_link().url_hash
|
||||
|
||||
@property
|
||||
def base_url(self):
|
||||
return self.as_link().base_url
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.urls import path
|
|||
from core.views import MainIndex, LinkDetails
|
||||
|
||||
urlpatterns = [
|
||||
path('', admin.site.urls),
|
||||
path('admin/', admin.site.urls),
|
||||
path('archive/<timestamp>/', LinkDetails.as_view(), name='LinkDetails'),
|
||||
path('main/', MainIndex.as_view(), name='Home'),
|
||||
]
|
||||
|
|
|
@ -181,8 +181,9 @@ class Link:
|
|||
if key in cls.field_names()
|
||||
}
|
||||
info['updated'] = parse_date(info['updated'])
|
||||
info['sources'] = info.get('sources') or []
|
||||
|
||||
json_history = info['history']
|
||||
json_history = info.get('history') or {}
|
||||
cast_history = {}
|
||||
|
||||
for method, method_history in json_history.items():
|
||||
|
|
Loading…
Reference in a new issue