not found now does 404 & moved login

This commit is contained in:
Philip Sargent
2021-05-03 20:35:35 +01:00
parent 254b465755
commit 9b9f6720e0
8 changed files with 37 additions and 35 deletions

View File

@@ -1,8 +1,27 @@
from builtins import str
from django.conf import settings
from django.shortcuts import render
from django.http import Http404, HttpResponseRedirect
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth import forms as auth_forms
from django.contrib.auth.decorators import login_required
"""This enforces the login requirement for non-public pages using
the decorator mechanism.
https://www.fullstackpython.com/django-contrib-auth-decorators-login-required-examples.html
"""
class login_required_if_public(object):
def __init__(self, f):
if settings.PUBLIC_SITE:
self.f = login_required(f)
else:
self.f = f
def __call__(self, *args, **kwargs):
return self.f(*args, **kwargs)
# This is copied from CUYC.cuy.website.view.auth
# If we want to do the whole online-email thing, we would also need to copy across the code in these

View File

@@ -20,7 +20,7 @@ from troggle.core.models.troggle import Expedition, DataIssue
from troggle.core.models.caves import CaveSlug, Cave, CaveAndEntrance, QM, EntranceSlug, Entrance, Area, SurvexStation, GetCaveLookup
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, EntranceForm, EntranceLetterForm
#from troggle.core.forms import VersionControlCommentForm
from .login import login_required_if_public
from .auth import login_required_if_public
'''Manages the complex procedures to assemble a cave description out of the compnoents
Manages the use of cavern to parse survex files to produce 3d and pos files

View File

@@ -14,7 +14,7 @@ from django.contrib import admin
import django.forms as forms
from .login import login_required_if_public
from .auth import login_required_if_public
from troggle.core.models.caves import Cave
import troggle.core.views.caves
import troggle.settings as settings
@@ -121,7 +121,7 @@ def expowebpage(request, expowebpath, path):
'''Adds menus and serves an HTML page
'''
if not Path(expowebpath / path).is_file():
return render(request, 'pagenotfound.html', {'path': path})
return render(request, 'pagenotfound.html', {'path': path}, status="404")
with open(os.path.normpath(expowebpath / path), "r") as o:
html = o.read()
@@ -164,9 +164,9 @@ def mediapage(request, subpath=None, doc_root=None):
try:
return HttpResponse(content=open(filetobeopened, "rb"), content_type=getmimetype(subpath))
except IOError:
return render(request, 'pagenotfound.html', {'path': subpath})
return render(request, 'pagenotfound.html', {'path': subpath}, status="404")
else:
return render(request, 'pagenotfound.html', {'path': subpath})
return render(request, 'pagenotfound.html', {'path': subpath}, status="404")
@@ -196,7 +196,7 @@ def expopage(request, path):
if (expowebpath / path / p).is_file():
# This needs to reset the path to the new subdirectory
return HttpResponseRedirect('/'+str(Path(path) / p))
return render(request, 'pagenotfound.html', {'path': Path(path) / "index.html"})
return render(request, 'pagenotfound.html', {'path': Path(path) / "index.html"}, status="404")
if path.endswith("/"):
# we already know it is not a directory.
@@ -210,7 +210,7 @@ def expopage(request, path):
try:
return HttpResponse(content=open(filetobeopened, "rb"), content_type=getmimetype(path))
except IOError:
return render(request, 'pagenotfound.html', {'path': path})
return render(request, 'pagenotfound.html', {'path': path}, status="404")
@@ -310,7 +310,7 @@ def editexpopage(request, path):
git = settings.GIT
with open(filepath, "w") as f:
f.write(result)
print(f'WROTE {cwd}---{filename} ')
#print(f'WROTE {cwd}---{filename} ')
subprocess.call([git, "add", filename], cwd=cwd)
subprocess.call([git, "commit", "-m", 'Edit this page'], cwd=cwd)

View File

@@ -16,7 +16,7 @@ from troggle.core.models.troggle import Expedition, Person, PersonExpedition
from troggle.core.utils import TROG
from troggle.core.models.caves import LogbookEntry, PersonTrip
from troggle.core.models.survex import SurvexBlock
from .login import login_required_if_public
from .auth import login_required_if_public
from troggle.parsers.logbooks import LoadLogbookForExpedition
from troggle.parsers.people import GetPersonExpeditionNameLookup

View File

@@ -1,17 +0,0 @@
from django.contrib.auth.decorators import login_required
from django.conf import settings
"""This enforces the login requirement for non-public pages using
the decorator mechanism.
https://www.fullstackpython.com/django-contrib-auth-decorators-login-required-examples.html
"""
class login_required_if_public(object):
def __init__(self, f):
if settings.PUBLIC_SITE:
self.f = login_required(f)
else:
self.f = f
def __call__(self, *args, **kwargs):
return self.f(*args, **kwargs)

View File

@@ -16,7 +16,7 @@ from troggle.parsers.imports import import_logbooks, import_QMs, import_drawings
# from databaseReset import reinit_db # don't do this. databaseRest runs code *at import time*
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
from troggle.core.models.caves import LogbookEntry, QM, Cave, PersonTrip
from .login import login_required_if_public
from .auth import login_required_if_public
'''Utility functions and code to serve the control panel and individual user's
progress and task list (deprecated as we do not have individual user login).