diff --git a/core/views/logbooks.py b/core/views/logbooks.py index 6e207ca..8f7d002 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -218,6 +218,61 @@ def personexpedition(request, slug="", year=""): print(msg) return render(request, "errors/generic.html", {"message": msg}) +def logreport(request, year=1999): + """ + Remember that 'personexpedition__expedition' is interpreted by Django to mean the + 'expedition' object which is connected by a foreign key to the 'personexpedition' + object, which is a field of the PersonLogEntry object: + PersonLogEntry.objects.filter(personexpedition__expedition=expo) + +""" + print(f"logreport(): begun") + + expeditions = Expedition.objects.all() # top menu only, evaluated only when template renders + dates = None + dateditems = None + + + try: + expo = Expedition.objects.get(year=int(year)) + except: + message = ( + "Expedition not found - database apparently empty, you probably need to do a full re-import of all data." + ) + return render(request, "errors/generic.html", {"message": message}) + + entries = expo.logbookentry_set.all() # lazy list + dateditems = list(entries) # evaluates the Django query and hits db + dates = sorted(set([item.date for item in dateditems])) + + try: + for entry in dateditems: + + people = PersonLogEntry.objects.filter(logbook_entry=entry) + entry.who = [] + for p in people: + if p.is_logbook_entry_author: + entry.author = p + else: + entry.who.append(p) + + + print(f"logreport(): trying..") + context = { + "year": year, + "expedition": expo, + "expeditions": expeditions, + "settings": settings, + "dateditems": dateditems, + "dates": dates, + } + print(f"logreport(): rendering..") + return render(request, "logreport.html", context) + + except Exception as e: + msg = f' Logbook report for year:"{year}" not implemented yet\n{e}\n {context}' + print(msg) + return render(request, "errors/generic.html", {"message": msg}) def logbookentry(request, date, slug): # start = time.time() diff --git a/templates/expedition.html b/templates/expedition.html index e68afa6..0aa8d8c 100644 --- a/templates/expedition.html +++ b/templates/expedition.html @@ -23,6 +23,7 @@
Reparse and reload this year's logbook by clicking here: RELOAD diff --git a/templates/logreport.html b/templates/logreport.html new file mode 100644 index 0000000..087792e --- /dev/null +++ b/templates/logreport.html @@ -0,0 +1,72 @@ +{% extends "base.html" %} +{% block title %}Log Report {{year}} for {{expedition.name}}{% endblock %} +{% block related %} +{% endblock %} + +{% block content %} + + +
Other years: +{% for otherexpedition in expeditions %} + {% if otherexpedition == expedition %} + | {{otherexpedition.year}} + {% else %} + | {{ otherexpedition.year }} + {% endif %} +{% endfor %} +
+ + + +Date | Logged trips and diary entries | Cave | Text.. | Author | Who else |
---|---|---|---|---|---|
{{date.grouper|date:"D d M Y"}} | ++ {{entry.title|truncatechars:30|safe|striptags}} + | +
+ {% if entry.cave %}
+ {{entry.cave|safe}} + {% else %} + + {% endif %} + |
+ + {{entry.text|striptags|safe|truncatechars:30}} + | ++ {{entry.author.nickname_used}} + | ++ {% if entry.who %} + {% for w in entry.who %} + {{w.nickname_used}}, + {% endfor %} + {% endif %} + + | +
See also the +