mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-19 05:57:20 +00:00
create marker .url file for uploaded image
This commit is contained in:
@@ -19,7 +19,7 @@ import troggle.settings as settings
|
||||
from troggle.core.utils import ( COOKIE_MAX_AGE,
|
||||
WriteAndCommitError, get_editor,
|
||||
git_string,
|
||||
write_binary_file, write_and_commit,
|
||||
write_binary_file, write_and_commit, write_files,
|
||||
current_expo, random_slug, ensure_dir_exists,
|
||||
is_identified_user
|
||||
)
|
||||
@@ -291,6 +291,7 @@ def new_image_form(request, path):
|
||||
editor = form.cleaned_data["who_are_you"]
|
||||
editor = git_string(editor)
|
||||
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_"]
|
||||
if not title:
|
||||
title = f.name
|
||||
@@ -395,7 +396,7 @@ 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
|
||||
)
|
||||
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.set_cookie('editor_id', editor, max_age=COOKIE_MAX_AGE) # does NOT seem to work updating who_are_you cookie
|
||||
return j_response
|
||||
@@ -422,7 +423,7 @@ def extract_git_name(git_str):
|
||||
return match.group(1).strip()
|
||||
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
|
||||
|
||||
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
|
||||
content = f.read()
|
||||
write_binary_file(filepath, content)
|
||||
write_url_file(filepath, f.name, handbook_directory, page)
|
||||
elif isinstance(f, TemporaryUploadedFile):
|
||||
if filepath.is_file:
|
||||
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()}")
|
||||
try:
|
||||
dest = shutil.move(f.temporary_file_path(), filepath)
|
||||
write_url_file(filepath, f.name, handbook_directory, page)
|
||||
except Exception as e:
|
||||
print("+++++ ",e)
|
||||
raise
|
||||
@@ -467,6 +470,21 @@ def save_original_in_expofiles(f, year, photographer):
|
||||
print(msg)
|
||||
raise TypeError(msg)
|
||||
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):
|
||||
"""The form used by the editexpopage function"""
|
||||
|
||||
Reference in New Issue
Block a user