diff options
Diffstat (limited to 'core/views/survex.py')
-rw-r--r-- | core/views/survex.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/core/views/survex.py b/core/views/survex.py index 70f4616..0255559 100644 --- a/core/views/survex.py +++ b/core/views/survex.py @@ -4,6 +4,7 @@ import os import re import socket from pathlib import Path +from collections import namedtuple from django import forms from django.db import models @@ -14,8 +15,10 @@ from django.shortcuts import render from django.views.decorators.csrf import ensure_csrf_cookie import troggle.settings as settings +from troggle.core.models.logbooks import LogbookEntry from troggle.core.models.caves import Cave from troggle.core.models.survex import SurvexFile, SurvexBlock +from troggle.core.models.wallets import Wallet from troggle.core.utils import only_commit """Everything that views survexfiles @@ -303,6 +306,12 @@ def svx(request, survex_file): svxblocks.append(b) print(f"{svxfile=} {svxblocks}") + # collect all the stuff that happens on the same dates as the survex blocks + + dates = set() + for b in svxblocks: + dates.add(b.date) + events = events_on_dates(dates) vmap = { "settings": settings, @@ -322,6 +331,26 @@ def svx(request, survex_file): return render(request, "svxfile.html", vmap) +SameDateEvents = namedtuple('SameDateEvents', ['trips', 'svxfiles', 'wallets']) + +def events_on_dates(dates): + """Returns a dictionary of indexed by date. For each date there is a named tuple of 3 lists: + logbookentries, survexfiles (NB files, not blocks), and wallets. + """ + print(dates) + events = {} + for d in dates: + trips = LogbookEntry.objects.filter(date=d) + + svxfiles = False + + # Wallets needs to get those identified only from JSON too, + # see logbookeentry() in views/logbooks.py + allwallets = Wallet.objects.all() + refwallets = allwallets.filter(survexblock__date=d) + + events[d] = SameDateEvents(trips=trips, svxfiles=svxfiles, wallets=refwallets) + return events # The cavern running function. This is NOT where it is run inside the form! see SvxForm.Process() for that def process(survex_file): |