summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/utils.py36
-rw-r--r--core/views/other.py8
-rw-r--r--urls.py4
3 files changed, 30 insertions, 18 deletions
diff --git a/core/utils.py b/core/utils.py
index d86b901..3cb2d8a 100644
--- a/core/utils.py
+++ b/core/utils.py
@@ -283,7 +283,7 @@ def is_admin_user(user):
return False
if user.username in ["expoadmin"]:
return True
- if user.is_superuser: # set in parsers/users.py i.e. WOokey, Philip S.
+ if user.is_superuser: # set in parsers/users.py i.e. Wookey, Philip S.
return True
return False
@@ -426,21 +426,24 @@ def write_binary_file(filepath, content):
write_files([(filepath, content, "")]) # null encoding does "wb"
def ensure_dir_exists(filepath):
- if filepath.is_dir():
- raise OSError(
- f"CANNOT write this file {filepath} as this is an existing DIRECTORY."
- )
- try:
- filepath.parent.mkdir(parents=True, exist_ok=True)
- # os.makedirs(os.path.dirname(filepath), exist_ok = True)
- except PermissionError as e:
- raise PermissionError(
- f"CANNOT make the directory.\nPERMISSIONS incorrectly set on server for this file {filepath}. Ask a nerd to fix this: {e}"
- )
- except Exception as e:
- raise OSError(
- f"CANNOT make the directory for {filepath}. Ask a nerd to fix this: {e}"
- )
+ """Takes a filepath for a file and all the parent directiories,
+ makes any directories necessary to make the filepath valid
+ """
+ if filepath.is_dir():
+ raise OSError(
+ f"CANNOT write this file {filepath} as this is an existing DIRECTORY."
+ )
+ try:
+ filepath.parent.mkdir(parents=True, exist_ok=True)
+ # os.makedirs(os.path.dirname(filepath), exist_ok = True)
+ except PermissionError as e:
+ raise PermissionError(
+ f"CANNOT make the directory.\nPERMISSIONS incorrectly set on server for this file {filepath}. Ask a nerd to fix this: {e}"
+ )
+ except Exception as e:
+ raise OSError(
+ f"CANNOT make the directory for {filepath}. Ask a nerd to fix this: {e}"
+ )
def write_files(files):
for filepath, content, encoding in files:
@@ -528,6 +531,7 @@ def find_nearest_point(points, target_point):
TODO FIND OUT
1. is this SRTM data ? TICK. Yes.
2. what is the zero altitude datum? Geoid or ellisoid ? Do we need to subtract 47m ??
+ 3. remove all these numbers from the .py file as it is confusing the code length calcs
In our dataset, the survey stations are all within 30m of an srtm reference point.
So we can safely ignore points more than 100m away in either x or y directions.
diff --git a/core/views/other.py b/core/views/other.py
index 18ab31f..6d1b175 100644
--- a/core/views/other.py
+++ b/core/views/other.py
@@ -11,7 +11,7 @@ from troggle.core.models.logbooks import LogbookEntry, writelogbook # , PersonL
# from databaseReset import reinit_db # don't do this. databaseRest runs code *at import time*
from troggle.core.models.troggle import Expedition
-from troggle.core.utils import current_expo
+from troggle.core.utils import current_expo, COOKIE_MAX_AGE
from troggle.parsers.imports import (
import_caves,
import_drawingsfiles,
@@ -36,6 +36,12 @@ todo = """
to the website.
"""
+def public_laptop(request):
+ """Just sets a cookie. Visit this web page from Crowley, Anathema, Aziraphale, Pulsifer etc.
+ """
+ response = HttpResponse("Cookie has been set on this machine, which now defines it as a public laptop. So login cookie lifetimes will now be short.")
+ response.set_cookie("public_laptop", "this is a public laptop", max_age=COOKIE_MAX_AGE) # Cookie expires in 1 hour
+ return response
def todos(request, module):
"""produces todo text from module
diff --git a/urls.py b/urls.py
index 5dcad03..8f46e84 100644
--- a/urls.py
+++ b/urls.py
@@ -55,7 +55,7 @@ from troggle.core.views.logbooks import (
person,
personexpedition,
)
-from troggle.core.views.other import controlpanel, exportlogbook, frontpage, todos
+from troggle.core.views.other import controlpanel, exportlogbook, frontpage, todos, public_laptop
from troggle.core.views.prospect import prospecting
from troggle.core.views.user_registration import register, newregister, reset_done, ExpoPasswordResetForm
from troggle.core.views.scans import allscans, cavewallets, scansingle, walletslistperson, walletslistyear
@@ -212,6 +212,8 @@ trogglepatterns = [
path('accounts/password_reset/', PasswordResetView.as_view(form_class=ExpoPasswordResetForm), name='password_reset'),
path('accounts/reset/<uidb64>/<token>/', PasswordResetConfirmView.as_view(), name="password_reset_confirm"),
path('accounts/', include('django.contrib.auth.urls')), # see line 109 in this file NB initial "/accounts/" in URL
+
+ path('expo_laptop', public_laptop, name="public_laptop"),
path('person/<slug:slug>', person, name="person"),
path('personexpedition/<slug:slug>/<int:year>', personexpedition, name="personexpedition"),