diff --git a/archivebox/core/admin.py b/archivebox/core/admin.py index 97ac7712..6a9fcdae 100644 --- a/archivebox/core/admin.py +++ b/archivebox/core/admin.py @@ -6,7 +6,7 @@ from contextlib import redirect_stdout from django.contrib import admin from django.urls import path from django.utils.html import format_html -from django.shortcuts import render +from django.shortcuts import render, redirect from django.contrib.auth import get_user_model from core.models import Snapshot @@ -103,10 +103,13 @@ class ArchiveBoxAdmin(admin.AdminSite): def get_urls(self): return [ - path('core/snapshot/add/', self.add_view, name='add'), + path('core/snapshot/add/', self.add_view, name='Add'), ] + super().get_urls() def add_view(self, request): + if not request.user.is_authenticated: + return redirect(f'/admin/login/?next={request.path}') + request.current_app = self.name context = { **self.each_context(request), diff --git a/archivebox/core/urls.py b/archivebox/core/urls.py index 0c1f8131..b830de68 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, LinkDetails +from core.views import MainIndex, OldIndex, LinkDetails # print('DEBUG', settings.DEBUG) @@ -14,6 +14,8 @@ urlpatterns = [ 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/pirate/ArchiveBox/wiki'), name='Docs'), + path('archive/', RedirectView.as_view(url='/')), path('archive/', LinkDetails.as_view(), name='LinkAssets'), path('add/', RedirectView.as_view(url='/admin/core/snapshot/add/')), @@ -25,8 +27,8 @@ urlpatterns = [ path('accounts/', include('django.contrib.auth.urls')), path('admin/', admin.site.urls), - path('old.html', MainIndex.as_view(), name='OldHome'), + 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('', RedirectView.as_view(url='/admin/core/snapshot/'), name='Home'), + path('', MainIndex.as_view(), name='Home'), ] diff --git a/archivebox/core/views.py b/archivebox/core/views.py index 1eb8fc20..7ce4eb82 100644 --- a/archivebox/core/views.py +++ b/archivebox/core/views.py @@ -22,21 +22,35 @@ class MainIndex(View): template = 'main_index.html' def get(self, request): - if not request.user.is_authenticated and not PUBLIC_INDEX: - return redirect(f'/admin/login/?next={request.path}') + if request.user.is_authenticated: + return redirect('/admin/core/snapshot/') - all_links = load_main_index(out_dir=OUTPUT_DIR) - meta_info = load_main_index_meta(out_dir=OUTPUT_DIR) + if PUBLIC_INDEX: + return redirect('OldHome') + + return redirect(f'/admin/login/?next={request.path}') - 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) +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): diff --git a/archivebox/themes/admin/base.html b/archivebox/themes/admin/base.html index 2a67873e..f961194f 100644 --- a/archivebox/themes/admin/base.html +++ b/archivebox/themes/admin/base.html @@ -32,10 +32,11 @@ {% block usertools %} {% if has_permission %}
- Add Links / - Main Index / - Admin / - Docs + Index / + Add URLs / + Admin / + Old UI / + Docs     {% block welcome-msg %} {% trans 'User' %} diff --git a/archivebox/themes/admin/login.html b/archivebox/themes/admin/login.html index a6d8eac7..98283f80 100644 --- a/archivebox/themes/admin/login.html +++ b/archivebox/themes/admin/login.html @@ -11,7 +11,7 @@ {% block usertools %}
- Back to Main Index + Back to Main Index {% endblock %} {% block nav-global %}{% endblock %}