summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2025-02-22 10:11:24 +0200
committerPhilip Sargent <philip.sargent@gmail.com>2025-02-22 10:11:24 +0200
commite95cff58180ec4f251dafeedb437dd48a94cbd9e (patch)
tree062eea65c1fe72d8ef5e5b19aac320d6a58633ed /core
parent8a95b0609dbcbcdf6ea603beace6877fb5d03301 (diff)
downloadtroggle-e95cff58180ec4f251dafeedb437dd48a94cbd9e.tar.gz
troggle-e95cff58180ec4f251dafeedb437dd48a94cbd9e.tar.bz2
troggle-e95cff58180ec4f251dafeedb437dd48a94cbd9e.zip
produce .url file in same folder as orig. photo in expofiles
Diffstat (limited to 'core')
-rw-r--r--core/views/editor_helpers.py21
-rw-r--r--core/views/expo.py10
2 files changed, 13 insertions, 18 deletions
diff --git a/core/views/editor_helpers.py b/core/views/editor_helpers.py
index 1430bdf..05716b0 100644
--- a/core/views/editor_helpers.py
+++ b/core/views/editor_helpers.py
@@ -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")])
diff --git a/core/views/expo.py b/core/views/expo.py
index f9ff399..cdd0030 100644
--- a/core/views/expo.py
+++ b/core/views/expo.py
@@ -18,9 +18,6 @@ from troggle.core.utils import (
WriteAndCommitError,
current_expo,
get_editor,
- # get_cookie,
- # git_string,
- # get_git_string,
write_and_commit,
is_identified_user
)
@@ -273,6 +270,9 @@ def expowebpage(request, expowebpath, path):
def mediapage(request, subpath=None, doc_root=None):
"""This is for special prefix paths /photos/ /site_media/, /static/ etc.
as defined in urls.py . If given a directory, gives a failure page.
+
+ If running on the server, Apache intercepts these so this code is not used there,
+ but it is vital for the devserver.
"""
#print("mediapath", subpath)
if doc_root is not None:
@@ -448,10 +448,6 @@ def editexpopage(request, path):
if m:
filefound = True
preheader, headerargs, head, postheader, bodyargs, body, postbody = m.groups()
- # linksmatch = re.match(r'(.*)(<ul\s+id="links">.*)', body, re.DOTALL + re.IGNORECASE)
- # if linksmatch:
- # body, links = linksmatch.groups()
-
else:
return HttpResponse(
default_head