2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-04-01 00:47:09 +01:00

create marker .url file for uploaded image

This commit is contained in:
2025-02-21 22:14:17 +02:00
parent 81fba01d1e
commit 8a95b0609d

View File

@@ -19,7 +19,7 @@ import troggle.settings as settings
from troggle.core.utils import ( COOKIE_MAX_AGE, from troggle.core.utils import ( COOKIE_MAX_AGE,
WriteAndCommitError, get_editor, WriteAndCommitError, get_editor,
git_string, git_string,
write_binary_file, write_and_commit, write_binary_file, write_and_commit, write_files,
current_expo, random_slug, ensure_dir_exists, current_expo, random_slug, ensure_dir_exists,
is_identified_user is_identified_user
) )
@@ -291,6 +291,7 @@ def new_image_form(request, path):
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"] title = form.cleaned_data["header"]
page = title # NOT GOOD, we want the URL of the calling page, but this context is lost ?
f = request.FILES["file_"] f = request.FILES["file_"]
if not title: if not title:
title = f.name title = f.name
@@ -395,7 +396,7 @@ def new_image_form(request, path):
html_snippet = linked_image_template.render( html_snippet = linked_image_template.render(
{"thumbnail_url": f"/{thumb_rel_path}", "page_url": f"/{desc_rel_path}"}, request {"thumbnail_url": f"/{thumb_rel_path}", "page_url": f"/{desc_rel_path}"}, request
) )
save_original_in_expofiles(f, year, form.cleaned_data["photographer"]) save_original_in_expofiles(f, year, form.cleaned_data["photographer"], image_rel_path, page)
j_response = 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 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 return j_response
@@ -422,7 +423,7 @@ def extract_git_name(git_str):
return match.group(1).strip() return match.group(1).strip()
return "Anon." return "Anon."
def save_original_in_expofiles(f, year, photographer): def save_original_in_expofiles(f, year, photographer, handbook_directory, page):
"""Moves the uploaded file from /tmp to EXPOFILES """Moves the uploaded file from /tmp to EXPOFILES
This may be redundant, if the original was already in EXPOFILES, but this This may be redundant, if the original was already in EXPOFILES, but this
@@ -446,6 +447,7 @@ def save_original_in_expofiles(f, year, photographer):
f.open() # rewind to beginning f.open() # rewind to beginning
content = f.read() content = f.read()
write_binary_file(filepath, content) write_binary_file(filepath, content)
write_url_file(filepath, f.name, handbook_directory, page)
elif isinstance(f, TemporaryUploadedFile): elif isinstance(f, TemporaryUploadedFile):
if filepath.is_file: if filepath.is_file:
print(f"+++++ Out of cheese error\n Destination EXISTS {filepath}") print(f"+++++ Out of cheese error\n Destination EXISTS {filepath}")
@@ -457,6 +459,7 @@ def save_original_in_expofiles(f, year, photographer):
# print(f"+++++ Found {f.temporary_file_path()}") # print(f"+++++ Found {f.temporary_file_path()}")
try: try:
dest = shutil.move(f.temporary_file_path(), filepath) dest = shutil.move(f.temporary_file_path(), filepath)
write_url_file(filepath, f.name, handbook_directory, page)
except Exception as e: except Exception as e:
print("+++++ ",e) print("+++++ ",e)
raise raise
@@ -467,6 +470,21 @@ def save_original_in_expofiles(f, year, photographer):
print(msg) print(msg)
raise TypeError(msg) raise TypeError(msg)
return return
def write_url_file(targetpath, name, handbook_rel_path, page):
# still no good, this is just getting where the copied image is stored on the handbook,
# not which handbook page has it visible in it.
# the ".url" is there, just never visible in Windows Explorer.
# FIND and fix th "page" value to be the originating page, somewhere inthe request() data? Previous page??
# FIND AND FIX the correct host for this !
host = "localhost:8000/"
content = f"[InternetShortcut]\nURL=http://{host}{handbook_rel_path}\n\n[TrogglePage]\nURL=http://{page}"
print(content)
filepath = targetpath.with_suffix(".url")
write_files([(filepath, content, "utf8")])
class NewWebImageForm(forms.Form): class NewWebImageForm(forms.Form):
"""The form used by the editexpopage function""" """The form used by the editexpopage function"""