diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2023-09-01 20:31:19 +0300 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2023-09-01 20:31:19 +0300 |
commit | 98412c140d9cadc3009febe8f903f79b4ad8769b (patch) | |
tree | 2763c4392f3dd0211722bfe57e409dd5715ece88 /core/views/uploads.py | |
parent | 1cf02afec9ef1f6af74849cf2879d0e37215b8df (diff) | |
download | troggle-98412c140d9cadc3009febe8f903f79b4ad8769b.tar.gz troggle-98412c140d9cadc3009febe8f903f79b4ad8769b.tar.bz2 troggle-98412c140d9cadc3009febe8f903f79b4ad8769b.zip |
more robust tripid labelling
Diffstat (limited to 'core/views/uploads.py')
-rw-r--r-- | core/views/uploads.py | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/core/views/uploads.py b/core/views/uploads.py index f0dedfa..5c2f4f4 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -1,5 +1,4 @@ import subprocess -import hashlib import string from datetime import datetime from pathlib import Path @@ -9,10 +8,11 @@ from django.core.files.storage import FileSystemStorage from django.shortcuts import render, redirect import settings -from troggle.core.models.caves import GetCaveLookup + from troggle.core.models.logbooks import LogbookEntry, writelogbook, PersonLogEntry from troggle.core.models.survex import DrawingFile from troggle.core.models.troggle import DataIssue, Expedition, PersonExpedition +from troggle.core.utils import alphabet_suffix from troggle.parsers.people import GetPersonExpeditionNameLookup, known_foreigner # from databaseReset import reinit_db # don't do this. databaseRest runs code *at import time* @@ -45,29 +45,15 @@ todo = """ - Make file rename utility less ugly. """ -sha = hashlib.new('sha256') - -def unique_slug(text, n): - """This gives each logbook entry a unique id based on the date+content, so the order of entries on a particular day - does not matter. This is a change (August 2023) from previous process. - - 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] def create_new_lbe_slug(date): onthisdate = LogbookEntry.objects.filter(date=date) n = len(onthisdate) # print(f" Already entries on this date: {n}\n {onthisdate}") - alphabet = list(string.ascii_lowercase) - tid = f"{date}{alphabet[n]}" + suffix = alphabet_suffix(n) + + tid = f"{date}{suffix}" print(tid) return tid |