From a98298103daf10f189f7c0547dee03b593ef0d9e Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Sat, 30 Jan 2021 05:35:07 -0500 Subject: [PATCH] cleanup templates and views --- archivebox/core/admin.py | 4 +- archivebox/core/templatetags/core_tags.py | 2 +- archivebox/core/urls.py | 8 +- archivebox/core/views.py | 16 +- archivebox/index/html.py | 6 +- .../admin/actions_as_select.html | 0 .../admin/app_index.html | 0 .../{themes => templates}/admin/base.html | 0 .../{themes => templates}/admin/login.html | 0 archivebox/templates/admin/private_index.html | 150 ++++++++++++ .../admin/private_index_grid.html} | 2 +- .../admin/snapshots_grid.html | 2 +- .../core/add.html} | 2 +- .../default => templates/core}/base.html | 0 .../core/index_row.html} | 6 +- .../core/minimal_index.html} | 4 +- .../core/public_index.html} | 2 +- .../core/snapshot.html} | 0 .../core/static_index.html} | 2 +- .../default => templates}/static/add.css | 0 .../default => templates}/static/admin.css | 0 .../default => templates}/static/archive.png | Bin .../static/bootstrap.min.css | 0 .../default => templates}/static/external.png | Bin .../static/jquery.dataTables.min.css | 0 .../static/jquery.dataTables.min.js | 0 .../static/jquery.min.js | 0 .../default => templates}/static/sort_asc.png | Bin .../static/sort_both.png | Bin .../static/sort_desc.png | Bin .../default => templates}/static/spinner.gif | Bin archivebox/themes/legacy/main_index.html | 215 ------------------ archivebox/themes/legacy/main_index_row.html | 16 -- etc/ArchiveBox.conf.default | 1 - 34 files changed, 179 insertions(+), 259 deletions(-) rename archivebox/{themes => templates}/admin/actions_as_select.html (100%) rename archivebox/{themes => templates}/admin/app_index.html (100%) rename archivebox/{themes => templates}/admin/base.html (100%) rename archivebox/{themes => templates}/admin/login.html (100%) create mode 100644 archivebox/templates/admin/private_index.html rename archivebox/{themes/admin/grid_change_list.html => templates/admin/private_index_grid.html} (99%) rename archivebox/{themes => templates}/admin/snapshots_grid.html (99%) rename archivebox/{themes/default/add_links.html => templates/core/add.html} (98%) rename archivebox/{themes/default => templates/core}/base.html (100%) rename archivebox/{themes/default/main_index_row.html => templates/core/index_row.html} (82%) rename archivebox/{themes/default/main_index_minimal.html => templates/core/minimal_index.html} (90%) rename archivebox/{themes/default/core/snapshot_list.html => templates/core/public_index.html} (97%) rename archivebox/{themes/default/link_details.html => templates/core/snapshot.html} (100%) rename archivebox/{themes/default/main_index.html => templates/core/static_index.html} (99%) rename archivebox/{themes/default => templates}/static/add.css (100%) rename archivebox/{themes/default => templates}/static/admin.css (100%) rename archivebox/{themes/default => templates}/static/archive.png (100%) rename archivebox/{themes/default => templates}/static/bootstrap.min.css (100%) rename archivebox/{themes/default => templates}/static/external.png (100%) rename archivebox/{themes/default => templates}/static/jquery.dataTables.min.css (100%) rename archivebox/{themes/default => templates}/static/jquery.dataTables.min.js (100%) rename archivebox/{themes/default => templates}/static/jquery.min.js (100%) rename archivebox/{themes/default => templates}/static/sort_asc.png (100%) rename archivebox/{themes/default => templates}/static/sort_both.png (100%) rename archivebox/{themes/default => templates}/static/sort_desc.png (100%) rename archivebox/{themes/default => templates}/static/spinner.gif (100%) delete mode 100644 archivebox/themes/legacy/main_index.html delete mode 100644 archivebox/themes/legacy/main_index_row.html diff --git a/archivebox/core/admin.py b/archivebox/core/admin.py index f641b177..518731f1 100644 --- a/archivebox/core/admin.py +++ b/archivebox/core/admin.py @@ -171,7 +171,7 @@ class SnapshotAdmin(SearchResultsAdminMixin, admin.ModelAdmin): saved_list_max_show_all = self.list_max_show_all # Monkey patch here plus core_tags.py - self.change_list_template = 'admin/grid_change_list.html' + self.change_list_template = 'private_index_grid.html' self.list_per_page = 20 self.list_max_show_all = self.list_per_page @@ -249,7 +249,7 @@ class ArchiveBoxAdmin(admin.AdminSite): else: context["form"] = form - return render(template_name='add_links.html', request=request, context=context) + return render(template_name='add.html', request=request, context=context) admin.site = ArchiveBoxAdmin() admin.site.register(get_user_model()) diff --git a/archivebox/core/templatetags/core_tags.py b/archivebox/core/templatetags/core_tags.py index 25f06852..9ac1ee27 100644 --- a/archivebox/core/templatetags/core_tags.py +++ b/archivebox/core/templatetags/core_tags.py @@ -14,7 +14,7 @@ register = template.Library() def snapshot_image(snapshot): result = ArchiveResult.objects.filter(snapshot=snapshot, extractor='screenshot', status='succeeded').first() if result: - return reverse('LinkAssets', args=[f'{str(snapshot.timestamp)}/{result.output}']) + return reverse('Snapshot', args=[f'{str(snapshot.timestamp)}/{result.output}']) return static('archive.png') diff --git a/archivebox/core/urls.py b/archivebox/core/urls.py index b8e4bafb..4c7b429c 100644 --- a/archivebox/core/urls.py +++ b/archivebox/core/urls.py @@ -5,22 +5,24 @@ from django.views import static from django.conf import settings from django.views.generic.base import RedirectView -from core.views import MainIndex, LinkDetails, PublicArchiveView, AddView +from core.views import HomepageView, SnapshotView, PublicIndexView, AddView # print('DEBUG', settings.DEBUG) urlpatterns = [ + path('public/', PublicIndexView.as_view(), name='public-index'), + 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('docs/', RedirectView.as_view(url='https://github.com/ArchiveBox/ArchiveBox/wiki'), name='Docs'), path('archive/', RedirectView.as_view(url='/')), - path('archive/', LinkDetails.as_view(), name='LinkAssets'), + path('archive/', SnapshotView.as_view(), name='Snapshot'), path('admin/core/snapshot/add/', RedirectView.as_view(url='/add/')), - path('add/', AddView.as_view()), + path('add/', AddView.as_view(), name='add'), path('accounts/login/', RedirectView.as_view(url='/admin/login/')), path('accounts/logout/', RedirectView.as_view(url='/admin/logout/')), diff --git a/archivebox/core/views.py b/archivebox/core/views.py index 810b4740..0e19fad6 100644 --- a/archivebox/core/views.py +++ b/archivebox/core/views.py @@ -28,20 +28,20 @@ from ..util import base_url, ansi_to_html from ..index.html import snapshot_icons -class MainIndex(View): - template = 'main_index.html' - +class HomepageView(View): def get(self, request): if request.user.is_authenticated: return redirect('/admin/core/snapshot/') if PUBLIC_INDEX: - return redirect('public-index') + return redirect('/public') return redirect(f'/admin/login/?next={request.path}') -class LinkDetails(View): +class SnapshotView(View): + # render static html index from filesystem archive//index.html + def get(self, request, path): # missing trailing slash -> redirect to index if '/' not in path: @@ -91,8 +91,8 @@ class LinkDetails(View): status=404, ) -class PublicArchiveView(ListView): - template = 'snapshot_list.html' +class PublicIndexView(ListView): + template_name = 'public_index.html' model = Snapshot paginate_by = 100 ordering = ['title'] @@ -122,7 +122,7 @@ class PublicArchiveView(ListView): class AddView(UserPassesTestMixin, FormView): - template_name = "add_links.html" + template_name = "add.html" form_class = AddLinkForm def get_initial(self): diff --git a/archivebox/index/html.py b/archivebox/index/html.py index 28f25fde..3eca5f01 100644 --- a/archivebox/index/html.py +++ b/archivebox/index/html.py @@ -25,9 +25,9 @@ from ..config import ( HTML_INDEX_FILENAME, ) -MAIN_INDEX_TEMPLATE = 'main_index.html' -MINIMAL_INDEX_TEMPLATE = 'main_index_minimal.html' -LINK_DETAILS_TEMPLATE = 'link_details.html' +MAIN_INDEX_TEMPLATE = 'static_index.html' +MINIMAL_INDEX_TEMPLATE = 'minimal_index.html' +LINK_DETAILS_TEMPLATE = 'snapshot.html' TITLE_LOADING_MSG = 'Not yet archived...' diff --git a/archivebox/themes/admin/actions_as_select.html b/archivebox/templates/admin/actions_as_select.html similarity index 100% rename from archivebox/themes/admin/actions_as_select.html rename to archivebox/templates/admin/actions_as_select.html diff --git a/archivebox/themes/admin/app_index.html b/archivebox/templates/admin/app_index.html similarity index 100% rename from archivebox/themes/admin/app_index.html rename to archivebox/templates/admin/app_index.html diff --git a/archivebox/themes/admin/base.html b/archivebox/templates/admin/base.html similarity index 100% rename from archivebox/themes/admin/base.html rename to archivebox/templates/admin/base.html diff --git a/archivebox/themes/admin/login.html b/archivebox/templates/admin/login.html similarity index 100% rename from archivebox/themes/admin/login.html rename to archivebox/templates/admin/login.html diff --git a/archivebox/templates/admin/private_index.html b/archivebox/templates/admin/private_index.html new file mode 100644 index 00000000..7afb62c3 --- /dev/null +++ b/archivebox/templates/admin/private_index.html @@ -0,0 +1,150 @@ +{% extends "base.html" %} +{% load static %} + +{% block body %} +
+ +
+ + + + + + + + + + + {% for link in object_list %} + {% include 'main_index_row.html' with link=link %} + {% endfor %} + +
BookmarkedSnapshot ({{object_list|length}})FilesOriginal URL
+
+ + {% if page_obj.has_previous %} + « first + previous + {% endif %} + + + Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}. + + + {% if page_obj.has_next %} + next + last » + {% endif %} + + + {% if page_obj.has_next %} + next + last » + {% endif %} + +
+
+{% endblock %} +{% extends "admin/base_site.html" %} +{% load i18n admin_urls static admin_list %} +{% load core_tags %} + +{% block extrastyle %} + {{ block.super }} + + {% if cl.formset %} + + {% endif %} + {% if cl.formset or action_form %} + + {% endif %} + {{ media.css }} + {% if not actions_on_top and not actions_on_bottom %} + + {% endif %} +{% endblock %} + +{% block extrahead %} +{{ block.super }} +{{ media.js }} +{% endblock %} + +{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} change-list{% endblock %} + +{% if not is_popup %} +{% block breadcrumbs %} + +{% endblock %} +{% endif %} + +{% block coltype %}{% endblock %} + +{% block content %} +
+ {% block object-tools %} +
    + {% block object-tools-items %} + {% change_list_object_tools %} + {% endblock %} +
