2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-02-08 07:40:19 +00:00

Edit Logbook Entry mostly working

This commit is contained in:
2023-08-31 18:55:20 +03:00
parent bbb821e2f9
commit c29c12ea76
7 changed files with 276 additions and 100 deletions

View File

@@ -1,8 +1,11 @@
import re
from pathlib import Path
from urllib.parse import urljoin
from django.db import models
from django.urls import reverse
from django.template import loader
import settings
from troggle.core.models.troggle import Expedition, TroggleModel
@@ -50,7 +53,7 @@ class LogbookEntry(TroggleModel):
max_length=100, blank=True, null=True, help_text="Only use this if you haven't chosen a cave"
)
text = models.TextField()
slug = models.SlugField(max_length=50)
slug = models.SlugField(max_length=50) # this is tripid
time_underground = models.FloatField(null=True, help_text="In decimal hours")
class Meta:
@@ -93,7 +96,47 @@ class LogbookEntry(TroggleModel):
index = index % mx
return index
def writelogbook(year, filename):
current_expedition = Expedition.objects.get(year=year)
logbook_entries = LogbookEntry.objects.filter(expedition=current_expedition).order_by(
"slug"
) # now that slug, aka tripid, is in our standard date form, this will preserve ordering.
print(f"Logbook exported has {len(logbook_entries)} entries in it.")
extension = "html"
template = "logbook2005style.html"
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)
# print(f'Logbook exported to {filepath}')
class PersonLogEntry(TroggleModel):
"""Single Person going on a trip, which may or may not be written up.
It could account for different T/U for people in same logbook entry.