mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-16 23:37:03 +00:00
refactored
This commit is contained in:
@@ -28,6 +28,7 @@ todo = """- Fix the get_person_chronology() display bug.
|
|||||||
- Fix id= value preservation on editing
|
- Fix id= value preservation on editing
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
LOGBOOK_ENTRIES = "log_entries" # directory name
|
||||||
|
|
||||||
def notablepersons(request):
|
def notablepersons(request):
|
||||||
def notabilitykey(person):
|
def notabilitykey(person):
|
||||||
@@ -383,34 +384,21 @@ def logbook_entries_export(request, year):
|
|||||||
entries = get_entries(year)
|
entries = get_entries(year)
|
||||||
# for e in entries:
|
# for e in entries:
|
||||||
# print(f"{e.pk:03} {e}")
|
# print(f"{e.pk:03} {e}")
|
||||||
|
|
||||||
editor = get_editor(request)
|
editor = get_editor(request)
|
||||||
|
|
||||||
write_entries(entries, year, editor)
|
write_entries(entries, year, editor)
|
||||||
return redirect(f"/logreport/{year}")
|
return redirect(f"/logreport/{year}")
|
||||||
|
|
||||||
|
|
||||||
def write_entries(entries, year, editor):
|
def write_entries(entries, year, editor):
|
||||||
|
"""Exports logentries from the live database to JSON files.
|
||||||
|
|
||||||
dirpath = settings.EXPOWEB / "years" / year / "log_entries"
|
entries - a list, use a list of one member if writing a single entry
|
||||||
try:
|
|
||||||
dirpath.mkdir(parents=True, exist_ok=True)
|
|
||||||
except PermissionError as e:
|
|
||||||
raise PermissionError(
|
|
||||||
f"CANNOT make the directory.\nPERMISSIONS incorrectly set on server for this file {filepath}. Ask a nerd to fix this: {e}"
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
raise OSError(
|
|
||||||
f"CANNOT make the directory for {filepath}. Ask a nerd to fix this: {e}"
|
|
||||||
)
|
|
||||||
|
|
||||||
for le in entries:
|
year - the year of the expo.
|
||||||
# REPLACE this with hand-built serializer which includes .author, .who which were added to the entries but re not in the model Class directly
|
"""
|
||||||
# see below for Gemini code to do that. Going to bed now.
|
|
||||||
jsondict = serialize("json", [le], fields=('slug', 'date', 'expedition', 'title', 'cave', 'place', 'other_people', 'time_underground', 'text'))
|
|
||||||
|
|
||||||
filename = f"{le.slug}-{le.pk:03}.json"
|
def write_json_file():
|
||||||
filepath = dirpath / filename
|
|
||||||
description = f" {le.slug} :: {le.date} - {le.title}"
|
|
||||||
try:
|
try:
|
||||||
with open(filepath, 'w', encoding='utf-8') as json_f:
|
with open(filepath, 'w', encoding='utf-8') as json_f:
|
||||||
json.dump(jsondict, json_f, indent=1)
|
json.dump(jsondict, json_f, indent=1)
|
||||||
@@ -422,6 +410,19 @@ def write_entries(entries, year, editor):
|
|||||||
print(f"CANNOT write this file {filepath}. Exception dumping json. Ask a nerd to fix this: {e}")
|
print(f"CANNOT write this file {filepath}. Exception dumping json. Ask a nerd to fix this: {e}")
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
dirpath = settings.EXPOWEB / "years" / year / LOGBOOK_ENTRIES
|
||||||
|
dirpath.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
for le in entries:
|
||||||
|
filename = f"{le.slug}-{le.pk:03}.json"
|
||||||
|
filepath = dirpath / filename
|
||||||
|
# description = f" {le.slug} :: {le.date} - {le.title}"
|
||||||
|
|
||||||
|
# REPLACE this with hand-built serializer which includes .author, .who which were added to the entries but re not in the model Class directly
|
||||||
|
# see below for Gemini code to do that. Going to bed now.
|
||||||
|
jsondict = serialize("json", [le], fields=('slug', 'date', 'expedition', 'title', 'cave', 'place', 'other_people', 'time_underground', 'text'))
|
||||||
|
|
||||||
|
write_json_file()
|
||||||
git_add(filename, dirpath)
|
git_add(filename, dirpath)
|
||||||
|
|
||||||
commit_msg = f"Exporting logbook entries as individual files"
|
commit_msg = f"Exporting logbook entries as individual files"
|
||||||
|
|||||||
Reference in New Issue
Block a user