+ {% endblock %} + {% if cl.formset and cl.formset.errors %} +

+ {% if cl.formset.total_error_count == 1 %}{% translate "Please correct the error below." %}{% else %}{% translate "Please correct the errors below." %}{% endif %} +

+ {{ cl.formset.non_form_errors }} + {% endif %} +
+
+ {% block search %}{% search_form cl %}{% endblock %} + {% block date_hierarchy %}{% if cl.date_hierarchy %}{% date_hierarchy cl %}{% endif %}{% endblock %} + +
{% csrf_token %} + {% if cl.formset %} +
{{ cl.formset.management_form }}
+ {% endif %} + + {% block result_list %} + {% if action_form and actions_on_top and cl.show_admin_actions %}{% admin_actions %}{% endif %} + {% comment %} + Table grid + {% result_list cl %} + {% endcomment %} + {% snapshots_grid cl %} + {% if action_form and actions_on_bottom and cl.show_admin_actions %}{% admin_actions %}{% endif %} + {% endblock %} + {% block pagination %}{% pagination cl %}{% endblock %} +
+
+ {% block filters %} + {% if cl.has_filters %} +
+

{% translate 'Filter' %}

+ {% if cl.has_active_filters %}

+ ✖ {% translate "Clear all filters" %} +

{% endif %} + {% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %} +
+ {% endif %} + {% endblock %} +
+
+{% endblock %} diff --git a/archivebox/themes/admin/grid_change_list.html b/archivebox/templates/admin/private_index_grid.html similarity index 99% rename from archivebox/themes/admin/grid_change_list.html rename to archivebox/templates/admin/private_index_grid.html index 6894efd7..b60f3a3e 100644 --- a/archivebox/themes/admin/grid_change_list.html +++ b/archivebox/templates/admin/private_index_grid.html @@ -88,4 +88,4 @@ {% endblock %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/archivebox/themes/admin/snapshots_grid.html b/archivebox/templates/admin/snapshots_grid.html similarity index 99% rename from archivebox/themes/admin/snapshots_grid.html rename to archivebox/templates/admin/snapshots_grid.html index a7a2d4f9..10788060 100644 --- a/archivebox/themes/admin/snapshots_grid.html +++ b/archivebox/templates/admin/snapshots_grid.html @@ -159,4 +159,4 @@ footer { {% endfor %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/archivebox/themes/default/add_links.html b/archivebox/templates/core/add.html similarity index 98% rename from archivebox/themes/default/add_links.html rename to archivebox/templates/core/add.html index fa8b441f..0f161885 100644 --- a/archivebox/themes/default/add_links.html +++ b/archivebox/templates/core/add.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "core/base.html" %} {% load static %} {% load i18n %} diff --git a/archivebox/themes/default/base.html b/archivebox/templates/core/base.html similarity index 100% rename from archivebox/themes/default/base.html rename to archivebox/templates/core/base.html diff --git a/archivebox/themes/default/main_index_row.html b/archivebox/templates/core/index_row.html similarity index 82% rename from archivebox/themes/default/main_index_row.html rename to archivebox/templates/core/index_row.html index eae60ea9..cba3ec39 100644 --- a/archivebox/themes/default/main_index_row.html +++ b/archivebox/templates/core/index_row.html @@ -4,9 +4,9 @@ {% if link.bookmarked_date %} {{ link.bookmarked_date }} {% else %} {{ link.added }} {% endif %} {% if link.is_archived %} - + {% else %} - + {% endif %} @@ -28,7 +28,7 @@ {{link.icons}} {{link.num_outputs}} {% else %} 📄 - {{link.num_outputs}} + {{link.num_outputs}} {% endif %} diff --git a/archivebox/themes/default/main_index_minimal.html b/archivebox/templates/core/minimal_index.html similarity index 90% rename from archivebox/themes/default/main_index_minimal.html rename to archivebox/templates/core/minimal_index.html index dcfaa23f..3c69a831 100644 --- a/archivebox/themes/default/main_index_minimal.html +++ b/archivebox/templates/core/minimal_index.html @@ -16,9 +16,9 @@ {% for link in links %} - {% include "main_index_row.html" with link=link %} + {% include "index_row.html" with link=link %} {% endfor %} - \ No newline at end of file + diff --git a/archivebox/themes/default/core/snapshot_list.html b/archivebox/templates/core/public_index.html similarity index 97% rename from archivebox/themes/default/core/snapshot_list.html rename to archivebox/templates/core/public_index.html index dd8ebf15..327042ea 100644 --- a/archivebox/themes/default/core/snapshot_list.html +++ b/archivebox/templates/core/public_index.html @@ -28,7 +28,7 @@ {% for link in object_list %} - {% include 'main_index_row.html' with link=link %} + {% include 'index_row.html' with link=link %} {% endfor %} diff --git a/archivebox/themes/default/link_details.html b/archivebox/templates/core/snapshot.html similarity index 100% rename from archivebox/themes/default/link_details.html rename to archivebox/templates/core/snapshot.html diff --git a/archivebox/themes/default/main_index.html b/archivebox/templates/core/static_index.html similarity index 99% rename from archivebox/themes/default/main_index.html rename to archivebox/templates/core/static_index.html index 269c9825..07066e27 100644 --- a/archivebox/themes/default/main_index.html +++ b/archivebox/templates/core/static_index.html @@ -234,7 +234,7 @@ {% for link in links %} - {% include 'main_index_row.html' with link=link %} + {% include 'index_row.html' with link=link %} {% endfor %} diff --git a/archivebox/themes/default/static/add.css b/archivebox/templates/static/add.css similarity index 100% rename from archivebox/themes/default/static/add.css rename to archivebox/templates/static/add.css diff --git a/archivebox/themes/default/static/admin.css b/archivebox/templates/static/admin.css similarity index 100% rename from archivebox/themes/default/static/admin.css rename to archivebox/templates/static/admin.css diff --git a/archivebox/themes/default/static/archive.png b/archivebox/templates/static/archive.png similarity index 100% rename from archivebox/themes/default/static/archive.png rename to archivebox/templates/static/archive.png diff --git a/archivebox/themes/default/static/bootstrap.min.css b/archivebox/templates/static/bootstrap.min.css similarity index 100% rename from archivebox/themes/default/static/bootstrap.min.css rename to archivebox/templates/static/bootstrap.min.css diff --git a/archivebox/themes/default/static/external.png b/archivebox/templates/static/external.png similarity index 100% rename from archivebox/themes/default/static/external.png rename to archivebox/templates/static/external.png diff --git a/archivebox/themes/default/static/jquery.dataTables.min.css b/archivebox/templates/static/jquery.dataTables.min.css similarity index 100% rename from archivebox/themes/default/static/jquery.dataTables.min.css rename to archivebox/templates/static/jquery.dataTables.min.css diff --git a/archivebox/themes/default/static/jquery.dataTables.min.js b/archivebox/templates/static/jquery.dataTables.min.js similarity index 100% rename from archivebox/themes/default/static/jquery.dataTables.min.js rename to archivebox/templates/static/jquery.dataTables.min.js diff --git a/archivebox/themes/default/static/jquery.min.js b/archivebox/templates/static/jquery.min.js similarity index 100% rename from archivebox/themes/default/static/jquery.min.js rename to archivebox/templates/static/jquery.min.js diff --git a/archivebox/themes/default/static/sort_asc.png b/archivebox/templates/static/sort_asc.png similarity index 100% rename from archivebox/themes/default/static/sort_asc.png rename to archivebox/templates/static/sort_asc.png diff --git a/archivebox/themes/default/static/sort_both.png b/archivebox/templates/static/sort_both.png similarity index 100% rename from archivebox/themes/default/static/sort_both.png rename to archivebox/templates/static/sort_both.png diff --git a/archivebox/themes/default/static/sort_desc.png b/archivebox/templates/static/sort_desc.png similarity index 100% rename from archivebox/themes/default/static/sort_desc.png rename to archivebox/templates/static/sort_desc.png diff --git a/archivebox/themes/default/static/spinner.gif b/archivebox/templates/static/spinner.gif similarity index 100% rename from archivebox/themes/default/static/spinner.gif rename to archivebox/templates/static/spinner.gif diff --git a/archivebox/themes/legacy/main_index.html b/archivebox/themes/legacy/main_index.html deleted file mode 100644 index 74e7bf65..00000000 --- a/archivebox/themes/legacy/main_index.html +++ /dev/null @@ -1,215 +0,0 @@ - - - - Archived Sites - - - - - - - - - -
-
- -
-
- - - - - - - - - - $rows -
BookmarkedSnapshot ($num_links)FilesOriginal URL
- - - diff --git a/archivebox/themes/legacy/main_index_row.html b/archivebox/themes/legacy/main_index_row.html deleted file mode 100644 index 9112eace..00000000 --- a/archivebox/themes/legacy/main_index_row.html +++ /dev/null @@ -1,16 +0,0 @@ - - $bookmarked_date - - - - $title - $tags - - - - 📄 - $num_outputs - - - $url - diff --git a/etc/ArchiveBox.conf.default b/etc/ArchiveBox.conf.default index fe3bcdde..982a1931 100644 --- a/etc/ArchiveBox.conf.default +++ b/etc/ArchiveBox.conf.default @@ -24,7 +24,6 @@ # PUBLIC_INDEX = True # PUBLIC_SNAPSHOTS = True # FOOTER_INFO = Content is hosted for personal archiving purposes only. Contact server owner for any takedown requests. -# ACTIVE_THEME = default [ARCHIVE_METHOD_TOGGLES]