1
0
Fork 0
mirror of synced 2024-06-16 17:35:15 +12:00

use proper url naming instead of hardcoding paths

This commit is contained in:
Nick Sweeting 2020-07-27 23:56:35 -04:00
parent b8c8c4a599
commit d70bb7980e
5 changed files with 42 additions and 22 deletions

View file

@ -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),

View file

@ -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/<path:path>', 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'),
]

View file

@ -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):

View file

@ -32,10 +32,11 @@
{% block usertools %}
{% if has_permission %}
<div id="user-tools">
<a href="/add/">Add Links</a> /
<a href="/">Main Index</a> /
<a href="/admin/">Admin</a> /
<a href="https://github.com/pirate/ArchiveBox/wiki">Docs</a>
<a href="{% url 'Home' %}">Index</a> /
<a href="{% url 'admin:Add' %}">Add URLs</a> /
<a href="{% url 'admin:index' %}">Admin</a> /
<a href="{% url 'OldHome' %}">Old UI</a> /
<a href="{% url 'Docs' %}">Docs</a>
&nbsp; &nbsp;
{% block welcome-msg %}
{% trans 'User' %}

View file

@ -11,7 +11,7 @@
{% block usertools %}
<br/>
<a href="/">Back to Main Index</a>
<a href="{% url 'Home' %}">Back to Main Index</a>
{% endblock %}
{% block nav-global %}{% endblock %}