forked from expo/troggle
fix bleed through of previous metadata onto another wallet
This commit is contained in:
parent
e98ffced98
commit
43b6b590e8
@ -56,7 +56,7 @@ todo = '''
|
|||||||
- Enable folder creation in dwguploads or as a separate form
|
- Enable folder creation in dwguploads or as a separate form
|
||||||
|
|
||||||
'''
|
'''
|
||||||
wallet_blank_json = {
|
WALLET_BLANK_JSON = {
|
||||||
"cave": "",
|
"cave": "",
|
||||||
"date": "",
|
"date": "",
|
||||||
"description url": "1623/XXX",
|
"description url": "1623/XXX",
|
||||||
@ -239,7 +239,7 @@ def scanupload(request, path=None):
|
|||||||
|
|
||||||
def save_json(jsondict):
|
def save_json(jsondict):
|
||||||
newfolder = contents_path.parent
|
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):
|
if not os.path.exists(contents_path.parent):
|
||||||
print(f'--- No wallet directory in :drawings: repo, so creating it')
|
print(f'--- No wallet directory in :drawings: repo, so creating it')
|
||||||
os.makedirs(contents_path.parent)
|
os.makedirs(contents_path.parent)
|
||||||
@ -253,12 +253,12 @@ def scanupload(request, path=None):
|
|||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
w, created = Wallet.objects.get_or_create(walletname=walletname)
|
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:
|
if created:
|
||||||
w.fpath = Path(settings.SCANS_ROOT, walletname[0:4], walletname)
|
w.fpath = Path(settings.SCANS_ROOT, walletname[0:4], walletname)
|
||||||
w.save()
|
w.save()
|
||||||
except:
|
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
|
raise
|
||||||
|
|
||||||
def commit_json(waldata):
|
def commit_json(waldata):
|
||||||
@ -296,7 +296,7 @@ def scanupload(request, path=None):
|
|||||||
if path:
|
if path:
|
||||||
wallet = urllib.parse.unquote(path)
|
wallet = urllib.parse.unquote(path)
|
||||||
else:
|
else:
|
||||||
wallet = "2022#01" # improve this later
|
wallet = "2022#00" # improve this later
|
||||||
|
|
||||||
year = wallet[:4]
|
year = wallet[:4]
|
||||||
try:
|
try:
|
||||||
@ -313,7 +313,7 @@ def scanupload(request, path=None):
|
|||||||
return(walletindex(request, path))
|
return(walletindex(request, path))
|
||||||
|
|
||||||
if not re.match('(19|20)\d\d[:#]\d\d', wallet):
|
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}')
|
# print(f'! - FORM scanupload - start {wallet}')
|
||||||
|
|
||||||
if path:
|
if path:
|
||||||
@ -342,7 +342,7 @@ def scanupload(request, path=None):
|
|||||||
form = FilesForm()
|
form = FilesForm()
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if "psg" in request.POST:
|
if "psg" in request.POST: # handle metadata form
|
||||||
formj = WalletForm(request.POST)
|
formj = WalletForm(request.POST)
|
||||||
# Beware. All fields returned as strings. Must re-type them as lists etc. before using or re-saving
|
# 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
|
# 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():
|
if formj.is_valid():
|
||||||
posted = request.POST.copy()
|
posted = request.POST.copy()
|
||||||
posted.pop("csrfmiddlewaretoken") # discard this
|
posted.pop("csrfmiddlewaretoken") # discard this
|
||||||
wd = wallet_blank_json
|
wd = WALLET_BLANK_JSON.copy()
|
||||||
for f in checkboxes:
|
for f in checkboxes:
|
||||||
wd[f] = False
|
wd[f] = False
|
||||||
#print(f'--- wd ${f}$ - {wd[f]}')
|
#print(f'--- wd ${f}$ - {wd[f]}')
|
||||||
@ -393,11 +393,11 @@ def scanupload(request, path=None):
|
|||||||
form = FilesForm(request.POST,request.FILES)
|
form = FilesForm(request.POST,request.FILES)
|
||||||
|
|
||||||
if form.is_valid():
|
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')
|
multiple = request.FILES.getlist('uploadfiles')
|
||||||
fs = FileSystemStorage(os.path.join(dirpath)) # creates wallet folder if necessary
|
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
|
waldata = {} # clean this out
|
||||||
actual_saved = []
|
actual_saved = []
|
||||||
if multiple:
|
if multiple:
|
||||||
@ -411,9 +411,12 @@ def scanupload(request, path=None):
|
|||||||
actual_saved.append(saved_filename)
|
actual_saved.append(saved_filename)
|
||||||
# print(f'! - FORM scanupload multiple {actual_saved}')
|
# print(f'! - FORM scanupload multiple {actual_saved}')
|
||||||
filesaved = True
|
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)
|
make_wallet(wallet)
|
||||||
commit_json(waldata)
|
commit_json(waldata)
|
||||||
|
|
||||||
|
# Not a POST, so a GET starts here. And also control gets here after a POST is processed.
|
||||||
files = []
|
files = []
|
||||||
dirs = []
|
dirs = []
|
||||||
# print(f'! - FORM scanupload - start {wallet} {dirpath}')
|
# print(f'! - FORM scanupload - start {wallet} {dirpath}')
|
||||||
@ -426,7 +429,7 @@ def scanupload(request, path=None):
|
|||||||
if f.is_file():
|
if f.is_file():
|
||||||
files.append(f.name)
|
files.append(f.name)
|
||||||
except FileNotFoundError:
|
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:
|
else:
|
||||||
create = True
|
create = True
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user