diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2023-08-26 18:39:29 +0300 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2023-08-26 18:39:29 +0300 |
commit | d08a6aa204144e20e1e697fde3f6444edce814f1 (patch) | |
tree | 534c1376bc59e3f9ca31f14836f33ebe6bc8e4eb /core | |
parent | 93397a774fc5cd1aceec0b4329c8f96c708559a5 (diff) | |
download | troggle-d08a6aa204144e20e1e697fde3f6444edce814f1.tar.gz troggle-d08a6aa204144e20e1e697fde3f6444edce814f1.tar.bz2 troggle-d08a6aa204144e20e1e697fde3f6444edce814f1.zip |
Nicknames preserved, date checked
Diffstat (limited to 'core')
-rw-r--r-- | core/models/logbooks.py | 1 | ||||
-rw-r--r-- | core/views/logbooks.py | 9 | ||||
-rw-r--r-- | core/views/uploads.py | 56 |
3 files changed, 47 insertions, 19 deletions
diff --git a/core/models/logbooks.py b/core/models/logbooks.py index 34032fd..3498de1 100644 --- a/core/models/logbooks.py +++ b/core/models/logbooks.py @@ -106,6 +106,7 @@ class PersonLogEntry(TroggleModel): time_underground = models.FloatField(help_text="In decimal hours") logbook_entry = models.ForeignKey(LogbookEntry, on_delete=models.CASCADE) is_logbook_entry_author = models.BooleanField(default=False) + nickname_used = models.CharField(max_length=100,default="") # e.g. "Animal" or "Zonker", as it appears in the original logbook class Meta: ordering = ("-personexpedition",) diff --git a/core/views/logbooks.py b/core/views/logbooks.py index 2f89963..7934bb3 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -17,7 +17,9 @@ and for persons: their individual pages and their perseonexpedition pages. It uses the global object TROG to hold some cached pages. """ -todo = """Fix the get_person_chronology() display bug. +todo = """- Fix the get_person_chronology() display bug. + +- Fix id= value preservation on editing """ @@ -49,8 +51,9 @@ def expedition(request, expeditionname): """Returns a rendered page for one expedition, specified by the year e.g. '2019'. If page caching is enabled, it caches the dictionaries used to render the template page. - This is not as difficult to understand as it looks. Yes there are many levels of indirection, with multiple trees being traversed at the same time. And the Django special syntax - makes this hard for normal Python programmers. + This is not as difficult to understand as it looks. + Yes there are many levels of indirection, with multiple trees being traversed at the same time. + And the Django special syntax makes this hard for normal Python programmers. Remember that 'personexpedition__expedition' is interpreted by Django to mean the 'expedition' object which is connected by a foreign key to the 'personexpedition' diff --git a/core/views/uploads.py b/core/views/uploads.py index e7675b8..a4f5d9c 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -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}") |