Browse Source

no more oldhome, cbvs uniform across views

apkallum 5 years ago
parent
commit
1cdaad00a8

+ 2 - 3
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/<path:path>', 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'),

+ 36 - 58
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()
-
-            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}')
+            add_stdout = StringIO()
+            with redirect_stdout(add_stdout):
+                add(**input_kwargs)
+                print(add_stdout.getvalue())
+
+            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)

+ 8 - 43
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 @@
     </div>
 {% endblock %}
 
-{% block content %}
-    <style>
-        .dashboard #content {
-            width: 100%;
-            margin-right: 0px;
-            margin-left: 0px;
-        }
-        #submit {
-            border: 1px solid rgba(0,0,0,0.2);
-            padding: 10px;
-            border-radius: 4px;
-            background-color: #f5dd5d;
-            color: #333;
-            font-size: 18px;
-            font-weight: 800;
-        }
-        #add-form button[role=submit]:hover {
-            background-color: #e5cd4d;
-        }
-        #add-form label {
-            display: block;
-            font-size: 16px;
-        }
-        #add-form textarea {
-            width: 100%;
-            min-height: 300px;
-        }
-        #delay-warning div {
-            border: 1px solid red;
-            border-radius: 4px;
-            margin: 10px;
-            padding: 10px;
-            font-size: 15px;
-            background-color: #F5DD5D;
-        }
-        #stdout {
-            background-color: #ded;
-            padding: 10px 10px;
-            border-radius: 4px;
-            white-space: normal;
-        }
-    </style>
+{% block extra_head %}
+    <link rel="stylesheet" href="{% static 'add.css' %}" />
+{% endblock %}
+
+{% block body %}
     <div style="max-width: 550px; margin: auto; float: none">
         <br/><br/>
         {% if stdout %}

+ 4 - 248
archivebox/themes/default/core/snapshot_list.html

@@ -1,237 +1,8 @@
+{% extends "base.html" %}
 {% load static %}
 
