From 6387de038ba063e96d4cadc26d28fda1c0423720 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 27 Feb 2023 16:42:08 +0000 Subject: [PATCH] get events on same date.progress. --- core/views/scans.py | 2 +- core/views/survex.py | 29 +++++++++++++++++++++++++++++ templates/statistics.html | 3 ++- templates/svxfile.html | 3 ++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/core/views/scans.py b/core/views/scans.py index dae372a..0e49a8c 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -193,7 +193,7 @@ def walletslistyear(request, year): year = str(year) manywallets = ticksyearwallet(year) - expeditions = Expedition.objects.all() + expeditions = Expedition.objects.all() #bad Django style expedition = expeditions.filter(year=year) print("--") return render( 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): diff --git a/templates/statistics.html b/templates/statistics.html index 02a8d5c..67a895d 100644 --- a/templates/statistics.html +++ b/templates/statistics.html @@ -12,7 +12,8 @@ Total length: {{addupsurvexlength|stringformat:".1f"}} km adding up the total fo

These are uncorrected tape lengths which include pitches and duplicates but exclude splays or surface-surveys.

-This is work in progress (April 2022). +This is work in progress (Feb.2023). +

This includes ARGE and other surveys currently. It will be changed to only include lengths surveyed by valid Expo-attendees. diff --git a/templates/svxfile.html b/templates/svxfile.html index 45e0127..7241f09 100644 --- a/templates/svxfile.html +++ b/templates/svxfile.html @@ -82,7 +82,8 @@ LOGMESSAGES {% for sb in svxblocks %} -
{{sb.date|date:"Y-m-d"}} {{sb.title}} '{{sb.name}}' +
+{{sb.date|date:"Y"}}{{sb.date|date:"-m-d"}} {{sb.title}} '{{sb.name}}' List of Logbook entries, wallets and other survex files on {{sb.date|date:"Y-m-d"}}.
[Work in progress, Feb. 2023...]
YearSurvex
Survey
Blocks
Survex
Survey Legs
Total length
(m)