summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/views/uploads.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/core/views/uploads.py b/core/views/uploads.py
index 6ebdecf..369e297 100644
--- a/core/views/uploads.py
+++ b/core/views/uploads.py
@@ -198,7 +198,7 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl):
# @login_required_if_public
def scanupload(request, path=None):
'''Upload scanned image files into a wallet on /expofiles
- Also display and edit the contents.json data in the wallet.
+ Also display AND EDIT the contents.json data in the wallet.
This does NOT use a Django model linked to a Django form. Just a simple Django form.
You will find the Django documentation on forms very confusing, This is simpler.
@@ -208,6 +208,7 @@ def scanupload(request, path=None):
REWRITE bits using the ticklist, dateify, caveify, populate etc utility functions in core.view.scans.py
'''
+ git = settings.GIT
filesaved = False
actual_saved = []
@@ -257,7 +258,6 @@ def scanupload(request, path=None):
wurl = f"/scanupload/{wallet}".replace('#', ':')
wallet = wallet.replace(':','#')
dirpath = Path(settings.SCANS_ROOT, year, wallet)
- #contents_path = dirpath / contentsjson
contents_path = Path(settings.DRAWINGS_DATA, "walletjson") / year / wallet / contentsjson
form = FilesForm()
@@ -299,7 +299,7 @@ def scanupload(request, path=None):
json.dump(wd, jfile, indent = 1)
# print(f'--- FINISHED saving to JSON\n')
- # This copies the new data to the drawings repo and commit it
+ # This copies the new data to the drawings repo and commits it
# needs the troggle object wallet, not a string
try:
@@ -308,17 +308,32 @@ def scanupload(request, path=None):
if created:
w.fpath = Path(settings.SCANS_ROOT, wallet[0:4], wallet)
w.save()
- CopyWalletData(w)
except:
- print(f'wallet string {wallet}, FAIL TO GET WALLET OBJECT, maybe we need to create it ?')
+ print(f'wallet string {wallet}, FAIL TO GET or create WALLET OBJECT')
raise
-
+
+ destfolder = contents_path.parent
+ dr_add = subprocess.run([git, "add", contentsjson], cwd=destfolder, capture_output=True, text=True)
+ if dr_add.returncode != 0:
+ msgdata = 'Ask a nerd to fix this.\n--' + dr_add.stderr + '\n--' + dr_add.stdout + '\n--return code: ' + str(dr_add.returncode)
+ message = f'CANNOT git on server for this file {contentsjson}. Edits saved but not added to git.\n\n' + msgdata
+ print(message)
+ return render(request,'errors/generic.html', {'message': message})
+ else:
+ dr_commit = subprocess.run([git, "commit", "-m", f'Update of {contentsjson} in wallet'], cwd=destfolder, capture_output=True, text=True)
+ # This produces return code = 1 if it commits OK
+ if dr_commit.returncode != 0:
+ msgdata = 'Ask a nerd to fix this.\n\n' + dr_commit.stderr + '\n\n' + dr_commit.stdout + '\n\nreturn code: ' + str(dr_commit.returncode)
+ message = f'Error code with git on server for this {contentsjson}. File is added to git, but NOT committed.\n' + msgdata
+ print(message)
+ return render(request,'errors/generic.html', {'message': message})
+
else:
print(f'--- INVALID JSON Update form submitted')
print(formj.errors)
return render(request,'errors/generic.html', {'message': formj.errors})
- else:
+ else: # not editing wallet data, uploading a file..
form = FilesForm(request.POST,request.FILES)
if form.is_valid():