From 354895aef161801eba4e050a8f7838310b2e5c6d Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Mon, 22 Apr 2019 13:20:19 -0400 Subject: [PATCH] django admin to view links now working --- archivebox/core/admin.py | 10 +++++++++- archivebox/core/models.py | 28 ++++++++++++++++++++++++++++ archivebox/core/urls.py | 2 +- archivebox/legacy/schema.py | 3 ++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/archivebox/core/admin.py b/archivebox/core/admin.py index 8c38f3f3..b61d93d6 100644 --- a/archivebox/core/admin.py +++ b/archivebox/core/admin.py @@ -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) diff --git a/archivebox/core/models.py b/archivebox/core/models.py index 6fdcdae2..94258b1a 100644 --- a/archivebox/core/models.py +++ b/archivebox/core/models.py @@ -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 diff --git a/archivebox/core/urls.py b/archivebox/core/urls.py index a105c91c..3a2cb826 100644 --- a/archivebox/core/urls.py +++ b/archivebox/core/urls.py @@ -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//', LinkDetails.as_view(), name='LinkDetails'), path('main/', MainIndex.as_view(), name='Home'), ] diff --git a/archivebox/legacy/schema.py b/archivebox/legacy/schema.py index 38f2ec95..2c0cf033 100644 --- a/archivebox/legacy/schema.py +++ b/archivebox/legacy/schema.py @@ -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():