-<!DOCTYPE html>
-<html lang="en">
-    <head>
-        <title>Archived Sites</title>
-        <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1">
-        <style>
-            :root {
-                --bg-main: #efefef;
-                --accent-1: #aa1e55;
-                --accent-2: #ffebeb;
-                --accent-3: #efefef;
-
-                --text-1: #1c1c1c;
-                --text-2: #eaeaea;
-                --text-main: #1a1a1a;
-                --font-main: "Gill Sans", Helvetica, sans-serif;
-            }
-            /* Dark Mode (WIP) */
-            /*
-            @media (prefers-color-scheme: dark) {
-                :root {
-                    --accent-2: hsl(160, 100%, 96%);
-
-                    --text-1: #eaeaea;
-                    --text-2: #1a1a1a;
-                    --bg-main: #101010;
-                }
-
-                #table-bookmarks_wrapper,
-                #table-bookmarks_wrapper img,
-                tbody td:nth-child(3),
-                tbody td:nth-child(3) span,
-                footer {
-                    filter: invert(100%);
-                }
-            }*/
-
-            html, body {
-                width: 100%;
-                height: 100%;
-                font-size: 18px;
-                font-weight: 200;
-                text-align: center;
-                margin: 0px;
-                padding: 0px;
-                font-family: var(--font-main);
-            }
-
-            .header-top small {
-                font-weight: 200;
-                color: var(--accent-3);
-            }
-            
-            .header-top {
-                width: 100%;
-                height: auto;
-                min-height: 40px;
-                margin: 0px;
-                text-align: center;
-                color: white;
-                font-size: calc(11px + 0.84vw);
-                font-weight: 200;
-                padding: 4px 4px;
-                border-bottom: 3px solid var(--accent-1);
-                background-color: var(--accent-1);
-            }
-            input[type=search] {
-                width: 22vw;
-                border-radius: 4px;
-                border: 1px solid #aeaeae;
-                padding: 3px 5px;
-            }
-            .nav > div {
-                min-height: 30px;
-            }
-            .header-top a {
-                text-decoration: none;
-                color: rgba(0,0,0,0.6);
-            }
-            .header-top a:hover {
-                text-decoration: none;
-                color: rgba(0,0,0,0.9);
-            }
-            .header-top .col-lg-4 {
-                text-align: center;
-                padding-top: 4px;
-                padding-bottom: 4px;
-            }
-            .header-archivebox img {
-                display: inline-block;
-                margin-right: 3px;
-                height: 30px;
-                margin-left: 12px;
-                margin-top: -4px;
-                margin-bottom: 2px;
-            }
-            .header-archivebox img:hover {
-                opacity: 0.5;
-            }
-
-            #table-bookmarks_length, #table-bookmarks_filter {
-                padding-top: 12px;
-                opacity: 0.8;
-                padding-left: 24px;
-                padding-right: 22px;
-                margin-bottom: -16px;
-            }
-            table {
-                padding: 6px;
-                width: 100%;
-            }
-            table thead th {
-                font-weight: 400;
-            }
-            table tr {
-                height: 35px;
-            }
-            tbody tr:nth-child(odd) {
-               background-color: var(--accent-2) !important;
-            }
-            table tr td {
-                white-space: nowrap;
-                overflow: hidden;
-                /*padding-bottom: 0.4em;*/
-                /*padding-top: 0.4em;*/
-                padding-left: 2px;
-                text-align: center;
-            }
-            table tr td a {
-                text-decoration: none;
-            }
-            table tr td img, table tr td object {
-                display: inline-block;
-                margin: auto;
-                height: 24px;
-                width: 24px;
-                padding: 0px;
-                padding-right: 5px;
-                vertical-align: middle;
-                margin-left: 4px;
-            }
-            #table-bookmarks {
-                width: 100%; 
-                overflow-y: scroll;
-                table-layout: fixed;
-            }
-            .dataTables_wrapper {
-                background-color: #fafafa;
-            }
-            table tr a span[data-archived~=False] {
-                opacity: 0.4;
-            }
-            .files-spinner {
-                height: 15px;
-                width: auto;
-                opacity: 0.5;
-                vertical-align: -2px;
-            }
-            .in-progress {
-                display: none;
-            }
-            body[data-status~=finished] .files-spinner {
-                display: none;
-            }
-            /*body[data-status~=running] .in-progress {
-                display: inline-block;
-            }*/
-            tr td a.favicon img {
-                padding-left: 6px;
-                padding-right: 12px;
-                vertical-align: -4px;
-            }
-            tr td a.title {
-                font-size: 1.4em;
-                text-decoration:none;
-                color:black;
-            }
-            tr td a.title small {
-                background-color: var(--accent-3);
-                border-radius: 4px;
-                float:right
-            }
-            input[type=search]::-webkit-search-cancel-button {
-                -webkit-appearance: searchfield-cancel-button;
-            }
-            .title-col {
-                text-align: left;
-            }
-            .title-col a {
-                color: black;
-            }
-        </style>
-        <link rel="stylesheet" href="{% static 'bootstrap.min.css' %}">
-        <link rel="stylesheet" href="{% static 'jquery.dataTables.min.css' %}"/>
-        <script src="{% static 'jquery.min.js' %}"></script>
-        <script src="{% static 'jquery.dataTables.min.js' %}"></script>
-        <script>
-            document.addEventListener('error', function(e) {
-              e.target.style.opacity = 0;
-            }, 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: '<lf<t>ip>', // how to show the table and its helpers (filter, etc) in the DOM
-                    order: [[0, 'desc']],
-                    iDisplayLength: 100,
-                });
-            });
-        </script>
-        <base href="{% url 'Home' %}">
-    </head>
-    <body data-status="finished">
-        <header>
-            <div class="header-top container-fluid">
-                <div class="row nav">
-                    <div class="col-sm-2">
-                        <a href="{% url 'public-index' %}" class="header-archivebox" title="Last updated: {{updated}}">
-                            <img src="{% static 'archive.png' %}" alt="Logo"/>
-                            ArchiveBox: Index
-                        </a>
-                    </div>
-                    <div class="col-sm-10" style="text-align: right">
-                        <a href="/add/">Add Links</a> &nbsp; | &nbsp; 
-                        <a href="/admin/core/snapshot/">Admin</a> &nbsp; | &nbsp; 
-                        <a href="https://github.com/pirate/ArchiveBox/wiki">Docs</a>
-                    </div>
-                </div>
-            </div>
-        </header>
-        <br>
+{% block body %}
+<br>
         <form action="{% url 'public-index' %}" method="get">
             <input name="q" type="text" placeholder="Search...">
             <button type="submit">Search</button>
@@ -290,19 +61,4 @@
             </span>
             <br>
     </center>
-        <footer>
-            <br/>
-            <center>
-                <small>
-                    Archive created using <a href="https://github.com/pirate/ArchiveBox" title="Github">ArchiveBox</a>
-                    version <a href="https://github.com/pirate/ArchiveBox/tree/v{{VERSION}}" title="Git commit">v{{VERSION}}</a> &nbsp; | &nbsp; 
-                    Download index as <a href="index.json" title="JSON summary of archived links.">JSON</a>
-                    <br/><br/>
-                    {{FOOTER_INFO}}
-                </small>
-            </center>
-            <br/>
-        </footer>
-    </body>
-</html>
-
+        {% endblock %}