diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2023-09-05 15:49:12 +0300 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2023-09-05 15:49:12 +0300 |
commit | 220e1327d743b3b3c65b2d37aebdc063ca3c18a3 (patch) | |
tree | 285725262a7660fc1e080a59ad8e33e5a8c56285 /core/views/uploads.py | |
parent | 0ea8fadaebb93b4f7299d621e86419088fed4acb (diff) | |
download | troggle-220e1327d743b3b3c65b2d37aebdc063ca3c18a3.tar.gz troggle-220e1327d743b3b3c65b2d37aebdc063ca3c18a3.tar.bz2 troggle-220e1327d743b3b3c65b2d37aebdc063ca3c18a3.zip |
validate author of trip on editing
Diffstat (limited to 'core/views/uploads.py')
-rw-r--r-- | core/views/uploads.py | 35 |
1 files changed, 27 insertions, 8 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( |