2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-19 06:17:15 +00:00

Removed obligatory typing when uploading photo

This commit is contained in:
2025-02-11 00:59:33 +00:00
parent 91d8d33e95
commit 89afdded38

View File

@@ -1,4 +1,6 @@
import io
import re
from pathlib import Path
import django.forms as forms
@@ -10,7 +12,7 @@ from django.urls import reverse
from PIL import Image
import troggle.settings as settings
from troggle.core.utils import COOKIE_MAX_AGE, WriteAndCommitError, get_cookie, git_string, write_and_commit
from troggle.core.utils import COOKIE_MAX_AGE, WriteAndCommitError, get_cookie, git_string, write_and_commit, current_expo
from .auth import login_required_if_public
@@ -122,7 +124,10 @@ def new_image_form(request, path):
# print(f"new_image_form(): form is valid ")
editor = form.cleaned_data["who_are_you"]
editor = git_string(editor)
title = form.cleaned_data["header"]
f = request.FILES["file_"]
if not title:
title = f.name
binary_data = io.BytesIO()
for chunk in f.chunks():
binary_data.write(chunk)
@@ -140,9 +145,14 @@ def new_image_form(request, path):
# int(f"new_image_form() After DUMP {exif=}")
except:
exif = None
descrip = form.cleaned_data["description"]
if not descrip:
# date and time from exif data
descrip = f"{exif_dict["Exif"][36867].decode()} {exif_dict["Exif"][36880].decode()}"
else:
exif = None
width, height = i.size
# print(f"new_image_form(): {i.size=}")
if width > MAX_IMAGE_WIDTH or height > MAX_IMAGE_HEIGHT:
@@ -177,8 +187,8 @@ def new_image_form(request, path):
image_page_template = loader.get_template("image_page_template.html")
image_page = image_page_template.render(
{
"header": form.cleaned_data["header"],
"description": form.cleaned_data["description"],
"header": title,
"description": descrip,
"photographer": form.cleaned_data["photographer"],
"year": form.cleaned_data["year"],
"filepath": f"/{image_rel_path}",
@@ -216,12 +226,22 @@ def new_image_form(request, path):
return j_response
else:
# print(f"new_image_form(): not POST ")
form = NewWebImageForm(directory=directory, initial={"who_are_you":editor})
initial={"who_are_you":editor,
"year": current_expo(), "photographer": extract_git_name(editor),
"change_message": "Uploading photo"}
form = NewWebImageForm(directory=directory, initial=initial )
# 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)
return JsonResponse({"form": htmlform})
def extract_git_name(git_str):
pattern = r"^([^<]+)"
match = re.match(pattern, git_str)
if match:
return match.group(1).strip()
return "Anon."
class NewWebImageForm(forms.Form):
"""The form used by the editexpopage function"""
@@ -229,11 +249,11 @@ class NewWebImageForm(forms.Form):
header = forms.CharField(
widget=forms.TextInput(
attrs={"size": "60", "placeholder": "Enter title (displayed as a header and in the tab)"}
)
), required=False
)
file_ = forms.FileField()
description = forms.CharField(
widget=forms.Textarea(attrs={"cols": 80, "rows": 20, "placeholder": "Describe the photo (using HTML)"})
widget=forms.Textarea(attrs={"cols": 80, "rows": 20, "placeholder": "Describe the photo (using HTML)"}), required=False
)
photographer = forms.CharField(
widget=forms.TextInput(attrs={"size": "60", "placeholder": "Photographers name"}), required=False
@@ -242,7 +262,7 @@ 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": "Describe the change made (for git)"})
widget=forms.Textarea(attrs={"cols": 80, "rows": 3, "placeholder": "Describe the change made (for git)"}), required=False
)
who_are_you = forms.CharField(
widget=forms.TextInput(