all working, queries improved, date-ordered.

This commit is contained in:
2023-02-27 22:23:24 +00:00
parent 154722f765
commit 5c3927c25d
6 changed files with 56 additions and 66 deletions

View File

@@ -1,10 +1,10 @@
from django.db.models import Q
from django.shortcuts import render
from django.views.generic.list import ListView
import troggle.settings as settings
from troggle.core.models.logbooks import LogbookEntry, PersonLogEntry
from troggle.core.models.survex import SurvexBlock
from troggle.core.models.survex import SurvexBlock, SurvexFile
from troggle.core.models.troggle import Expedition, Person
from troggle.core.models.wallets import Wallet
from troggle.core.utils import TROG
@@ -212,22 +212,13 @@ def logbookentry(request, date, slug):
if this_logbookentry:
if len(this_logbookentry) > 1:
# BUG
return render(request, "object_list.html", {"object_list": this_logbookentry})
else:
wallets = set()
allwallets = Wallet.objects.all()
refwallets = allwallets.filter(survexblock__date=date)
for r in refwallets:
wallets.add(r)
# Note that w.year() only works for wallets which have a valid JSON file existing
# This is very slow with a big lag as w.date() is a computed field
# Noticably slow with WSL2 and NTFS filesystem, even with caching as walletdate.
jwallets = allwallets.filter(walletdate=date)
for j in jwallets:
wallets.add(j)
svxothers = SurvexBlock.objects.filter(date=date)
# https://stackoverflow.com/questions/739776/how-do-i-do-an-or-filter-in-a-django-query
wallets = Wallet.objects.filter(Q(survexblock__date=date) | Q(walletdate=date)).distinct()
svxothers = SurvexFile.objects.filter(survexblock__date=date).distinct()
this_logbookentry = this_logbookentry[0]
# This is the only page that uses next_.. and prev_..
# and it is calculated on the fly in the model