summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2023-09-05 15:49:12 +0300
committerPhilip Sargent <philip.sargent@gmail.com>2023-09-05 15:49:12 +0300
commit220e1327d743b3b3c65b2d37aebdc063ca3c18a3 (patch)
tree285725262a7660fc1e080a59ad8e33e5a8c56285
parent0ea8fadaebb93b4f7299d621e86419088fed4acb (diff)
downloadtroggle-220e1327d743b3b3c65b2d37aebdc063ca3c18a3.tar.gz
troggle-220e1327d743b3b3c65b2d37aebdc063ca3c18a3.tar.bz2
troggle-220e1327d743b3b3c65b2d37aebdc063ca3c18a3.zip
validate author of trip on editing
-rw-r--r--core/views/uploads.py35
-rw-r--r--parsers/logbooks.py5
-rw-r--r--templates/logbookform.html4
3 files changed, 34 insertions, 10 deletions
diff --git a/core/views/uploads.py b/core/views/uploads.py
index 0041769..67ffb48 100644
--- a/core/views/uploads.py
+++ b/core/views/uploads.py
@@ -101,11 +101,13 @@ def store_edited_entry_into_database(date, place, title, text, others, author, t
if len(name) > 0:
if name[0] == "*": # a name prefix of "*" is special, just a string.
odds.append(name)
+ print(f" - adding * special name '{name}'")
else:
try:
personyear = GetPersonExpeditionNameLookup(expedition).get(name.lower())
if not personyear:
odds.append(name)
+ print(f" - adding unrecognised expoer '{name}'")
if known_foreigner(name):
message = f" ! - Known foreigner: '{name}' in entry {slug=}"
print(message)
@@ -128,6 +130,7 @@ def store_edited_entry_into_database(date, place, title, text, others, author, t
PersonLogEntry.objects.bulk_create(pt_list)
lbo.other_people = ", ".join(odds)
+ print(f" - Saving other_people '{lbo.other_people}'")
lbo.save()
class FilesForm(forms.Form): # not a model-form, just a form-form
@@ -149,9 +152,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 'nickname_used'
- (or, previously, 'fullname'), to be re-parsed on re-importing.
- And there is no guarantee that this will be the same thing. Oh well.
+
+ This 'validates' the author as being on expo in the current year, but only indicates this by
+ putting the text of the form prompt in red (same as for an invalid date, which is arguably more important).
+ No check is done on the other people on the trip as this is picked up anyway by parsing on import
+ and we don't really care at this point.
"""
def clean_tu(tu):
if tu =="":
@@ -181,8 +186,8 @@ def logbookedit(request, year=None, slug=None):
# otherwise it is an update
# validation all to be done yet..
date = request.POST["date"].strip()
- author = request.POST["author"].strip() # TODO check against personexpedition
- others = request.POST["others"].strip() # TODO check each against personexpedition
+ author = request.POST["author"].strip() # TODO check against personexpedition on submit
+ others = request.POST["others"].strip() # TODO check each against personexpedition on submit
place = request.POST["place"].strip().replace(' - ',' = ') # no hyphens !
title = request.POST["title"].strip()
entry = request.POST["text"].strip()
@@ -201,6 +206,15 @@ def logbookedit(request, year=None, slug=None):
print(f"! Invalid date string {date}, setting to {odate}")
dateflag = True
date = odate.isoformat()
+
+ expo = Expedition.objects.get(year=year)
+ personyear = GetPersonExpeditionNameLookup(expo).get(author.lower())
+ if personyear:
+ authorflag = False
+ else:
+ authorflag = True
+ print(f"! Unrecognised author: {author}")
+
if not slug:
# Creating a new logbook entry with all the gubbins
@@ -238,7 +252,8 @@ def logbookedit(request, year=None, slug=None):
# Successful POST
# So save to database and then write out whole new logbook.html file
- #TO DO author and team validation, and check that 'place' is not deleted and that *bloke not forgotten
+ # We do author validation on the form as displayed by GET, not at the moment of POST.
+ # If we had JS validation then we could be more timely.
git = settings.GIT
dirpath = Path(settings.EXPOWEB) / "years" / str(year)
lbe_add = subprocess.run(
@@ -301,7 +316,7 @@ def logbookedit(request, year=None, slug=None):
"form": form,
"year": year,
"date": date, "dateflag": dateflag,
- "author": author,
+ "author": author, "authorflag": authorflag,
"others": others,
"place": place,
"title": title,
@@ -333,8 +348,12 @@ def logbookedit(request, year=None, slug=None):
# people.append(p.personexpedition.person.fullname)
people.append(p.nickname_used)
others =', '.join(people)
+ print(f"{others=}")
+ if lbe.other_people:
+ others = others + ", " + lbe.other_people
lenothers = min(70,max(20, len(others)))
- print(f"{lenothers}")
+ print(f"{others=}")
+
text = lbe.text
rows = max(5,len(text)/50)
return render(
diff --git a/parsers/logbooks.py b/parsers/logbooks.py
index ddc65f7..8737508 100644
--- a/parsers/logbooks.py
+++ b/parsers/logbooks.py
@@ -166,7 +166,8 @@ def GetTripPersons(trippeople, expedition, logtime_underground, tid=None):
message = f" ! - {expedition.year} No name match for: '{nickname_used}' in entry {tid=} for this year."
print(message)
DataIssue.objects.create(parser="logbooks", message=message)
- res.append((personyear, nickname_used, logtime_underground))
+ else:
+ res.append((personyear, nickname_used, logtime_underground))
except:
# This should not happen. We do not raise exceptions in that function
message = f" ! - {expedition.year} EXCEPTION: '{tripperson}' ({nickname_used}) in entry {tid=} for this year."
@@ -259,6 +260,8 @@ def store_entry_into_database(date, place, tripcave, title, text, trippersons, a
faster ?
"""
other_people = ", ".join(guests) # join list members separated by comma
+ if guests:
+ print(f" {date} - {guests}")
nonLookupAttribs = {
"place": place,
diff --git a/templates/logbookform.html b/templates/logbookform.html
index 4023318..1f7602b 100644
--- a/templates/logbookform.html
+++ b/templates/logbookform.html
@@ -36,13 +36,15 @@
required />
</span>
- <br /><br />
+ <br /><br />
+ <span {% if authorflag %}style="color:red"{% endif %}>
<label for="author">Your name (author) <a href="/aliases/{{year}}">[valid authors]</a></label>
<input {% if not user.username %} disabled{% endif %}
label = "author" name = "author" size="20"
title="The person writing the logbook entry"
{% if author %}value="{{author}}"{% else %}placeholder="Animal"{% endif %}
required />
+ </span>
<br /><br />
<label for="others">Other names (comma separated) <a href="/aliases/{{year}}">[valid aliases]</a></label>
<input {% if not user.username %} disabled{% endif %}