mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-01-19 05:42:54 +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")])
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "expobase.html" %}
|
||||
{% block title %}Edit {{ path }}{% endblock %}
|
||||
{% block extrahead %}
|
||||
{% include 'html_editor_scripts_css.html' %}
|
||||
{% include 'html_editor_scripts_css.html' %} <!-- JS magic to make a popup image selector page -->
|
||||
{% endblock %}
|
||||
{% block body %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user