diff options
Diffstat (limited to 'core/views')
-rw-r--r-- | core/views/caves.py | 22 | ||||
-rw-r--r-- | core/views/expo.py | 2 | ||||
-rw-r--r-- | core/views/survex.py | 6 |
3 files changed, 17 insertions, 13 deletions
diff --git a/core/views/caves.py b/core/views/caves.py index ba74f7b..a40b314 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -484,6 +484,7 @@ def edit_cave(request, path="", slug=None): if form.is_valid(): print(f'edit_cave(): POST is valid. Editing {cave}') editor = form.cleaned_data["who_are_you"] + editor = git_string(editor) cave = form.save(commit=False) # print(cave) if not cave.filename: @@ -645,10 +646,7 @@ def edit_entrance(request, path="", caveslug=None, entslug=None): imgpath = Path(path) / cave.areacode / cave.number() print(f"Edit Entrance {imgpath=}") - print(f"Reading cookie...") - editor_id = request.COOKIES.get('editor_id', 'Hohlenforscher <hohlenforscher@stonebridge.expo>') # if no cookie, then default string - editor = git_string(editor_id) # belt and braces, should have been validity checked on saving already - print(f"Cookie read: {editor_id=} reformatted as: {editor=}") + editor = get_cookie(request) if request.POST: print(f"POST Online edit of entrance: '{entrance}' where {cave=}") @@ -682,8 +680,9 @@ def edit_entrance(request, path="", caveslug=None, entslug=None): return render(request, "errors/generic.html", {"message": message}) else: - print(f"- POST {caveslug=} {entslug=} {entranceletter=} {path=}") + print(f"'edit_entrance(): POST is valid {caveslug=} Editing {entslug=} {entranceletter=} {path=}") editor = entform.cleaned_data["who_are_you"] + editor = git_string(editor) if entslug is None: # we are creating a new entrance entrance = entform.save(commit=False) @@ -731,14 +730,17 @@ def edit_entrance(request, path="", caveslug=None, entslug=None): print(f"- POST WRITE letter: '{ce}' {entrance=}") try: write_and_commit([entrance_file, cave_file], f"Online edit of entrance {entrance.slug}", editor) - return HttpResponseRedirect("/" + cave.url) + edit_response = HttpResponseRedirect("/" + cave.url) + edit_response.set_cookie('editor_id', editor, max_age=COOKIE_MAX_AGE) # cookie expires after COOKIE_MAX_AGE seconds + return edit_response except Exception as e: efilepath, econtent, eencoding = entrance_file cfilepath, ccontent, cencoding = cave_file message = f"- FAIL write_and_commit \n entr:'{efilepath}'\n cave:'{cfilepath}'\n\n{e}" print(message) return render(request, "errors/generic.html", {"message": message}) - + + # Unlike other similar forms, we do NOT drop into this GET code after processing the POST else: # GET the page, not POST, or if either of the forms were invalid when POSTed entletterform = None entletter = "" @@ -753,7 +755,7 @@ def edit_entrance(request, path="", caveslug=None, entslug=None): # ent only in db not on file. Interesting, let's run with it using whatever we have in the db print(f"ENTRANCE NOT read from file: entranceletter = '{ce.entranceletter}'") - entform = EntranceForm(instance=entrance) + entform = EntranceForm(instance=entrance, initial={"who_are_you":editor}) if entslug is None: entletterform = EntranceLetterForm() # print(f" Getting entletter from EntranceLetterForm") @@ -764,9 +766,9 @@ def edit_entrance(request, path="", caveslug=None, entslug=None): print(f" Blank value: getting entletter from EntranceLetterForm") print(f"{entletter=} ") else: - entform = EntranceForm() + entform = EntranceForm(initial={"who_are_you":editor}) entletterform = EntranceLetterForm() - + return render( request, "editentrance.html", diff --git a/core/views/expo.py b/core/views/expo.py index 848fe21..3432ac3 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -457,6 +457,7 @@ def editexpopage(request, path): pageform = ExpoPageForm(request.POST) # A form bound to the POST data if pageform.is_valid(): # Form valid therefore write file editor = pageform.cleaned_data["who_are_you"] + editor = git_string(editor) # print("### \n", str(pageform)[0:300]) # print("### \n csrfmiddlewaretoken: ",request.POST['csrfmiddlewaretoken']) if filefound: @@ -489,6 +490,7 @@ def editexpopage(request, path): try: change_message = pageform.cleaned_data["change_message"] editor = pageform.cleaned_data["who_are_you"] + editor = git_string(editor) write_and_commit([(filepath, result, "utf-8")], f"{change_message} - online edit of {path}", editor) except WriteAndCommitError as e: return render(request, "errors/generic.html", {"message": e.message}) diff --git a/core/views/survex.py b/core/views/survex.py index afa6a69..5707720 100644 --- a/core/views/survex.py +++ b/core/views/survex.py @@ -324,8 +324,9 @@ def svx(request, survex_file): if request.method == "POST": # If the form has been submitted... rform = SvxForm(request.POST) # - if rform.is_valid(): # All validation rules pass (how do we check it against the filename and users?) + if rform.is_valid(): # All Django syntax validation rules pass (how do we check it against a valid filename and users?) editor = rform.cleaned_data["who_are_you"] + editor = git_string(editor) rcode = rform.cleaned_data["code"] outputtype = rform.cleaned_data["outputtype"] # used by CodeMirror ajax I think difflist = form.DiffCode(rcode) @@ -352,9 +353,8 @@ def svx(request, survex_file): if "save" in rform.data: if request.user.is_authenticated: if difflist: - editor = rform.cleaned_data["who_are_you"] print(f"Saving code and editor id {editor=}") - message = form.SaveCode(rcode, editor) + message = form.SaveCode(rcode, editor) # saves file and does git thing else: message = "NO DIFFERENCES - so not saving the file" else: |