mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-16 10:47:12 +00:00
validate author of trip on editing
This commit is contained in:
@@ -101,11 +101,13 @@ def store_edited_entry_into_database(date, place, title, text, others, author, t
|
|||||||
if len(name) > 0:
|
if len(name) > 0:
|
||||||
if name[0] == "*": # a name prefix of "*" is special, just a string.
|
if name[0] == "*": # a name prefix of "*" is special, just a string.
|
||||||
odds.append(name)
|
odds.append(name)
|
||||||
|
print(f" - adding * special name '{name}'")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
personyear = GetPersonExpeditionNameLookup(expedition).get(name.lower())
|
personyear = GetPersonExpeditionNameLookup(expedition).get(name.lower())
|
||||||
if not personyear:
|
if not personyear:
|
||||||
odds.append(name)
|
odds.append(name)
|
||||||
|
print(f" - adding unrecognised expoer '{name}'")
|
||||||
if known_foreigner(name):
|
if known_foreigner(name):
|
||||||
message = f" ! - Known foreigner: '{name}' in entry {slug=}"
|
message = f" ! - Known foreigner: '{name}' in entry {slug=}"
|
||||||
print(message)
|
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)
|
PersonLogEntry.objects.bulk_create(pt_list)
|
||||||
|
|
||||||
lbo.other_people = ", ".join(odds)
|
lbo.other_people = ", ".join(odds)
|
||||||
|
print(f" - Saving other_people '{lbo.other_people}'")
|
||||||
lbo.save()
|
lbo.save()
|
||||||
|
|
||||||
class FilesForm(forms.Form): # not a model-form, just a form-form
|
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
|
@login_required_if_public
|
||||||
def logbookedit(request, year=None, slug=None):
|
def logbookedit(request, year=None, slug=None):
|
||||||
"""Edit a logbook entry
|
"""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.
|
This 'validates' the author as being on expo in the current year, but only indicates this by
|
||||||
And there is no guarantee that this will be the same thing. Oh well.
|
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):
|
def clean_tu(tu):
|
||||||
if tu =="":
|
if tu =="":
|
||||||
@@ -181,8 +186,8 @@ def logbookedit(request, year=None, slug=None):
|
|||||||
# otherwise it is an update
|
# otherwise it is an update
|
||||||
# validation all to be done yet..
|
# validation all to be done yet..
|
||||||
date = request.POST["date"].strip()
|
date = request.POST["date"].strip()
|
||||||
author = request.POST["author"].strip() # TODO check against personexpedition
|
author = request.POST["author"].strip() # TODO check against personexpedition on submit
|
||||||
others = request.POST["others"].strip() # TODO check each against personexpedition
|
others = request.POST["others"].strip() # TODO check each against personexpedition on submit
|
||||||
place = request.POST["place"].strip().replace(' - ',' = ') # no hyphens !
|
place = request.POST["place"].strip().replace(' - ',' = ') # no hyphens !
|
||||||
title = request.POST["title"].strip()
|
title = request.POST["title"].strip()
|
||||||
entry = request.POST["text"].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}")
|
print(f"! Invalid date string {date}, setting to {odate}")
|
||||||
dateflag = True
|
dateflag = True
|
||||||
date = odate.isoformat()
|
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:
|
if not slug:
|
||||||
# Creating a new logbook entry with all the gubbins
|
# Creating a new logbook entry with all the gubbins
|
||||||
@@ -238,7 +252,8 @@ def logbookedit(request, year=None, slug=None):
|
|||||||
# Successful POST
|
# Successful POST
|
||||||
# So save to database and then write out whole new logbook.html file
|
# 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
|
git = settings.GIT
|
||||||
dirpath = Path(settings.EXPOWEB) / "years" / str(year)
|
dirpath = Path(settings.EXPOWEB) / "years" / str(year)
|
||||||
lbe_add = subprocess.run(
|
lbe_add = subprocess.run(
|
||||||
@@ -301,7 +316,7 @@ def logbookedit(request, year=None, slug=None):
|
|||||||
"form": form,
|
"form": form,
|
||||||
"year": year,
|
"year": year,
|
||||||
"date": date, "dateflag": dateflag,
|
"date": date, "dateflag": dateflag,
|
||||||
"author": author,
|
"author": author, "authorflag": authorflag,
|
||||||
"others": others,
|
"others": others,
|
||||||
"place": place,
|
"place": place,
|
||||||
"title": title,
|
"title": title,
|
||||||
@@ -333,8 +348,12 @@ def logbookedit(request, year=None, slug=None):
|
|||||||
# people.append(p.personexpedition.person.fullname)
|
# people.append(p.personexpedition.person.fullname)
|
||||||
people.append(p.nickname_used)
|
people.append(p.nickname_used)
|
||||||
others =', '.join(people)
|
others =', '.join(people)
|
||||||
|
print(f"{others=}")
|
||||||
|
if lbe.other_people:
|
||||||
|
others = others + ", " + lbe.other_people
|
||||||
lenothers = min(70,max(20, len(others)))
|
lenothers = min(70,max(20, len(others)))
|
||||||
print(f"{lenothers}")
|
print(f"{others=}")
|
||||||
|
|
||||||
text = lbe.text
|
text = lbe.text
|
||||||
rows = max(5,len(text)/50)
|
rows = max(5,len(text)/50)
|
||||||
return render(
|
return render(
|
||||||
|
|||||||
@@ -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."
|
message = f" ! - {expedition.year} No name match for: '{nickname_used}' in entry {tid=} for this year."
|
||||||
print(message)
|
print(message)
|
||||||
DataIssue.objects.create(parser="logbooks", message=message)
|
DataIssue.objects.create(parser="logbooks", message=message)
|
||||||
res.append((personyear, nickname_used, logtime_underground))
|
else:
|
||||||
|
res.append((personyear, nickname_used, logtime_underground))
|
||||||
except:
|
except:
|
||||||
# This should not happen. We do not raise exceptions in that function
|
# 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."
|
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 ?
|
faster ?
|
||||||
"""
|
"""
|
||||||
other_people = ", ".join(guests) # join list members separated by comma
|
other_people = ", ".join(guests) # join list members separated by comma
|
||||||
|
if guests:
|
||||||
|
print(f" {date} - {guests}")
|
||||||
|
|
||||||
nonLookupAttribs = {
|
nonLookupAttribs = {
|
||||||
"place": place,
|
"place": place,
|
||||||
|
|||||||
@@ -36,13 +36,15 @@
|
|||||||
required />
|
required />
|
||||||
</span>
|
</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>
|
<label for="author">Your name (author) <a href="/aliases/{{year}}">[valid authors]</a></label>
|
||||||
<input {% if not user.username %} disabled{% endif %}
|
<input {% if not user.username %} disabled{% endif %}
|
||||||
label = "author" name = "author" size="20"
|
label = "author" name = "author" size="20"
|
||||||
title="The person writing the logbook entry"
|
title="The person writing the logbook entry"
|
||||||
{% if author %}value="{{author}}"{% else %}placeholder="Animal"{% endif %}
|
{% if author %}value="{{author}}"{% else %}placeholder="Animal"{% endif %}
|
||||||
required />
|
required />
|
||||||
|
</span>
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<label for="others">Other names (comma separated) <a href="/aliases/{{year}}">[valid aliases]</a></label>
|
<label for="others">Other names (comma separated) <a href="/aliases/{{year}}">[valid aliases]</a></label>
|
||||||
<input {% if not user.username %} disabled{% endif %}
|
<input {% if not user.username %} disabled{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user