summaryrefslogtreecommitdiffstats
path: root/core/views/uploads.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2024-12-29 23:37:20 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2024-12-29 23:37:20 +0000
commitf73f1b50fe73631ce147ea59bd62d4eaac10cd69 (patch)
treeeebb7b02d10cf5a5e9ece139cd1a13f9785a6cd5 /core/views/uploads.py
parent1ddd4da27bf1aa1594cdfc0477e016932c735026 (diff)
downloadtroggle-f73f1b50fe73631ce147ea59bd62d4eaac10cd69.tar.gz
troggle-f73f1b50fe73631ce147ea59bd62d4eaac10cd69.tar.bz2
troggle-f73f1b50fe73631ce147ea59bd62d4eaac10cd69.zip
Bug fixes
Diffstat (limited to 'core/views/uploads.py')
-rw-r--r--core/views/uploads.py66
1 files changed, 9 insertions, 57 deletions
diff --git a/core/views/uploads.py b/core/views/uploads.py
index 869c466..c81f4de 100644
--- a/core/views/uploads.py
+++ b/core/views/uploads.py
@@ -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