2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

renaming confusing Class, step 1

This commit is contained in:
Philip Sargent 2023-01-30 16:07:44 +00:00
parent 3742e0f367
commit 58f7cf72d4
3 changed files with 19 additions and 21 deletions

View File

@ -104,14 +104,14 @@ class PersonTrip(TroggleModel):
ordering = ('-personexpedition',) ordering = ('-personexpedition',)
#order_with_respect_to = 'personexpedition' #order_with_respect_to = 'personexpedition'
def persontrip_next(self): def next_personlog(self):
futurePTs = PersonTrip.objects.filter(personexpedition = self.personexpedition, logbook_entry__date__gt = self.logbook_entry.date).order_by('logbook_entry__date').all() futurePTs = PersonTrip.objects.filter(personexpedition = self.personexpedition, logbook_entry__date__gt = self.logbook_entry.date).order_by('logbook_entry__date').all()
if len(futurePTs) > 0: if len(futurePTs) > 0:
return futurePTs[0] return futurePTs[0]
else: else:
return None return None
def persontrip_prev(self): def prev_personlog(self):
pastPTs = PersonTrip.objects.filter(personexpedition = self.personexpedition, logbook_entry__date__lt = self.logbook_entry.date).order_by('-logbook_entry__date').all() pastPTs = PersonTrip.objects.filter(personexpedition = self.personexpedition, logbook_entry__date__lt = self.logbook_entry.date).order_by('-logbook_entry__date').all()
if len(pastPTs) > 0: if len(pastPTs) > 0:
return pastPTs[0] return pastPTs[0]

View File

@ -100,12 +100,12 @@ def expedition(request, expeditionname):
dateditems = list(entries) + list(blocks) # evaluates the Django query and hits db dateditems = list(entries) + list(blocks) # evaluates the Django query and hits db
dates = sorted(set([item.date for item in dateditems])) dates = sorted(set([item.date for item in dateditems]))
allpersontrips = PersonTrip.objects.filter(personexpedition__expedition=expo) allpersonlogentries = PersonTrip.objects.filter(personexpedition__expedition=expo)
personexpeditiondays = [ ] personexpeditiondays = [ ]
for personexpedition in expo.personexpedition_set.all(): for personexpedition in expo.personexpedition_set.all():
expotrips = allpersontrips.filter(personexpedition=personexpedition) # lazy expotrips = allpersonlogentries.filter(personexpedition=personexpedition) # lazy
expoblocks = blocks.filter(survexpersonrole__personexpedition=personexpedition) expoblocks = blocks.filter(survexpersonrole__personexpedition=personexpedition)
prow = [ ] prow = [ ]
@ -168,7 +168,7 @@ def get_person_chronology(personexpedition):
res = { } res = { }
for persontrip in personexpedition.persontrip_set.all(): for persontrip in personexpedition.persontrip_set.all():
a = res.setdefault(persontrip.logbook_entry.date, { }) a = res.setdefault(persontrip.logbook_entry.date, { })
a.setdefault("persontrips", [ ]).append(persontrip) a.setdefault("personlogentries", [ ]).append(persontrip)
for personrole in personexpedition.survexpersonrole_set.all(): for personrole in personexpedition.survexpersonrole_set.all():
if personrole.survexblock.date: # avoid bad data from another bug if personrole.survexblock.date: # avoid bad data from another bug
@ -180,10 +180,10 @@ def get_person_chronology(personexpedition):
res2 = [ ] res2 = [ ]
for rdate in rdates: for rdate in rdates:
persontrips = res[rdate].get("persontrips", []) personlogentries = res[rdate].get("personlogentries", [])
personroles = res[rdate].get("personroles", []) personroles = res[rdate].get("personroles", [])
for n in range(max(len(persontrips), len(personroles) )): for n in range(max(len(personlogentries), len(personroles) )):
res2.append(((n == 0 and rdate or "--"), (n < len(persontrips) and persontrips[n]), (n < len(personroles) and personroles[n]) )) res2.append(((n == 0 and rdate or "--"), (n < len(personlogentries) and personlogentries[n]), (n < len(personroles) and personroles[n]) ))
return res2 return res2
@ -227,10 +227,8 @@ def logbookentry(request, date, slug):
# svxothers = None # svxothers = None
svxothers = SurvexBlock.objects.filter(date=date) svxothers = SurvexBlock.objects.filter(date=date)
this_logbookentry=this_logbookentry[0] this_logbookentry=this_logbookentry[0]
# This is the only page that uses presontrip_next and persontrip_prev # This is the only page that uses persontrip_next and persontrip_prev
# and it is calculated on the fly in the model # and it is calculated on the fly in the model
# duration = time.time()-start
# print(f"--- Render after {duration:.2f} seconds")
return render(request, 'logbookentry.html', return render(request, 'logbookentry.html',
{'logbookentry': this_logbookentry, 'trips': trips, 'svxothers': svxothers, 'wallets': wallets}) {'logbookentry': this_logbookentry, 'trips': trips, 'svxothers': svxothers, 'wallets': wallets})
else: else:

