From 1cdaad00a8a9db8c70183c86d81f666a10cd476e Mon Sep 17 00:00:00 2001 From: apkallum Date: Wed, 26 Aug 2020 21:44:06 -0400 Subject: [PATCH] no more oldhome, cbvs uniform across views --- archivebox/core/urls.py | 5 +- archivebox/core/views.py | 92 +++---- archivebox/themes/default/add_links.html | 51 +--- .../themes/default/core/snapshot_list.html | 252 +----------------- 4 files changed, 49 insertions(+), 351 deletions(-) diff --git a/archivebox/core/urls.py b/archivebox/core/urls.py index 60548c2d..47c29942 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, add_view +from core.views import MainIndex, LinkDetails, PublicArchiveView, AddView # print('DEBUG', settings.DEBUG) @@ -18,7 +18,7 @@ urlpatterns = [ path('archive/', RedirectView.as_view(url='/')), path('archive/', LinkDetails.as_view(), name='LinkAssets'), - path('add/', add_view), + path('add/', AddView.as_view()), path('accounts/login/', RedirectView.as_view(url='/admin/login/')), path('accounts/logout/', RedirectView.as_view(url='/admin/logout/')), @@ -27,7 +27,6 @@ urlpatterns = [ path('accounts/', include('django.contrib.auth.urls')), path('admin/', admin.site.urls), - path('old.html', OldIndex.as_view(), name='OldHome'), 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'), diff --git a/archivebox/core/views.py b/archivebox/core/views.py index 4dee4612..78cdf99a 100644 --- a/archivebox/core/views.py +++ b/archivebox/core/views.py @@ -9,8 +9,7 @@ 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 django.views import View from core.models import Snapshot from core.utils import get_icons @@ -39,32 +38,10 @@ class MainIndex(View): return redirect('/admin/core/snapshot/') if PUBLIC_INDEX: - return redirect('OldHome') + return redirect('public-index') return redirect(f'/admin/login/?next={request.path}') - - -class OldIndex(View): - template = 'main_index.html' - - def get(self, request): - if PUBLIC_INDEX or request.user.is_authenticated: - all_links = load_main_index(out_dir=OUTPUT_DIR) - meta_info = load_main_index_meta(out_dir=OUTPUT_DIR) - - context = { - 'updated': meta_info['updated'], - 'num_links': meta_info['num_links'], - 'links': all_links, - 'VERSION': VERSION, - 'FOOTER_INFO': FOOTER_INFO, - } - - return render(template_name=self.template, request=request, context=context) - - return redirect(f'/admin/login/?next={request.path}') - class LinkDetails(View): def get(self, request, path): @@ -138,37 +115,38 @@ class PublicArchiveView(ListView): return redirect(f'/admin/login/?next={self.request.path}') -def add_view(request): - if PUBLIC_ADD_VIEW or request.user.is_authenticated: - context = { - 'title': 'Add URLs', +class AddView(View): + extra_context = {'title': 'Add URLs'} + + def get(self, request, *args, **kwargs): + if PUBLIC_ADD_VIEW or self.request.user.is_authenticated: + self.extra_context['form'] = AddLinkForm() + return render(template_name='add_links.html', request=request, context=self.extra_context) + else: + return redirect(f'/admin/login/?next={request.path}') + + def post(self, request, *args, **kwargs): + form = AddLinkForm(request.POST) + if form.is_valid(): + url = form.cleaned_data["url"] + print(f'[+] Adding URL: {url}') + depth = 0 if form.cleaned_data["depth"] == "0" else 1 + input_kwargs = { + "urls": url, + "depth": depth, + "update_all": False, + "out_dir": OUTPUT_DIR, } - if request.method == 'GET': - context['form'] = AddLinkForm() + add_stdout = StringIO() + with redirect_stdout(add_stdout): + add(**input_kwargs) + print(add_stdout.getvalue()) - elif request.method == 'POST': - form = AddLinkForm(request.POST) - if form.is_valid(): - url = form.cleaned_data["url"] - print(f'[+] Adding URL: {url}') - depth = 0 if form.cleaned_data["depth"] == "0" else 1 - input_kwargs = { - "urls": url, - "depth": depth, - "update_all": False, - "out_dir": OUTPUT_DIR, - } - add_stdout = StringIO() - with redirect_stdout(add_stdout): - add(**input_kwargs) - print(add_stdout.getvalue()) - - context.update({ - "stdout": ansi_to_html(add_stdout.getvalue().strip()), - "form": AddLinkForm() - }) - else: - context["form"] = form - return render(template_name='add_links.html', request=request, context=context) - else: - return redirect(f'/admin/login/?next={request.path}') \ No newline at end of file + self.extra_context.update({ + "stdout": ansi_to_html(add_stdout.getvalue().strip()), + "form": AddLinkForm() + }) + else: + self.extra_context["form"] = form + + return render(template_name='add_links.html', request=request, context=self.extra_context) \ No newline at end of file diff --git a/archivebox/themes/default/add_links.html b/archivebox/themes/default/add_links.html index 80a4b1fc..57bbffe4 100644 --- a/archivebox/themes/default/add_links.html +++ b/archivebox/themes/default/add_links.html @@ -1,4 +1,6 @@ -{% extends "admin/index.html" %} +{% extends "base.html" %} + +{% load static %} {% load i18n %} {% block breadcrumbs %} @@ -8,48 +10,11 @@ {% endblock %} -{% block content %} - +{% block extra_head %} + +{% endblock %} + +{% block body %}


{% if stdout %} diff --git a/archivebox/themes/default/core/snapshot_list.html b/archivebox/themes/default/core/snapshot_list.html index ec92db14..8cb4cec5 100644 --- a/archivebox/themes/default/core/snapshot_list.html +++ b/archivebox/themes/default/core/snapshot_list.html @@ -1,237 +1,8 @@ +{% extends "base.html" %} {% load static %} - - - - Archived Sites - - - - - - - - - - -
-
- -
-
-
+{% block body %} +
@@ -290,19 +61,4 @@
- - - - + {% endblock %} \ No newline at end of file