2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

new entry deletuion capability

This commit is contained in:
Philip Sargent 2024-07-17 21:58:27 +02:00
parent 6729698d7b
commit 12fa55f537
4 changed files with 54 additions and 6 deletions

View File

@ -3,9 +3,11 @@ import re
from django.db.models import Q from django.db.models import Q
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.shortcuts import render, redirect
import troggle.settings as settings 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.survex import SurvexBlock, SurvexFile
from troggle.core.models.troggle import Expedition, Person from troggle.core.models.troggle import Expedition, Person
from troggle.core.models.wallets import Wallet from troggle.core.models.wallets import Wallet
@ -218,6 +220,31 @@ def personexpedition(request, slug="", year=""):
print(msg) print(msg)
return render(request, "errors/generic.html", {"message": 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): def logreport(request, year=1999):
""" """
Remember that 'personexpedition__expedition' is interpreted by Django to mean the Remember that 'personexpedition__expedition' is interpreted by Django to mean the
@ -231,6 +258,11 @@ def logreport(request, year=1999):
expeditions = Expedition.objects.all() # top menu only, evaluated only when template renders expeditions = Expedition.objects.all() # top menu only, evaluated only when template renders
dates = None dates = None
dateditems = None dateditems = None
logged_in = False
if request.user.is_superuser: # expoadmin is both .is_staff and ._is_superuser
logged_in = True
try: try:
@ -265,6 +297,7 @@ def logreport(request, year=1999):
"settings": settings, "settings": settings,
"dateditems": dateditems, "dateditems": dateditems,
"dates": dates, "dates": dates,
"logged_in": logged_in,
} }
# print(f"logreport(): rendering..") # print(f"logreport(): rendering..")
return render(request, "logreport.html", context) return render(request, "logreport.html", context)

View File

@ -2689,7 +2689,7 @@ def survexifywallets():
if b.parent.scanswallet != sentinelbad: if b.parent.scanswallet != sentinelbad:
b.scanswallet = b.parent.scanswallet b.scanswallet = b.parent.scanswallet
continue 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): if b.date > date(2019, 1, 1) and b.date < date(2020, 1, 1):
print(message, file=sys.stderr) print(message, file=sys.stderr)
url = get_offending_filename(b.survexfile.path) url = get_offending_filename(b.survexfile.path)

View File

@ -19,9 +19,14 @@
</p> </p>
<p>(Hover mouse over the date to see the slug for the entry.) <p>(Hover mouse over the date to see the slug for the entry.)
{% if logged_in %}<font color="red">Logged in as expoadmin</font>{% endif %}
<table class="expeditionlogbooks"> <table class="expeditionlogbooks">
<tr><th>Date</th><th>Logged trips and diary entries</th><th>Cave</th><th>Text..</th><th>Words</th><th>Author</th><th>Who else</th></tr> <tr><th>Date</th><th>Logged trips and diary entries</th><th>Cave</th><th>Text..</th><th>Words</th><th>Author</th><th>Who else</th>
{% if logged_in %}<th><font color="red">Admin</font></th>{% endif %}
</tr>
{% regroup dateditems|dictsort:"date" by date as dates %} {% regroup dateditems|dictsort:"date" by date as dates %}
{% for date in dates %} {% for date in dates %}
{% for entry in date.list %} {% for entry in date.list %}
@ -54,11 +59,19 @@
{% endif %} {% endif %}
</td> </td>
{% if logged_in %}
<form name="import" method="post" action="/logentrydelete/{{year}}">{% csrf_token %}
<td><input type="hidden" value="{{entry.slug}}" name="entry_slug">
<input type="submit" value="delete"></td>
</form>
{% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
</table> </table>
<p>See also: <p>See also:
<ul> <ul>
<li> <a href="/expedition/{{expedition.year}}">full calendar page</a> for this Expo (slow page) <li> <a href="/expedition/{{expedition.year}}">full calendar page</a> for this Expo (slow page)

View File

@ -15,7 +15,7 @@ from troggle.core.views.expo import (pubspage, indexpage, editexpopage, expofile
expofilessingle, expopage, map, mapfile, expofilessingle, expopage, map, mapfile,
mediapage, spider) mediapage, spider)
from troggle.core.views.logbooks import (QMs_jsonListView, Expeditions_jsonListView, from troggle.core.views.logbooks import (QMs_jsonListView, Expeditions_jsonListView,
Expeditions_tsvListView, expedition, logreport, Expeditions_tsvListView, expedition, logreport, logentrydelete,
get_logbook_entries, get_people, get_logbook_entries, get_people,
logbookentry, notablepersons, person, logbookentry, notablepersons, person,
personexpedition) personexpedition)
@ -150,6 +150,8 @@ trogglepatterns = [
re_path(r'^logbookentry/(?P<date>.*)/(?P<slug>.*)/?$', logbookentry,name="logbookentry"), re_path(r'^logbookentry/(?P<date>.*)/(?P<slug>.*)/?$', logbookentry,name="logbookentry"),
re_path(r'^logbook$', exportlogbook, name='exportlogbook'), re_path(r'^logbook$', exportlogbook, name='exportlogbook'),
path('logreport/<slug:year>', logreport, name='logreport'), path('logreport/<slug:year>', logreport, name='logreport'),
path('logentrydelete/<slug:year>', logentrydelete, name='logentrydelete'),
# Internal. editfile.html template uses these internally # Internal. editfile.html template uses these internally
re_path(r'^getPeople/(?P<expeditionslug>.*)', get_people, name = "get_people"), re_path(r'^getPeople/(?P<expeditionslug>.*)', get_people, name = "get_people"),