2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

fix bleed through of previous metadata onto another wallet

This commit is contained in:
Philip Sargent 2022-08-24 16:22:15 +03:00
parent e98ffced98
commit 43b6b590e8

View File

@ -56,7 +56,7 @@ todo = '''
- Enable folder creation in dwguploads or as a separate form
'''
wallet_blank_json = {
WALLET_BLANK_JSON = {
"cave": "",
"date": "",
"description url": "1623/XXX",
@ -239,7 +239,7 @@ def scanupload(request, path=None):
def save_json(jsondict):
newfolder = contents_path.parent
print(f'--- wallet directory in :drawings: repo {newfolder=}')
print(f'--- Wallet directory in :drawings: repo {newfolder=} {jsondict}')
if not os.path.exists(contents_path.parent):
print(f'--- No wallet directory in :drawings: repo, so creating it')
os.makedirs(contents_path.parent)
@ -253,12 +253,12 @@ def scanupload(request, path=None):
'''
try:
w, created = Wallet.objects.get_or_create(walletname=walletname)
print(f'wallet string {walletname}, wallet object {w} created new?: {created}')
print(f'--- Wallet string {walletname}, wallet object {w} created new?: {created}')
if created:
w.fpath = Path(settings.SCANS_ROOT, walletname[0:4], walletname)
w.save()
except:
print(f'wallet string {walletname}, FAIL TO GET or create WALLET OBJECT')
print(f'!-- Wallet string {walletname}, FAIL TO GET or create WALLET OBJECT')
raise
def commit_json(waldata):
@ -296,7 +296,7 @@ def scanupload(request, path=None):
if path:
wallet = urllib.parse.unquote(path)
else:
wallet = "2022#01" # improve this later
wallet = "2022#00" # improve this later
year = wallet[:4]
try:
@ -313,7 +313,7 @@ def scanupload(request, path=None):
return(walletindex(request, path))
if not re.match('(19|20)\d\d[:#]\d\d', wallet):
wallet = "2022:01" # improve this later
wallet = "2022:00" # improve this later
# print(f'! - FORM scanupload - start {wallet}')
if path:
@ -342,7 +342,7 @@ def scanupload(request, path=None):
form = FilesForm()
if request.method == 'POST':
if "psg" in request.POST:
if "psg" in request.POST: # handle metadata form
formj = WalletForm(request.POST)
# Beware. All fields returned as strings. Must re-type them as lists etc. before using or re-saving
# Also lots of hassle with lists of strings interpreted as a single string
@ -350,7 +350,7 @@ def scanupload(request, path=None):
if formj.is_valid():
posted = request.POST.copy()
posted.pop("csrfmiddlewaretoken") # discard this
wd = wallet_blank_json
wd = WALLET_BLANK_JSON.copy()
for f in checkboxes:
wd[f] = False
#print(f'--- wd ${f}$ - {wd[f]}')
@ -393,11 +393,11 @@ def scanupload(request, path=None):
form = FilesForm(request.POST,request.FILES)
if form.is_valid():
#f = request.FILES["uploadfiles"]
print(f'--- FORM scanupload multiple BUT EMPTY METADATA supposedly {WALLET_BLANK_JSON["date"]=}')
multiple = request.FILES.getlist('uploadfiles')
fs = FileSystemStorage(os.path.join(dirpath)) # creates wallet folder if necessary
wd = wallet_blank_json # clean this out
wd = WALLET_BLANK_JSON.copy() # clean this out
waldata = {} # clean this out
actual_saved = []
if multiple:
@ -411,9 +411,12 @@ def scanupload(request, path=None):
actual_saved.append(saved_filename)
# print(f'! - FORM scanupload multiple {actual_saved}')
filesaved = True
save_json(wallet_blank_json)
print(f'--- FORM scanupload multiple BUT EMPTY METADATA supposedly {WALLET_BLANK_JSON["date"]=}')
save_json(WALLET_BLANK_JSON.copy())
make_wallet(wallet)
commit_json(waldata)
# Not a POST, so a GET starts here. And also control gets here after a POST is processed.
files = []
dirs = []
# print(f'! - FORM scanupload - start {wallet} {dirpath}')
@ -426,7 +429,7 @@ def scanupload(request, path=None):
if f.is_file():
files.append(f.name)
except FileNotFoundError:
files.append('(no wallet yet. It would be created if you upload a scan and then save the form with a date.)')
files.append('(No wallet yet. It would be created if you upload a scan and then save the form with a date.)')
else:
create = True