summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/utils.py6
-rw-r--r--core/views/other.py5
-rw-r--r--core/views/uploads.py66
3 files changed, 17 insertions, 60 deletions
diff --git a/core/utils.py b/core/utils.py
index 154c468..3dbbd9f 100644
--- a/core/utils.py
+++ b/core/utils.py
@@ -221,7 +221,7 @@ def git_string(author_string):
return author_string
else:
editor = author_string.replace("@","_at_")
- editor = re.sub('[^0-9a-zA-Z_\.]+', '_', editor)
+ editor = re.sub('[^0-9a-zA-Z_]+', '_', editor)
if editor.startswith("_"):
editor = "X" + editor
editor += f" <{editor}@potatohut.expo>"
@@ -265,9 +265,9 @@ def git_commit(cwd, message, editor, commands=[]):
print(f"git commit in {cwd}")
if socket.gethostname() != EXPOSERVER:
- message += f" on dev machine '{socket.gethostname()}'"
+ message += f" - on dev machine '{socket.gethostname()}'"
elif settings.DEVSERVER:
- message += " on a dev machine using 'runserver'"
+ message += " - on a dev machine using 'runserver'"
print(f"..{message=}\n..{editor=}")
cmd_commit = [git, "commit", "-m", message, "--author", f"{editor}"]
commands.append(cmd_commit)
diff --git a/core/views/other.py b/core/views/other.py
index 7c4c232..ce6c182 100644
--- a/core/views/other.py
+++ b/core/views/other.py
@@ -31,6 +31,9 @@ progress and task list (deprecated as we do not have individual user login).
todo = """
- [Low priority] Fix Login page so that it produces the frontpage or
redirects to the page which produced the login prompt requirement.
+
+- Statement on login page that "essential cookies" are used when you login
+ to the website.
"""
@@ -51,6 +54,7 @@ def todos(request, module):
from troggle.core.views.survex import todo as viewsurvex
from troggle.core.views.uploads import todo as viewuploads
from troggle.core.views.wallets_edit import todo as viewwallets_edit
+ from troggle.core.views.logbook_edit import todo as viewlogbook_edit
from troggle.parsers.caves import todo as parserscaves
from troggle.parsers.drawings import todo as parsersdrawings
from troggle.parsers.locations import todo as parserslocations
@@ -72,6 +76,7 @@ def todos(request, module):
"views/survex": viewsurvex,
"views/uploads": viewuploads,
"views/wallets_edit": viewwallets_edit,
+ "views/logbook_edit": viewlogbook_edit,
"parsers/caves": parserscaves,
"parsers/drawings": parsersdrawings,
"parsers/locations": parserslocations,
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