From 5c4ac3cf3dcff7cb0cd8792cc4ba745b1c2f69ae Mon Sep 17 00:00:00 2001 From: apkallum Date: Thu, 20 Aug 2020 10:04:34 -0400 Subject: [PATCH 01/13] new public view derived from django --- archivebox/core/urls.py | 3 +- archivebox/core/views.py | 11 + .../themes/default/core/snapshot_list.html | 281 ++++++++++++++++++ 3 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 archivebox/themes/default/core/snapshot_list.html diff --git a/archivebox/core/urls.py b/archivebox/core/urls.py index b830de68..bf5708d5 100644 --- a/archivebox/core/urls.py +++ b/archivebox/core/urls.py @@ -5,7 +5,7 @@ from django.views import static from django.conf import settings from django.views.generic.base import RedirectView -from core.views import MainIndex, OldIndex, LinkDetails +from core.views import MainIndex, OldIndex, LinkDetails, PublicArchiveView # print('DEBUG', settings.DEBUG) @@ -31,4 +31,5 @@ urlpatterns = [ path('index.html', RedirectView.as_view(url='/')), path('index.json', static.serve, {'document_root': settings.OUTPUT_DIR, 'path': 'index.json'}), path('', MainIndex.as_view(), name='Home'), + path('public/', PublicArchiveView.as_view()) ] diff --git a/archivebox/core/views.py b/archivebox/core/views.py index 399f368e..a4e67a42 100644 --- a/archivebox/core/views.py +++ b/archivebox/core/views.py @@ -4,6 +4,7 @@ from django.shortcuts import render, redirect from django.http import HttpResponse from django.views import View, static +from django.views.generic.list import ListView from core.models import Snapshot @@ -102,3 +103,13 @@ class LinkDetails(View): content_type="text/plain", status=404, ) + +class PublicArchiveView(ListView): + template = 'snapshot_list.html' + model = Snapshot + context_object_name = 'links' + paginate_by = 2 + def get_context_data(self, *args, **kwargs): + context = super(PublicArchiveView, self).get_context_data(*args, **kwargs) + context['links'] = [snapshot.as_link for snapshot in Snapshot.objects.all()] + return context diff --git a/archivebox/themes/default/core/snapshot_list.html b/archivebox/themes/default/core/snapshot_list.html new file mode 100644 index 00000000..07dbe675 --- /dev/null +++ b/archivebox/themes/default/core/snapshot_list.html @@ -0,0 +1,281 @@ +{% load static %} + + + + + Archived Sites + + + + + + + + + + +
+
+ +
+
+ + + + + + + + + + + {% for link in links %} + + + + + + + {% endfor %} + +
BookmarkedSaved Link ({{num_links}})FilesOriginal URL
{{link.bookmarked_date}} + {% if link.is_archived %} + + {% else %} + + {% endif %} + + {{link.title|default:'Loading...'}} + {{link.tags|default:''}} + + + 📄 + {{link.num_outputs}} + + {{link.url}}
+ + + + From 948b2469f634c1c5a75d46eee93f5181504c73f0 Mon Sep 17 00:00:00 2001 From: apkallum Date: Thu, 20 Aug 2020 10:07:13 -0400 Subject: [PATCH 02/13] no files count in public view --- archivebox/themes/default/core/snapshot_list.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archivebox/themes/default/core/snapshot_list.html b/archivebox/themes/default/core/snapshot_list.html index 07dbe675..9bcff67e 100644 --- a/archivebox/themes/default/core/snapshot_list.html +++ b/archivebox/themes/default/core/snapshot_list.html @@ -255,7 +255,7 @@ 📄 - {{link.num_outputs}} + Entry to files {{link.url}} From c50af04cce49d46bdaaa99a0fd7226b76489a009 Mon Sep 17 00:00:00 2001 From: apkallum Date: Thu, 20 Aug 2020 16:43:28 -0400 Subject: [PATCH 03/13] search view inherits from modified public view --- archivebox/core/urls.py | 5 ++- archivebox/core/views.py | 41 ++++++++++++++++--- .../themes/default/core/snapshot_list.html | 37 ++++++++++++++--- 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/archivebox/core/urls.py b/archivebox/core/urls.py index bf5708d5..394bbbd0 100644 --- a/archivebox/core/urls.py +++ b/archivebox/core/urls.py @@ -5,7 +5,7 @@ from django.views import static from django.conf import settings from django.views.generic.base import RedirectView -from core.views import MainIndex, OldIndex, LinkDetails, PublicArchiveView +from core.views import MainIndex, OldIndex, LinkDetails, PublicArchiveView, SearchResultsView # print('DEBUG', settings.DEBUG) @@ -31,5 +31,6 @@ urlpatterns = [ path('index.html', RedirectView.as_view(url='/')), path('index.json', static.serve, {'document_root': settings.OUTPUT_DIR, 'path': 'index.json'}), path('', MainIndex.as_view(), name='Home'), - path('public/', PublicArchiveView.as_view()) + path('public/', PublicArchiveView.as_view(), name='public-index'), + path('search_results/', SearchResultsView.as_view(), name='search-results'), ] diff --git a/archivebox/core/views.py b/archivebox/core/views.py index a4e67a42..9a71c42a 100644 --- a/archivebox/core/views.py +++ b/archivebox/core/views.py @@ -3,9 +3,12 @@ __package__ = 'archivebox.core' from django.shortcuts import render, redirect from django.http import HttpResponse +from django.db.models import Q from django.views import View, static from django.views.generic.list import ListView +from django_datatables_view.base_datatable_view import BaseDatatableView + from core.models import Snapshot from ..index import load_main_index, load_main_index_meta @@ -107,9 +110,35 @@ class LinkDetails(View): class PublicArchiveView(ListView): template = 'snapshot_list.html' model = Snapshot - context_object_name = 'links' - paginate_by = 2 - def get_context_data(self, *args, **kwargs): - context = super(PublicArchiveView, self).get_context_data(*args, **kwargs) - context['links'] = [snapshot.as_link for snapshot in Snapshot.objects.all()] - return context + paginate_by = 50 + + def get_queryset(self, *args, **kwargs): + qs = super(PublicArchiveView, self).get_queryset(*args, **kwargs) + for snapshot in qs: + snapshot.canonical_outputs = snapshot.as_link().canonical_outputs() + return qs + + def get(self, *args, **kwargs): + if PUBLIC_INDEX or self.request.user.is_authenticated: + response = super().get(*args, **kwargs) + return response + else: + return redirect(f'/admin/login/?next={self.request.path}') + +# should we use it? +class SnapshotDatatableView(BaseDatatableView): + model = Snapshot + columns = ['url', 'timestamp', 'title', 'tags', 'added'] + + def filter_queryset(self, qs): + sSearch = self.request.GET.get('sSearch', None) + if sSearch: + qs = qs.filter(Q(title__icontains=sSearch)) + return qs + +class SearchResultsView(PublicArchiveView): + def get_queryset(self, *args, **kwargs): + qs = super(PublicArchiveView, self).get_queryset(*args, **kwargs) + query = self.request.GET.get('q') + results = qs.filter(title__icontains=query) + return results \ No newline at end of file diff --git a/archivebox/themes/default/core/snapshot_list.html b/archivebox/themes/default/core/snapshot_list.html index 9bcff67e..1acdd708 100644 --- a/archivebox/themes/default/core/snapshot_list.html +++ b/archivebox/themes/default/core/snapshot_list.html @@ -202,6 +202,8 @@ }, true) jQuery(document).ready(function() { jQuery('#table-bookmarks').DataTable({ + searching: false, + paging: false, stateSave: true, // save state (filtered input, number of entries shown, etc) in localStorage dom: 'ip>', // how to show the table and its helpers (filter, etc) in the DOM order: [[0, 'desc']], @@ -209,14 +211,14 @@ }); }); - +
- +
+ + + + + +
@@ -239,9 +248,9 @@ - {% for link in links %} + {% for link in object_list %} - +
Bookmarked
{{link.bookmarked_date}}{{link.added}} {% if link.is_archived %} @@ -263,6 +272,24 @@ {% endfor %}
+
+ + {% 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 %} + +
+