mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-18 22:37:10 +00:00
produce .url file in same folder as orig. photo in expofiles
This commit is contained in:
@@ -264,6 +264,9 @@ def fix_dump_bugs(exif_dict):
|
||||
def new_image_form(request, path):
|
||||
"""Manages a form to upload new images
|
||||
|
||||
This returns JSON, not a normal response, because it is called
|
||||
by JavaScript ajax.
|
||||
|
||||
exif_dict = piexif.load(im.info["exif"])
|
||||
exif_dict = {"0th":zeroth_ifd, "Exif":exif_ifd, "GPS":gps_ifd, ...more}
|
||||
"""
|
||||
@@ -291,7 +294,8 @@ 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 ?
|
||||
referer = request.headers["Referer"].replace("_edit","") # original page being edited
|
||||
host = request.headers["Host"]
|
||||
f = request.FILES["file_"]
|
||||
if not title:
|
||||
title = f.name
|
||||
@@ -396,7 +400,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"], image_rel_path, page)
|
||||
save_original_in_expofiles(f, year, form.cleaned_data["photographer"], host, image_rel_path, referer)
|
||||
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
|
||||
@@ -423,7 +427,7 @@ def extract_git_name(git_str):
|
||||
return match.group(1).strip()
|
||||
return "Anon."
|
||||
|
||||
def save_original_in_expofiles(f, year, photographer, handbook_directory, page):
|
||||
def save_original_in_expofiles(f, year, photographer, host, handbook_directory, page):
|
||||
"""Moves the uploaded file from /tmp to EXPOFILES
|
||||
|
||||
This may be redundant, if the original was already in EXPOFILES, but this
|
||||
@@ -459,7 +463,7 @@ def save_original_in_expofiles(f, year, photographer, handbook_directory, page):
|
||||
# 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)
|
||||
write_url_file(filepath, host, handbook_directory, page)
|
||||
except Exception as e:
|
||||
print("+++++ ",e)
|
||||
raise
|
||||
@@ -471,17 +475,12 @@ def save_original_in_expofiles(f, year, photographer, handbook_directory, page):
|
||||
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.
|
||||
|
||||
def write_url_file(targetpath, host, handbook_rel_path, page):
|
||||
# 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}"
|
||||
content = f"[InternetShortcut]\nURL={page}\n\n[TroggleImage]\nURL=http://{host}/{handbook_rel_path}"
|
||||
print(content)
|
||||
filepath = targetpath.with_suffix(".url")
|
||||
write_files([(filepath, content, "utf8")])
|
||||
|
||||
Reference in New Issue
Block a user