mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-25 08:41:51 +00:00
bugfix which was deleting metadata
This commit is contained in:
parent
43b6b590e8
commit
8ca50d8fd4
@ -59,7 +59,7 @@ todo = '''
|
||||
WALLET_BLANK_JSON = {
|
||||
"cave": "",
|
||||
"date": "",
|
||||
"description url": "1623/XXX",
|
||||
"description url": "1623/NNN",
|
||||
"description written": False,
|
||||
"electronic survey": False,
|
||||
"elev drawn": False,
|
||||
@ -237,16 +237,32 @@ def scanupload(request, path=None):
|
||||
filesaved = False
|
||||
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):
|
||||
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):
|
||||
print(f'--- No wallet directory in :drawings: repo, so creating it')
|
||||
os.makedirs(contents_path.parent)
|
||||
|
||||
with open(contents_path, "w") as jfile:
|
||||
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):
|
||||
'''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)
|
||||
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)
|
||||
if formg.is_valid():
|
||||
walletgoto = request.POST["walletgoto"]
|
||||
|
||||
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)
|
||||
|
||||
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')
|
||||
fs = FileSystemStorage(os.path.join(dirpath)) # creates wallet folder if necessary
|
||||
|
||||
wd = WALLET_BLANK_JSON.copy() # clean this out
|
||||
waldata = {} # clean this out
|
||||
|
||||
waldata = read_json()
|
||||
actual_saved = []
|
||||
if multiple:
|
||||
for f in multiple:
|
||||
@ -411,8 +426,8 @@ def scanupload(request, path=None):
|
||||
actual_saved.append(saved_filename)
|
||||
# print(f'! - FORM scanupload multiple {actual_saved}')
|
||||
filesaved = True
|
||||
print(f'--- FORM scanupload multiple BUT EMPTY METADATA supposedly {WALLET_BLANK_JSON["date"]=}')
|
||||
save_json(WALLET_BLANK_JSON.copy())
|
||||
#print(f'--- FORM scanupload multiple BUT EMPTY METADATA supposedly {WALLET_BLANK_JSON["date"]=}')
|
||||
save_json(waldata)
|
||||
make_wallet(wallet)
|
||||
commit_json(waldata)
|
||||
|
||||
@ -439,17 +454,8 @@ def scanupload(request, path=None):
|
||||
if dirs:
|
||||
dirs = sorted(dirs)
|
||||
|
||||
waldata = {}
|
||||
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
|
||||
waldata = read_json()
|
||||
|
||||
cave =""
|
||||
psg = ""
|
||||
chkplannr = ""
|
||||
@ -459,7 +465,7 @@ def scanupload(request, path=None):
|
||||
context = {}
|
||||
if waldata:
|
||||
if not waldata["people"]:
|
||||
waldata["people"]=["NOBODY"]
|
||||
waldata["people"]=["NOBODY", "someone"]
|
||||
if not type(waldata["people"])==list:
|
||||
if waldata["people"][0] == '"':
|
||||
waldata["people"] = waldata["people"][1:-1]
|
||||
|
Loading…
Reference in New Issue
Block a user