forked from expo/troggle
bugfix which was deleting metadata
This commit is contained in:
parent
43b6b590e8
commit
8ca50d8fd4
@ -59,7 +59,7 @@ todo = '''
|
|||||||
WALLET_BLANK_JSON = {
|
WALLET_BLANK_JSON = {
|
||||||
"cave": "",
|
"cave": "",
|
||||||
"date": "",
|
"date": "",
|
||||||
"description url": "1623/XXX",
|
"description url": "1623/NNN",
|
||||||
"description written": False,
|
"description written": False,
|
||||||
"electronic survey": False,
|
"electronic survey": False,
|
||||||
"elev drawn": False,
|
"elev drawn": False,
|
||||||
@ -237,16 +237,32 @@ def scanupload(request, path=None):
|
|||||||
filesaved = False
|
filesaved = False
|
||||||
actual_saved = []
|
actual_saved = []
|
||||||
|
|
||||||
|
def read_json():
|
||||||
|
if contents_path.is_file():
|
||||||
|
create = False # yes wallet exists becaue JSON exists, even if no files in the surveyscans folder, or even if that folder does not exist
|
||||||
|
with open(contents_path) as json_file:
|
||||||
|
try:
|
||||||
|
waldata = json.load(json_file)
|
||||||
|
except:
|
||||||
|
message = f"! {wallet} Failed to load {contents_path} JSON file"
|
||||||
|
print(message)
|
||||||
|
DataIssue.objects.create(parser='scans', message=message, url=wurl) # set URL to this wallet folder
|
||||||
|
raise
|
||||||
|
else: # no JSON file exists
|
||||||
|
print(f'--- No JSON exists, so creating blank copy')
|
||||||
|
waldata = WALLET_BLANK_JSON.copy()
|
||||||
|
return waldata
|
||||||
|
|
||||||
def save_json(jsondict):
|
def save_json(jsondict):
|
||||||
newfolder = contents_path.parent
|
newfolder = contents_path.parent
|
||||||
print(f'--- Wallet directory in :drawings: repo {newfolder=} {jsondict}')
|
#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)
|
||||||
|
|
||||||
with open(contents_path, "w") as jfile:
|
with open(contents_path, "w") as jfile:
|
||||||
json.dump(jsondict, jfile, indent = 1)
|
json.dump(jsondict, jfile, indent = 1)
|
||||||
print(f'--- FINISHED saving to JSON at {contents_path}')
|
# print(f'--- FINISHED saving to JSON at {contents_path}')
|
||||||
|
|
||||||
def make_wallet(walletname):
|
def make_wallet(walletname):
|
||||||
'''We need a wallet Object so that the django template stuff can find the files
|
'''We need a wallet Object so that the django template stuff can find the files
|
||||||
@ -382,23 +398,22 @@ def scanupload(request, path=None):
|
|||||||
print(formj.errors)
|
print(formj.errors)
|
||||||
return render(request,'errors/generic.html', {'message': formj.errors})
|
return render(request,'errors/generic.html', {'message': formj.errors})
|
||||||
|
|
||||||
elif "walletgoto" in request.POST: # not editing wallet data, uploading a file.. going direct to a named wallet
|
elif "walletgoto" in request.POST: # not editing wallet data or uploading a file.. going direct to a named wallet
|
||||||
formg = WalletGotoForm(request.POST,request.FILES)
|
formg = WalletGotoForm(request.POST,request.FILES)
|
||||||
if formg.is_valid():
|
if formg.is_valid():
|
||||||
walletgoto = request.POST["walletgoto"]
|
walletgoto = request.POST["walletgoto"]
|
||||||
|
|
||||||
return HttpResponseRedirect(f'/scanupload/{walletgoto.replace("#",":")}')
|
return HttpResponseRedirect(f'/scanupload/{walletgoto.replace("#",":")}')
|
||||||
|
|
||||||
else: # not editing wallet data, uploading a file..
|
else: # not editing wallet data, uploading a file. But should not overwrite metadata at all.
|
||||||
form = FilesForm(request.POST,request.FILES)
|
form = FilesForm(request.POST,request.FILES)
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
print(f'--- FORM scanupload multiple BUT EMPTY METADATA supposedly {WALLET_BLANK_JSON["date"]=}')
|
#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.copy() # clean this out
|
waldata = read_json()
|
||||||
waldata = {} # clean this out
|
|
||||||
actual_saved = []
|
actual_saved = []
|
||||||
if multiple:
|
if multiple:
|
||||||
for f in multiple:
|
for f in multiple:
|
||||||
@ -411,8 +426,8 @@ 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
|
||||||
print(f'--- FORM scanupload multiple BUT EMPTY METADATA supposedly {WALLET_BLANK_JSON["date"]=}')
|
#print(f'--- FORM scanupload multiple BUT EMPTY METADATA supposedly {WALLET_BLANK_JSON["date"]=}')
|
||||||
save_json(WALLET_BLANK_JSON.copy())
|
save_json(waldata)
|
||||||
make_wallet(wallet)
|
make_wallet(wallet)
|
||||||
commit_json(waldata)
|
commit_json(waldata)
|
||||||
|
|
||||||
@ -439,17 +454,8 @@ def scanupload(request, path=None):
|
|||||||
if dirs:
|
if dirs:
|
||||||
dirs = sorted(dirs)
|
dirs = sorted(dirs)
|
||||||
|
|
||||||
waldata = {}
|
waldata = read_json()
|
||||||
if contents_path.is_file():
|
|
||||||
create = False # yes wallet exists becaue JSON exists, even if no files in the surveyscans folder, or even if that folder does not exist
|
|
||||||
with open(contents_path) as json_file:
|
|
||||||
try:
|
|
||||||
waldata = json.load(json_file)
|
|
||||||
except:
|
|
||||||
message = f"! {wallet} Failed to load {contents_path} JSON file"
|
|
||||||
print(message)
|
|
||||||
DataIssue.objects.create(parser='scans', message=message, url=wurl) # set URL to this wallet folder
|
|
||||||
raise
|
|
||||||
cave =""
|
cave =""
|
||||||
psg = ""
|
psg = ""
|
||||||
chkplannr = ""
|
chkplannr = ""
|
||||||
@ -459,7 +465,7 @@ def scanupload(request, path=None):
|
|||||||
context = {}
|
context = {}
|
||||||
if waldata:
|
if waldata:
|
||||||
if not waldata["people"]:
|
if not waldata["people"]:
|
||||||
waldata["people"]=["NOBODY"]
|
waldata["people"]=["NOBODY", "someone"]
|
||||||
if not type(waldata["people"])==list:
|
if not type(waldata["people"])==list:
|
||||||
if waldata["people"][0] == '"':
|
if waldata["people"][0] == '"':
|
||||||
waldata["people"] = waldata["people"][1:-1]
|
waldata["people"] = waldata["people"][1:-1]
|
||||||
|
Loading…
Reference in New Issue
Block a user