mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-02-08 13:18:15 +00:00
Removed obligatory typing when uploading photo
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
import io
|
import io
|
||||||
|
import re
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import django.forms as forms
|
import django.forms as forms
|
||||||
@@ -10,7 +12,7 @@ from django.urls import reverse
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
import troggle.settings as settings
|
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
|
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 ")
|
# print(f"new_image_form(): form is valid ")
|
||||||
editor = form.cleaned_data["who_are_you"]
|
editor = form.cleaned_data["who_are_you"]
|
||||||
editor = git_string(editor)
|
editor = git_string(editor)
|
||||||
|
title = form.cleaned_data["header"]
|
||||||
f = request.FILES["file_"]
|
f = request.FILES["file_"]
|
||||||
|
if not title:
|
||||||
|
title = f.name
|
||||||
binary_data = io.BytesIO()
|
binary_data = io.BytesIO()
|
||||||
for chunk in f.chunks():
|
for chunk in f.chunks():
|
||||||
binary_data.write(chunk)
|
binary_data.write(chunk)
|
||||||
@@ -140,9 +145,14 @@ def new_image_form(request, path):
|
|||||||
# int(f"new_image_form() After DUMP {exif=}")
|
# int(f"new_image_form() After DUMP {exif=}")
|
||||||
except:
|
except:
|
||||||
exif = None
|
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:
|
else:
|
||||||
exif = None
|
exif = None
|
||||||
|
|
||||||
|
|
||||||
width, height = i.size
|
width, height = i.size
|
||||||
# print(f"new_image_form(): {i.size=}")
|
# print(f"new_image_form(): {i.size=}")
|
||||||
if width > MAX_IMAGE_WIDTH or height > MAX_IMAGE_HEIGHT:
|
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_template = loader.get_template("image_page_template.html")
|
||||||
image_page = image_page_template.render(
|
image_page = image_page_template.render(
|
||||||
{
|
{
|
||||||
"header": form.cleaned_data["header"],
|
"header": title,
|
||||||
"description": form.cleaned_data["description"],
|
"description": descrip,
|
||||||
"photographer": form.cleaned_data["photographer"],
|
"photographer": form.cleaned_data["photographer"],
|
||||||
"year": form.cleaned_data["year"],
|
"year": form.cleaned_data["year"],
|
||||||
"filepath": f"/{image_rel_path}",
|
"filepath": f"/{image_rel_path}",
|
||||||
@@ -216,12 +226,22 @@ def new_image_form(request, path):
|
|||||||
return j_response
|
return j_response
|
||||||
else:
|
else:
|
||||||
# print(f"new_image_form(): not POST ")
|
# 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 ")
|
# print(f"new_image_form(): POST and not POST ")
|
||||||
template = loader.get_template("new_image_form.html")
|
template = loader.get_template("new_image_form.html")
|
||||||
htmlform = template.render({"form": form, "path": path}, request)
|
htmlform = template.render({"form": form, "path": path}, request)
|
||||||
return JsonResponse({"form": htmlform})
|
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):
|
class NewWebImageForm(forms.Form):
|
||||||
"""The form used by the editexpopage function"""
|
"""The form used by the editexpopage function"""
|
||||||
@@ -229,11 +249,11 @@ class NewWebImageForm(forms.Form):
|
|||||||
header = forms.CharField(
|
header = forms.CharField(
|
||||||
widget=forms.TextInput(
|
widget=forms.TextInput(
|
||||||
attrs={"size": "60", "placeholder": "Enter title (displayed as a header and in the tab)"}
|
attrs={"size": "60", "placeholder": "Enter title (displayed as a header and in the tab)"}
|
||||||
)
|
), required=False
|
||||||
)
|
)
|
||||||
file_ = forms.FileField()
|
file_ = forms.FileField()
|
||||||
description = forms.CharField(
|
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(
|
photographer = forms.CharField(
|
||||||
widget=forms.TextInput(attrs={"size": "60", "placeholder": "Photographers name"}), required=False
|
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
|
widget=forms.TextInput(attrs={"size": "60", "placeholder": "Year photo was taken"}), required=False
|
||||||
)
|
)
|
||||||
change_message = forms.CharField(
|
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(
|
who_are_you = forms.CharField(
|
||||||
widget=forms.TextInput(
|
widget=forms.TextInput(
|
||||||
|
|||||||
Reference in New Issue
Block a user