mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-17 09:07:19 +00:00
refactor & git author work
This commit is contained in:
@@ -11,7 +11,7 @@ from django.views.decorators.csrf import ensure_csrf_cookie
|
||||
from PIL import Image
|
||||
|
||||
import troggle.settings as settings
|
||||
from troggle.core.utils import WriteAndCommitError, write_and_commit
|
||||
from troggle.core.utils import COOKIE_MAX_AGE, WriteAndCommitError, get_cookie, git_string, write_and_commit
|
||||
|
||||
from .auth import login_required_if_public
|
||||
|
||||
@@ -97,12 +97,16 @@ def new_image_form(request, path):
|
||||
"""Manages a form to upload new images"""
|
||||
directory = get_dir(path)
|
||||
print(f"new_image_form(): {directory=} {path=}")
|
||||
|
||||
editor = get_cookie(request)
|
||||
if request.method == "POST":
|
||||
print(f"new_image_form(): POST ")
|
||||
form = NewWebImageForm(request.POST, request.FILES, directory=directory)
|
||||
if form.is_valid():
|
||||
print(f"new_image_form(): form is valid ")
|
||||
print(f"new_image_form(): files: {request.FILES['file_']}")
|
||||
editor = form.cleaned_data["who_are_you"]
|
||||
editor = git_string(editor)
|
||||
f = request.FILES["file_"]
|
||||
binary_data = io.BytesIO()
|
||||
for chunk in f.chunks():
|
||||
@@ -171,6 +175,7 @@ def new_image_form(request, path):
|
||||
(thumb_path, tb.getbuffer(), False),
|
||||
],
|
||||
f"{change_message} - online adding of an image",
|
||||
editor # this works, a new who_are_you typed on the Image form is used as the git comment
|
||||
)
|
||||
except WriteAndCommitError as e:
|
||||
print(f"new_image_form(): WriteAndCommitError: {e.message}")
|
||||
@@ -183,10 +188,12 @@ def new_image_form(request, path):
|
||||
html_snippet = linked_image_template.render(
|
||||
{"thumbnail_url": f"/{thumb_rel_path}", "page_url": f"/{desc_rel_path}"}, request
|
||||
)
|
||||
return JsonResponse({"html": html_snippet})
|
||||
j_response = JsonResponse({"html": html_snippet})
|
||||
j_response.set_cookie('editor_id', editor, max_age=COOKIE_MAX_AGE) # does not seem to work updating who_are_you cookie
|
||||
return j_response
|
||||
else:
|
||||
print(f"new_image_form(): not POST ")
|
||||
form = NewWebImageForm(directory=directory)
|
||||
form = NewWebImageForm(directory=directory, initial={"who_are_you":editor})
|
||||
print(f"new_image_form(): POST and not POST ")
|
||||
template = loader.get_template("new_image_form.html")
|
||||
htmlform = template.render({"form": form, "path": path}, request)
|
||||
@@ -212,9 +219,15 @@ class NewWebImageForm(forms.Form):
|
||||
widget=forms.TextInput(attrs={"size": "60", "placeholder": "Year photo was taken"}), required=False
|
||||
)
|
||||
change_message = forms.CharField(
|
||||
widget=forms.Textarea(attrs={"cols": 80, "rows": 3, "placeholder": "Descibe the change made (for git)"})
|
||||
widget=forms.Textarea(attrs={"cols": 80, "rows": 3, "placeholder": "Describe the change made (for git)"})
|
||||
)
|
||||
|
||||
who_are_you = forms.CharField(
|
||||
widget=forms.TextInput(
|
||||
attrs={"size": 60, "placeholder": "You are editing this page, who are you ? e.g. 'Becka' or 'Animal <mta@gasthof.expo>'",
|
||||
"style": "vertical-align: text-top;"}
|
||||
)
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.directory = Path(kwargs.pop("directory"))
|
||||
super(forms.Form, self).__init__(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user