mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-18 04:07:10 +00:00
Nicknames preserved, date checked
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import subprocess
|
||||
import hashlib
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from django import forms
|
||||
@@ -20,6 +21,11 @@ and that core/forms.py contains Django class-based forms for caves and entrances
|
||||
"""
|
||||
|
||||
todo = """
|
||||
- munge the URL of images in the logbook entry so that they work from both the " /logbookedit/" page,
|
||||
the logbook /years/2023/ page and the logbook fragment page /logbookentry/<date>/
|
||||
Note that this munging has already been done when the entry is imported into the database, so
|
||||
when doing an online edit it has already been fixed.
|
||||
|
||||
- Ideally we should validate uploaded file as being a valid file type, not a dubious script or hack
|
||||
Validate image files using a magic recogniser in walletedit()
|
||||
https://pypi.org/project/reportlab/ or
|
||||
@@ -62,15 +68,11 @@ class LogbookEditForm(forms.Form): # not a model-form, just a form-form
|
||||
@login_required_if_public
|
||||
def logbookedit(request, year=None, slug=None):
|
||||
"""Edit a logbook entry
|
||||
This is daft: we have the parsed identity of the person and we render it to text as 'fullname', to be re-parsed on re-importing.
|
||||
And there is no guarantee that this will be the same thing, esp. as aliases are used in the initial data input.
|
||||
This is daft: we have the parsed identity of the person and we render it to text as 'nickname_used'
|
||||
(or, previously, 'fullname'), to be re-parsed on re-importing.
|
||||
And there is no guarantee that this will be the same thing.
|
||||
|
||||
So we are losing all the cute aliases that have been used over the years by this export/re-import process. Bother.
|
||||
But they have already been lost in the Great Format Conversion of 2022-23 when everything was chnaged to use the same HTML parser.
|
||||
Which is a shame.
|
||||
Fix is to add "alias_used" as a field in class PersonLogEntry, so that we can preserve
|
||||
all those cute names. But it's rather a large manual effort (with some scripting) to recover the aliases from the original logbook
|
||||
html files which are now only in the git history. Bother. Very sorry.
|
||||
Someone can put in a nickname which is invalid (e.g. 2 Sophies on expo). When is this checked?
|
||||
"""
|
||||
def clean_tu(tu):
|
||||
if tu =="":
|
||||
@@ -89,12 +91,19 @@ def logbookedit(request, year=None, slug=None):
|
||||
2 hex digits would seem adequate for each expo day, but we might get a collision.
|
||||
The hash is based on the content after substitution of <p> so should be stable. Which means these ids
|
||||
can be used elsewhere in the troggle system as permanent slugs.
|
||||
|
||||
When SAVING an edited entry (as opposed to a new one) we will have a different hash so we will have to
|
||||
delete the original database object
|
||||
"""
|
||||
sha.update(text.encode('utf-8'))
|
||||
return sha.hexdigest()[0:n]
|
||||
|
||||
if not year:
|
||||
year = 2023
|
||||
if not slug:
|
||||
year = 2023
|
||||
else:
|
||||
year = slug[0:4]
|
||||
print(year)
|
||||
|
||||
if request.method == "POST":
|
||||
form = LogbookEditForm(request.POST)
|
||||
@@ -116,13 +125,26 @@ def logbookedit(request, year=None, slug=None):
|
||||
entry = entry.replace('<br>','<br />') # clean up previous hack
|
||||
tu = request.POST["tu"].strip()
|
||||
tu = clean_tu(tu)
|
||||
uniq = unique_id(entry,2)
|
||||
print(uniq)
|
||||
|
||||
try:
|
||||
odate = datetime.strptime(date.replace(".", "-"), "%Y-%m-%d").date()
|
||||
dateflag = False
|
||||
except:
|
||||
odate = datetime.strptime(f"{year}-01-01", "%Y-%m-%d").date()
|
||||
print(f"! Invalid date string {date}, setting to {odate}")
|
||||
dateflag = True
|
||||
date = odate.isoformat()
|
||||
|
||||
newslug = f"{date}_{unique_id(entry,2)}"
|
||||
if slug:
|
||||
if slug != newslug:
|
||||
print(f"! Entry id changed! from {slug} to {newslug}")
|
||||
|
||||
# OK this could be done by rendering a template, but for such a small bit of HTML, it is easier to have
|
||||
# it all in one place: here
|
||||
output = f'''
|
||||
<hr />
|
||||
<div class="tripdate" id="{date}-{uniq}">{date}</div>
|
||||
<div class="tripdate" id="{newslug}">{date}</div>
|
||||
<div class="trippeople"><u>{author}</u>, {others}</div>
|
||||
<div class="triptitle">{place} - {title}</div>
|
||||
{entry}
|
||||
@@ -133,7 +155,7 @@ def logbookedit(request, year=None, slug=None):
|
||||
{
|
||||
"form": form,
|
||||
"year": year,
|
||||
"date": date,
|
||||
"date": date, "dateflag": dateflag,
|
||||
"author": author,
|
||||
"others": others,
|
||||
"place": place,
|
||||
@@ -158,11 +180,13 @@ def logbookedit(request, year=None, slug=None):
|
||||
tu = clean_tu(lbe.time_underground)
|
||||
|
||||
people = []
|
||||
for p in lbe.personlogentry_set.filter(logbook_entry=lbe):
|
||||
for p in lbe.personlogentry_set.filter(logbook_entry=lbe): # p is a PersonLogEntry object
|
||||
if p.is_logbook_entry_author:
|
||||
author = p.personexpedition.person.fullname
|
||||
# author = p.personexpedition.person.fullname
|
||||
author = p.nickname_used
|
||||
else:
|
||||
people.append(p.personexpedition.person.fullname)
|
||||
# people.append(p.personexpedition.person.fullname)
|
||||
people.append(p.nickname_used)
|
||||
others =', '.join(people)
|
||||
lenothers = min(70,max(20, len(others)))
|
||||
print(f"{lenothers}")
|
||||
|
||||
Reference in New Issue
Block a user