2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-03-30 08:19:51 +01:00

apparently all working

This commit is contained in:
2025-11-26 02:00:09 +02:00
parent ced9a7b024
commit 137b6bce7d
3 changed files with 73 additions and 33 deletions

View File

@@ -307,6 +307,7 @@ def logbookedit(request, year=None, slug=None):
if json_entries_dir.is_dir(): # only 2025 currently, or the current expo
print(f"- Rewriting JUST this edited logbook entry to a JSON file. ")
this_entry = LogbookEntry.objects.get(slug=slug)
write_entries_json([this_entry], year, editor)
else:
print(f"- Rewriting the entire {year} logbook to disc ")
@@ -329,22 +330,22 @@ def logbookedit(request, year=None, slug=None):
commit_msg = f"Online edit of logbookentry {slug}"
add_commit(contents_path, commit_msg, editor)
# This does not change the URL in the browser, so despite a new slug being created,
# the next time this code is run it thinks a new slug needs to be created. So we should
# actually redirect to a new URL (an edit not a create) not simply return a render object.
# logbookedit/2022-08-21a
# HOWEVER by doing a redirect rather than returning a rendered page, we lose all the
# error settings e.g dateflag and authroflag so the user gets no feedback about bad data entered.
# so we need to pass the flags explicitly in the url and then extract them from the request in the GET bit. sigh.
response = HttpResponseRedirect(f"/logbookedit/{slug}?dateflag={dateflag}&authorflag={authorflag}")
response.set_cookie('editor_id', editor, max_age=get_cookie_max_age(request)) # cookie expires after get_cookie_max_age(request) seconds
return response
# Do the redirect instead of this:
# Code fragment illustration - not actually what gets saved to database
# output = f'''
# This does not change the URL in the browser, so despite a new slug being created,
# the next time this code is run it thinks a new slug needs to be created. So we should
# actually redirect to a new URL (an edit not a create) not simply return a render object.
# logbookedit/2022-08-21a
# HOWEVER by doing a redirect rather than returning a rendered page, we lose all the
# error settings e.g dateflag and authroflag so the user gets no feedback about bad data entered.
# so we need to pass the flags explicitly in the url and then extract them from the request in the GET bit. sigh.
response = HttpResponseRedirect(f"/logbookedit/{slug}?dateflag={dateflag}&authorflag={authorflag}")
response.set_cookie('editor_id', editor, max_age=get_cookie_max_age(request)) # cookie expires after get_cookie_max_age(request) seconds
return response
# Do the redirect instead of this:
# Code fragment illustration - not actually what gets saved to database
# output = f'''
# <div class="tripdate" id="{slug}">{date}</div>
# <div class="trippeople"><u>{author}</u>, {others}</div>
@@ -356,22 +357,22 @@ def logbookedit(request, year=None, slug=None):
# <hr />
# ''' # return render(
# request,
# "logbookform.html",
# {
# "form": form,
# "year": year,
# "date": date, "dateflag": dateflag,
# "author": author, "authorflag": authorflag,
# "others": others,
# "place": place,
# "title": title,
# "tu": tu,
# "entry": entry,
# "output": output,
# "slug": slug,
# },
# )
# request,
# "logbookform.html",
# {
# "form": form,
# "year": year,
# "date": date, "dateflag": dateflag,
# "author": author, "authorflag": authorflag,
# "others": others,
# "place": place,
# "title": title,
# "tu": tu,
# "entry": entry,
# "output": output,
# "slug": slug,
# },
# )
# GET here. Does not fall-through from the POST section.
else:

View File

@@ -476,6 +476,7 @@ def write_entries_json(entries, year, editor):
for le in entries:
# filename = f"{le.slug}-{le.pk:03}.json"
print(le)
filename = f"{le.slug}.json"
filepath = dirpath / filename
ensure_dir_exists(filepath)
@@ -483,7 +484,7 @@ def write_entries_json(entries, year, editor):
entrydict = serialize_logentry(le)
write_json_file(entrydict)
git_add(filename, dirpath)
commit_msg = f"Exporting {len(entries)} logbook entries as individual files."
git_commit(dirpath, commit_msg, editor)
return True