2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00

validate author of trip on editing

This commit is contained in:
Philip Sargent 2023-09-05 15:49:12 +03:00
parent 0ea8fadaeb
commit 220e1327d7
3 changed files with 34 additions and 10 deletions

View File

@ -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()
@ -202,6 +207,15 @@ def logbookedit(request, year=None, slug=None):
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
slug = create_new_lbe_slug(date)
@ -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(

View File

@ -166,6 +166,7 @@ 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)
else:
res.append((personyear, nickname_used, logtime_underground))
except:
# This should not happen. We do not raise exceptions in that function
@ -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,

View File

@ -37,12 +37,14 @@
</span>
<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 %}