View File

@ -29,30 +29,30 @@
<table class="cavers"> <table class="cavers">
<tr><th>Caver</th><th>T/U</th><th>Prev</th><th>Next</th></tr> <tr><th>Caver</th><th>T/U</th><th>Prev</th><th>Next</th></tr>
{% for persontrip in logbookentry.persontrip_set.all %} {% for personlogentry in logbookentry.persontrip_set.all %}
<tr> <tr>
{% if persontrip.is_logbook_entry_author %} {% if personlogentry.is_logbook_entry_author %}
<td class="author"> <td class="author">
{% else %} {% else %}
<td> <td>
{% endif %} {% endif %}
<a href="{{ persontrip.personexpedition.get_absolute_url }}">{{persontrip.personexpedition.person}}</a> <a href="{{ personlogentry.personexpedition.get_absolute_url }}">{{personlogentry.personexpedition.person}}</a>
</td> </td>
<td> <td>
{% if persontrip.timeunderground %} {% if personlogentry.timeunderground %}
- T/U {{persontrip.timeunderground}}</p> - T/U {{personlogentry.timeunderground}}</p>
{% endif %} {% endif %}
</td> </td>
<td> <td>
{% if persontrip.persontrip_prev %} {% if personlogentry.prev_personlog %}
<a href="{{ persontrip.persontrip_prev.logbook_entry.get_absolute_url }}">{{persontrip.persontrip_prev.logbook_entry.date|date:"D d M Y"}}</a> <a href="{{ personlogentry.prev_personlog.logbook_entry.get_absolute_url }}">{{personlogentry.prev_personlog.logbook_entry.date|date:"D d M Y"}}</a>
{% endif %} {% endif %}
</td> </td>
<td> <td>
{% if persontrip.persontrip_next %} {% if personlogentry.next_personlog %}
<a href="{{ persontrip.persontrip_next.logbook_entry.get_absolute_url }}">{{persontrip.persontrip_next.logbook_entry.date|date:"D d M Y"}}</a> <a href="{{ personlogentry.next_personlog.logbook_entry.get_absolute_url }}">{{personlogentry.next_personlog.logbook_entry.date|date:"D d M Y"}}</a>
{% endif %} {% endif %}
</td> </td>
@ -64,7 +64,7 @@
<div id="col1"> <div id="col1">
<div class="logbookentry"> <div class="logbookentry">
<b>{{logbookentry.date|date:"D d M Y"}}</b> <b>{{logbookentry.date|date:"D d M Y"}}</b>
{% for persontrip in logbookentry.persontrip_set.all %}{% if persontrip.is_logbook_entry_author %}<br />{{persontrip.personexpedition.person}}{% endif %}{% endfor %} {% for personlogentry in logbookentry.persontrip_set.all %}{% if personlogentry.is_logbook_entry_author %}<br />{{personlogentry.personexpedition.person}}{% endif %}{% endfor %}
<p>{{logbookentry.text|safe}}</p> <p>{{logbookentry.text|safe}}</p>
</div> </div>
</div> </div>