diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2024-12-29 22:53:26 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2024-12-29 22:53:26 +0000 |
commit | 1ddd4da27bf1aa1594cdfc0477e016932c735026 (patch) | |
tree | 76685b18ba29efe91501b11102caa16e512677a8 /core/views | |
parent | 2623af92c410f9a481b01e025f7c21ef7a8cd8f9 (diff) | |
download | troggle-1ddd4da27bf1aa1594cdfc0477e016932c735026.tar.gz troggle-1ddd4da27bf1aa1594cdfc0477e016932c735026.tar.bz2 troggle-1ddd4da27bf1aa1594cdfc0477e016932c735026.zip |
Upload drawings now using git_add()
Diffstat (limited to 'core/views')
-rw-r--r-- | core/views/uploads.py | 80 |
1 files changed, 51 insertions, 29 deletions
diff --git a/core/views/uploads.py b/core/views/uploads.py index 98e2c43..869c466 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -16,6 +16,7 @@ from troggle.core.utils import ( alphabet_suffix, current_expo, get_cookie, + git_add, git_string, sanitize_name, unique_slug, @@ -53,7 +54,12 @@ todo = """ class FilesForm(forms.Form): # not a model-form, just a form-form uploadfiles = forms.FileField() - + who_are_you = forms.CharField( + widget=forms.TextInput( + attrs={"size": 100, "placeholder": "You are editing this page, who are you ? e.g. 'Wookey' or 'Animal <mta@gasthof.expo>'", + "style": "vertical-align: text-top;"} + ) + ) class FilesRenameForm(forms.Form): # not a model-form, just a form-form uploadfiles = forms.FileField() renameto = forms.CharField(strip=True, required=False) @@ -703,12 +709,16 @@ def dwgupload(request, folder=None, gitdisable="no"): urlfile = Path("/dwgdataraw/") / folder urldir = Path("/dwgupload/") / folder + editor = get_cookie(request) form = FilesForm() if request.method == "POST": form = FilesForm(request.POST, request.FILES) if form.is_valid(): # print(f'! - FORM dwgupload - POST valid: "{request.FILES["uploadfiles"]}" ') + editor = form.cleaned_data["who_are_you"] + editor = git_string(editor) + f = request.FILES["uploadfiles"] multiple = request.FILES.getlist("uploadfiles") savepath = Path(settings.DRAWINGS_DATA, folder) @@ -725,6 +735,12 @@ def dwgupload(request, folder=None, gitdisable="no"): git = "echo" # print(f'git DISABLED {f.name}') + # For saving, and then comitting, multiple files, we should be using write_and_commit() + # + # try: + # write_and_commit([(filepath, newtext, "utf-8")], f"Online edit of {path}", editor) + # except WriteAndCommitError as e: + # return render(request, "errors/generic.html", {"message": e.message}) if multiple: for f in multiple: # print(f'! - FORM dwgupload - file {f} in {multiple=}') @@ -736,36 +752,40 @@ def dwgupload(request, folder=None, gitdisable="no"): f'! - FORM dwgupload - \n!! Permissions failure ?! on attempting to save file "{f.name}" in "{savepath}". Attempting to continue..' ) if "saved_filename" in locals(): - if Path(dirpath, saved_filename).is_file(): + filepath = dirpath / saved_filename + if filepath.is_file(): actual_saved.append(saved_filename) + if gitdisable != "yes": - 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}) + 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 ) @@ -824,6 +844,7 @@ def dwgupload(request, folder=None, gitdisable="no"): message = f"! - FORM dwgupload - Nothing actually saved. All were refused. {actual_saved=}" print(message) + # GET request starts here files = [] dirs = [] # print(f'! - FORM dwgupload - start {folder=} \n"{dirpath=}" \n"{dirpath.parent=}" \n"{dirpath.exists()=}"') @@ -859,5 +880,6 @@ def dwgupload(request, folder=None, gitdisable="no"): "filesaved": filesaved, "actual_saved": actual_saved, "refused": refused, + "who_are_you": editor, }, ) |