summaryrefslogtreecommitdiffstats
path: root/core/views/other.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2023-08-31 18:55:20 +0300
committerPhilip Sargent <philip.sargent@gmail.com>2023-08-31 18:55:20 +0300
commitc29c12ea765eefcd2ac41a7f475c8d870adcb793 (patch)
treed5da2cc80bb15e913835bedfd70f340413af17fe /core/views/other.py
parentbbb821e2f9a55eaaf636909341b8c7799f079ce2 (diff)
downloadtroggle-c29c12ea765eefcd2ac41a7f475c8d870adcb793.tar.gz
troggle-c29c12ea765eefcd2ac41a7f475c8d870adcb793.tar.bz2
troggle-c29c12ea765eefcd2ac41a7f475c8d870adcb793.zip
Edit Logbook Entry mostly working
Diffstat (limited to 'core/views/other.py')
-rw-r--r--core/views/other.py62
1 files changed, 12 insertions, 50 deletions
diff --git a/core/views/other.py b/core/views/other.py
index 8d40079..4d7d3f1 100644
--- a/core/views/other.py
+++ b/core/views/other.py
@@ -7,7 +7,7 @@ from django.shortcuts import render
from django.template import loader
from troggle.core.models.caves import Cave
-from troggle.core.models.logbooks import LogbookEntry # , PersonLogEntry
+from troggle.core.models.logbooks import LogbookEntry, writelogbook # , PersonLogEntry
# from databaseReset import reinit_db # don't do this. databaseRest runs code *at import time*
from troggle.core.models.troggle import Expedition
@@ -169,69 +169,31 @@ def controlpanel(request):
)
-def exportlogbook(request, year=None, extension=None):
+def exportlogbook(request, year=None):
"""Constructs, from the database, a complete HTML formatted logbook
- for the current year. Formats available are HTML2005. Other formats
- have been retired.
+ for the current year. Format available is now just HTML2005.
+ Other formats have been retired.
There are no images stored in the database. However links to images work in the HTML text of a logbook entry.
- This function is the recipient of the POST action os the export form in the control panel
+ This function is the recipient of the POST action as the export form in the control panel
"""
def lbeKey(lbe):
- """This function goes into a lexicographic sort function"""
- return str(lbe.date)
+ """This function goes into a lexicographic sort function - but where?!"""
+ return str(lbe.slug) # now that slugs are tripid such as 2023-07-30b
if not request.method == "POST":
return render(request, "controlPanel.html", {"expeditions": Expedition.objects.all(), "jobs_completed": ""})
else:
- print(f"Logbook export {request.POST}")
+ # print(f"Logbook export {request.POST}")
year = request.POST["year"]
- current_expedition = Expedition.objects.get(year=year)
- logbook_entries = LogbookEntry.objects.filter(expedition=current_expedition).order_by(
- "date"
- ) # need to be sorted by date!
-
- print(f"Logbook has {len(logbook_entries)} entries in it.")
-
- extension = "html"
- response = HttpResponse(content_type="text/html")
- style = "2005"
-
- filename = "logbook-new-format." + extension
- template = "logbook" + style + "style." + extension
- response["Content-Disposition"] = "attachment; filename=" + filename
- t = loader.get_template(template)
- logbookfile = t.render({"logbook_entries": logbook_entries})
-
- endpath = Path(settings.EXPOWEB, "years", year, "endmatter.html")
- endmatter = ""
- if endpath.is_file():
- try:
- with open(endpath, "r") as end:
- endmatter = end.read()
- except:
- print(" ! Very Bad Error opening " + endpath)
-
- frontpath = Path(settings.EXPOWEB, "years", year, "frontmatter.html")
- if frontpath.is_file():
- try:
- with open(frontpath, "r") as front:
- frontmatter = front.read()
- except:
- print(" ! Very Bad Error opening " + frontpath)
- logbookfile = re.sub(r"<body>", "<body>\n" + frontmatter + endmatter, logbookfile)
- else:
- logbookfile = re.sub(r"<body>", f"<body>\n<h1>Expo {year}</h1>\n" + endmatter, logbookfile)
-
- dir = Path(settings.EXPOWEB) / "years" / year
- filepath = Path(dir, filename)
- with (open(filepath, "w")) as lb:
- lb.writelines(logbookfile)
+ filename = "logbook-new-format.html"
- # print(f'Logbook exported to {filepath}')
+ writelogbook(year, filename)
+ #response = HttpResponse(content_type="text/html")
+ #response["Content-Disposition"] = "attachment; filename=" + filename
completed = f'Logbook exported to <a href="/years/{filename}">{filename}</a>'
return render(