From 35b04d096e32e8364942a7d61818d08165261260 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 14 Jul 2024 16:01:44 +0200 Subject: [PATCH] New log report by title --- core/views/logbooks.py | 55 ++++++++++++++++++++++++++++++ templates/expedition.html | 1 + templates/logreport.html | 72 +++++++++++++++++++++++++++++++++++++++ urls.py | 3 +- 4 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 templates/logreport.html 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 @@
  • wallet completion status for this Expo
  • alias names for this Expo
  • full logbook for this Expo +
  • logbook report for this Expo
  • new logbook entry for this Expo {% if logged_in %}

    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 %} + + +

    Logbook report for {{expedition.name}}

    + +

    Other years: +{% for otherexpedition in expeditions %} + {% if otherexpedition == expedition %} + | {{otherexpedition.year}} + {% else %} + | {{ otherexpedition.year }} + {% endif %} +{% endfor %} +

    + + + +

    {{expedition.name}} - Logbook entries per day

    + + + +{% regroup dateditems|dictsort:"date" by date as dates %} +{% for date in dates %} + {% for entry in date.list %} + + + + + + + + + {% endfor %} +{% endfor %} +
    DateLogged trips and diary entriesCaveText..AuthorWho 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 +

    + +

    {{expedition.name}}

    +{% endblock %} diff --git a/urls.py b/urls.py index 4fa5eba..6278d92 100644 --- a/urls.py +++ b/urls.py @@ -15,7 +15,7 @@ from troggle.core.views.expo import (pubspage, indexpage, editexpopage, expofile expofilessingle, expopage, map, mapfile, mediapage, spider) from troggle.core.views.logbooks import (QMs_jsonListView, Expeditions_jsonListView, - Expeditions_tsvListView, expedition, + Expeditions_tsvListView, expedition, logreport, get_logbook_entries, get_people, logbookentry, notablepersons, person, personexpedition) @@ -149,6 +149,7 @@ trogglepatterns = [ # Logbook entries re_path(r'^logbookentry/(?P.*)/(?P.*)/?$', logbookentry,name="logbookentry"), re_path(r'^logbook$', exportlogbook, name='exportlogbook'), + path('logreport/', logreport, name='logreport'), # Internal. editfile.html template uses these internally re_path(r'^getPeople/(?P.*)', get_people, name = "get_people"),