From 12fa55f53706135554c8fa7e8d2b2b64aa34b6cb Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Wed, 17 Jul 2024 21:58:27 +0200 Subject: [PATCH] new entry deletuion capability --- core/views/logbooks.py | 35 ++++++++++++++++++++++++++++++++++- parsers/survex.py | 4 ++-- templates/logreport.html | 17 +++++++++++++++-- urls.py | 4 +++- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/core/views/logbooks.py b/core/views/logbooks.py index b3f3176..2c15a1e 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -3,9 +3,11 @@ import re from django.db.models import Q from django.shortcuts import render from django.views.generic.list import ListView +from django.shortcuts import render, redirect + import troggle.settings as settings -from troggle.core.models.logbooks import LogbookEntry, PersonLogEntry, QM +from troggle.core.models.logbooks import LogbookEntry, PersonLogEntry, QM, writelogbook from troggle.core.models.survex import SurvexBlock, SurvexFile from troggle.core.models.troggle import Expedition, Person from troggle.core.models.wallets import Wallet @@ -218,6 +220,31 @@ def personexpedition(request, slug="", year=""): print(msg) return render(request, "errors/generic.html", {"message": msg}) +def logentrydelete(request, year): + """This only gets called by a POST from the logreport page + + The function in memory of James Waite who managed to make so many duplicate logbook entries + that we needed a sopecial mechanism to delete them. + """ + eslug = request.POST["entry_slug"] + entry = LogbookEntry.objects.get(slug=eslug) + # OK we delete it formt he db and then re-save logbook.html file + # to ensure that the permanent record also has the entry deleted. + entry.delete() + + print(f"- Rewriting the entire {year} logbook to disc ") + filename= "logbook.html" + try: + writelogbook(year, filename) # uses a template + except: + message = f'! - Logbook saving failed - \n!! Permissions failure ?! on attempting to save file "logbook.html"' + print(message) + return render(request, "errors/generic.html", {"message": message}) + + + return redirect(f"/logreport/{year}") + + def logreport(request, year=1999): """ Remember that 'personexpedition__expedition' is interpreted by Django to mean the @@ -231,7 +258,12 @@ def logreport(request, year=1999): expeditions = Expedition.objects.all() # top menu only, evaluated only when template renders dates = None dateditems = None + logged_in = False + + if request.user.is_superuser: # expoadmin is both .is_staff and ._is_superuser + logged_in = True + try: expo = Expedition.objects.get(year=int(year)) @@ -265,6 +297,7 @@ def logreport(request, year=1999): "settings": settings, "dateditems": dateditems, "dates": dates, + "logged_in": logged_in, } # print(f"logreport(): rendering..") return render(request, "logreport.html", context) diff --git a/parsers/survex.py b/parsers/survex.py index 5c59e6d..fb0f8d3 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -291,7 +291,7 @@ class LoadingSurvex: rx_include = re.compile(r"(?i)^\s*(\*include[\s].*)$") rx_include2 = re.compile("(?i)include$") rx_commref = re.compile(r"(?i)^\s*ref(?:erence)?[\s.:]*(\d+)\s*#\s*(X)?\s*(\d+)") - rx_ref_text = re.compile(r'(?i)^\s*\"[^"]*\"\s*$') + rx_ref_text = re.compile(r'(?i)^\s*\"[^"]*\"\s*$') rx_star = re.compile(r"(?i)\s*\*[\s,]*(\w+)\s*(.*?)\s*(?:;.*)?$") rx_starref = re.compile(r"(?i)^\s*\*ref[\s.:]*((?:19[6789]\d)|(?:20[0123]\d))\s*#?\s*(X)?\s*(.*?\d+.*?)$") rx_argsref = re.compile(r"(?i)^[\s.:]*((?:19[6789]\d)|(?:20[012345]\d))\s*#?\s*(X)?\s*(.*?\d+.*?)$") @@ -2689,7 +2689,7 @@ def survexifywallets(): if b.parent.scanswallet != sentinelbad: b.scanswallet = b.parent.scanswallet continue - message = f" ! *REF missing {b.date} {b.survexfile}.svx : '{b}'" + message = f" ! *REF missing {b.date} {b.survexfile}.svx : '{b}'" # msg appears if a *ref "something in quotes" actually does exist. if b.date > date(2019, 1, 1) and b.date < date(2020, 1, 1): print(message, file=sys.stderr) url = get_offending_filename(b.survexfile.path) diff --git a/templates/logreport.html b/templates/logreport.html index b76b979..5db7c76 100644 --- a/templates/logreport.html +++ b/templates/logreport.html @@ -19,9 +19,14 @@

(Hover mouse over the date to see the slug for the entry.) +{% if logged_in %}Logged in as expoadmin{% endif %} + + - + +{% if logged_in %}{% endif %} + {% regroup dateditems|dictsort:"date" by date as dates %} {% for date in dates %} {% for entry in date.list %} @@ -52,12 +57,20 @@ {{w.nickname_used}}, {% endfor %} {% endif %} - + +{% if logged_in %} +{% csrf_token %} + + +{% endif %} {% endfor %} {% endfor %}
DateLogged trips and diary entriesCaveText..WordsAuthorWho else
DateLogged trips and diary entriesCaveText..WordsAuthorWho elseAdmin
+
+ +

See also: