2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-18 04:27:16 +00:00

Bug fixes

This commit is contained in:
2024-12-29 23:37:20 +00:00
parent 1ddd4da27b
commit f73f1b50fe
3 changed files with 17 additions and 60 deletions

View File

@@ -17,6 +17,7 @@ from troggle.core.utils import (
current_expo,
get_cookie,
git_add,
git_commit,
git_string,
sanitize_name,
unique_slug,
@@ -758,33 +759,6 @@ def dwgupload(request, folder=None, gitdisable="no"):
if gitdisable != "yes":
commands = git_add(filepath, dirpath)
# dr_add = subprocess.run(
# [git, "add", saved_filename], cwd=dirpath, capture_output=True, text=True
# )
# msgdata = (
# dr_add.stderr
# + "\n"
# + dr_add.stdout
# + "\nreturn code: "
# + str(dr_add.returncode)
# )
# # message = f'! - FORM dwgupload - Success: git ADD on server for this file {saved_filename}.' + msgdata
# # print(message)
# if dr_add.returncode != 0:
# msgdata = (
# "Ask a nerd to fix this.\n\n"
# + dr_add.stderr
# + "\n\n"
# + dr_add.stdout
# + "\n\nreturn code: "
# + str(dr_add.returncode)
# )
# message = (
# f"! - FORM dwgupload - CANNOT git ADD on server for this file {saved_filename}. Edits saved but not added to git.\n"
# + msgdata
# )
# print(message)
# return render(request, "errors/generic.html", {"message": message})
dwgfile, created = DrawingFile.objects.get_or_create(
dwgpath=saved_filename, dwgname=Path(f.name).stem, filesize=f.size
@@ -810,41 +784,17 @@ def dwgupload(request, folder=None, gitdisable="no"):
if actual_saved:
filesaved = True
if len(actual_saved) > 1:
dots = "..."
dots = f"{len(actual_saved)} files"
else:
dots = ""
dots = f"{actual_saved[0]}"
commit_msg = f"Drawings upload - {dots}"
if gitdisable != "yes":
dr_commit = subprocess.run(
[git, "commit", "-m", f"Drawings upload - {actual_saved[0]}{dots}"],
cwd=dirpath,
capture_output=True,
text=True,
)
# message = f'! - FORM dwgupload - For uploading {actual_saved[0]}{dots}. Edits saved, added to git, and COMMITTED.\n' + msgdata
# print(message)
# 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"
+ dr_commit.stdout
+ "\nreturn code: "
+ str(dr_commit.returncode)
)
message = (
f"! - FORM dwgupload -Error code with git on server for this {actual_saved[0]}{dots}. Edits saved, added to git, but NOT committed.\n"
+ msgdata
)
print(message)
return render(request, "errors/generic.html", {"message": message})
else:
print(f' git disabled "{git=}"')
git_commit(dirpath, commit_msg, editor, commands)
else: # maybe all were refused by the suffix test in dwgvalid()
message = f"! - FORM dwgupload - Nothing actually saved. All were refused. {actual_saved=}"
print(message)
# GET request starts here
# GET request starts here, also drops through from POST
files = []
dirs = []
# print(f'! - FORM dwgupload - start {folder=} \n"{dirpath=}" \n"{dirpath.parent=}" \n"{dirpath.exists()=}"')
@@ -866,7 +816,7 @@ def dwgupload(request, folder=None, gitdisable="no"):
if dirs:
dirs = sorted(dirs)
return render(
response = render(
request,
"dwguploadform.html",
{
@@ -883,3 +833,5 @@ def dwgupload(request, folder=None, gitdisable="no"):
"who_are_you": editor,
},
)
response.set_cookie('editor_id', editor, max_age=COOKIE_MAX_AGE) # cookie expires after COOKIE_MAX_AGE seconds
return response