2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-02-08 04:27:45 +00:00

SurvexPersonTeam renamed form survexpersonrole

This commit is contained in:
2026-02-01 14:56:31 +00:00
parent c899c0749c
commit fd2f920745
11 changed files with 37 additions and 37 deletions

View File

@@ -9,7 +9,7 @@ from troggle.core.models.survex import (
SingleScan, SingleScan,
SurvexBlock, SurvexBlock,
SurvexFile, SurvexFile,
SurvexPersonRole, SurvexPersonTeam,
SurvexStation, SurvexStation,
) )
from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition
@@ -38,7 +38,7 @@ class TroggleModelAdmin(admin.ModelAdmin):
# class RoleInline(admin.TabularInline): # class RoleInline(admin.TabularInline):
# model = SurvexPersonRole # model = SurvexPersonTeam
# extra = 4 # extra = 4
@@ -118,7 +118,7 @@ admin.site.register(Entrance, EntranceAdmin)
admin.site.register(DrawingFile, DrawingFileAdmin) admin.site.register(DrawingFile, DrawingFileAdmin)
admin.site.register(Expedition) admin.site.register(Expedition)
admin.site.register(Person, PersonAdmin) admin.site.register(Person, PersonAdmin)
admin.site.register(SurvexPersonRole) admin.site.register(SurvexPersonTeam)
admin.site.register(SurvexFile, SurvexFileAdmin) admin.site.register(SurvexFile, SurvexFileAdmin)
admin.site.register(SurvexBlock, SurvexBlockAdmin) admin.site.register(SurvexBlock, SurvexBlockAdmin)
admin.site.register(SurvexStation, SurvexStationAdmin) admin.site.register(SurvexStation, SurvexStationAdmin)

View File

@@ -280,8 +280,8 @@ class SurvexBlock(models.Model):
return index return index
class SurvexPersonRole(models.Model): class SurvexPersonTeam(models.Model):
"""The CASCADE means that if a SurvexBlock or a Person is deleted, then the SurvexPersonRole """The CASCADE means that if a SurvexBlock or a Person is deleted, then the SurvexPersonTeam
is deleted too is deleted too
""" """
survexblock = models.ForeignKey("SurvexBlock", on_delete=models.CASCADE, db_index=True) survexblock = models.ForeignKey("SurvexBlock", on_delete=models.CASCADE, db_index=True)

View File

@@ -205,5 +205,5 @@ class PersonExpedition(TroggleModel):
def surveyedleglength(self): def surveyedleglength(self):
"""Survey length for this person on all survex trips on this expedition""" """Survey length for this person on all survex trips on this expedition"""
survexblocks = [personrole.survexblock for personrole in self.survexpersonrole_set.all()] survexblocks = [personrole.survexblock for personrole in self.survexpersonteam_set.all()]
return sum([survexblock.legslength for survexblock in set(survexblocks)]) return sum([survexblock.legslength for survexblock in set(survexblocks)])

View File

@@ -127,7 +127,7 @@ def expedition(request, expeditionname):
personexpodays = [] personexpodays = []
for personexpedition in expo.personexpedition_set.all().prefetch_related('person'): for personexpedition in expo.personexpedition_set.all().prefetch_related('person'):
expotrips = allpersonlogentries.filter(personexpedition=personexpedition) # lazy expotrips = allpersonlogentries.filter(personexpedition=personexpedition) # lazy
expoblocks = blocks.filter(survexpersonrole__personexpedition=personexpedition) expoblocks = blocks.filter(survexpersonteam__personexpedition=personexpedition)
prow = [] prow = []
@@ -204,7 +204,7 @@ def get_person_chronology(personexpedition):
a = res.setdefault(personlogentry.logbook_entry.date, {}) a = res.setdefault(personlogentry.logbook_entry.date, {})
a.setdefault("personlogentries", []).append(personlogentry) a.setdefault("personlogentries", []).append(personlogentry)
for personrole in personexpedition.survexpersonrole_set.all(): for personrole in personexpedition.survexpersonteam_set.all():
if personrole.survexblock.date: # avoid bad data from another bug if personrole.survexblock.date: # avoid bad data from another bug
a = res.setdefault(personrole.survexblock.date, {}) a = res.setdefault(personrole.survexblock.date, {})
a.setdefault("personroles", []).append(personrole.survexblock) a.setdefault("personroles", []).append(personrole.survexblock)

View File

@@ -8,7 +8,7 @@ from django.http import HttpResponse
from django.shortcuts import render from django.shortcuts import render
from troggle.core.models.caves import GetCaveLookup from troggle.core.models.caves import GetCaveLookup
from troggle.core.models.survex import SingleScan, SurvexBlock, SurvexPersonRole from troggle.core.models.survex import SingleScan, SurvexBlock, SurvexPersonTeam
from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition
from troggle.core.models.wallets import Wallet from troggle.core.models.wallets import Wallet
from troggle.core.utils import DatabaseResetOngoing, current_expo from troggle.core.utils import DatabaseResetOngoing, current_expo
@@ -198,7 +198,7 @@ def walletslistperson(request, slug):
manywallets = set() manywallets = set()
# Get the persons from the survexblocks on the survexfiles attached to the wallet directly # Get the persons from the survexblocks on the survexfiles attached to the wallet directly
sps = SurvexPersonRole.objects.filter(person=p) sps = SurvexPersonTeam.objects.filter(person=p)
for sp in sps: for sp in sps:
w = sp.survexblock.scanswallet w = sp.survexblock.scanswallet
if w: if w:

View File

@@ -7,7 +7,7 @@ from django.shortcuts import render
import troggle.settings as settings import troggle.settings as settings
from troggle.core.models.caves import Cave, Entrance from troggle.core.models.caves import Cave, Entrance
from troggle.core.models.logbooks import LogbookEntry from troggle.core.models.logbooks import LogbookEntry
from troggle.core.models.survex import SurvexPersonRole, SurvexStation from troggle.core.models.survex import SurvexPersonTeam, SurvexStation
from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition
from troggle.core.models.wallets import Wallet from troggle.core.models.wallets import Wallet
from troggle.core.utils import current_expo from troggle.core.utils import current_expo
@@ -72,7 +72,7 @@ def legs_and_lengths(expos):
# print(f" WILD {sb.survexfile} {sb.date}") # print(f" WILD {sb.survexfile} {sb.date}")
wildlength += sb.legslength wildlength += sb.legslength
sb.year = f"{expedition}" sb.year = f"{expedition}"
people = SurvexPersonRole.objects.filter(survexblock=sb) people = SurvexPersonTeam.objects.filter(survexblock=sb)
team = [] team = []
for p in people: for p in people:
team.append(p.personname) team.append(p.personname)

View File

@@ -16,7 +16,7 @@ from django.shortcuts import render
import settings import settings
from troggle.core.models.caves import Cave from troggle.core.models.caves import Cave
from troggle.core.models.logbooks import LogbookEntry # , PersonLogEntry from troggle.core.models.logbooks import LogbookEntry # , PersonLogEntry
from troggle.core.models.survex import SurvexBlock, SurvexFile, SurvexPersonRole, DrawingFile from troggle.core.models.survex import SurvexBlock, SurvexFile, SurvexPersonTeam, DrawingFile
from troggle.core.models.troggle import DataIssue, Expedition, Person from troggle.core.models.troggle import DataIssue, Expedition, Person
from troggle.core.models.wallets import YEAR_RANGE, Wallet, make_valid_date from troggle.core.models.wallets import YEAR_RANGE, Wallet, make_valid_date
from troggle.core.utils import ( from troggle.core.utils import (
@@ -575,7 +575,7 @@ def walletedit(request, path=None):
blocknames.append(str(b.name) + "|" + str(b.title)) blocknames.append(str(b.name) + "|" + str(b.title))
else: else:
blocknames.append(str(b.name)) blocknames.append(str(b.name))
QSpeople = SurvexPersonRole.objects.filter(survexblock=b) QSpeople = SurvexPersonTeam.objects.filter(survexblock=b)
# print(f" - - {QSpeople=}") # print(f" - - {QSpeople=}")
for p in QSpeople: for p in QSpeople:
# print(f" - - {p.personname} ") # print(f" - - {p.personname} ")

View File

@@ -10,7 +10,7 @@ from pathlib import Path
import troggle.settings as settings import troggle.settings as settings
from troggle.core.models.caves import Cave, Entrance from troggle.core.models.caves import Cave, Entrance
from troggle.core.models.logbooks import QM from troggle.core.models.logbooks import QM
from troggle.core.models.survex import SurvexBlock, SurvexFile, SurvexPersonRole, SurvexStation from troggle.core.models.survex import SurvexBlock, SurvexFile, SurvexPersonTeam, SurvexStation
from troggle.core.models.troggle import DataIssue, Expedition from troggle.core.models.troggle import DataIssue, Expedition
from troggle.core.models.wallets import Wallet from troggle.core.models.wallets import Wallet
from troggle.core.utils import chaosmonkey, get_process_memory from troggle.core.utils import chaosmonkey, get_process_memory

View File

@@ -17,7 +17,7 @@ from django.db import transaction
import troggle.settings as settings import troggle.settings as settings
from troggle.core.models.caves import Cave, Entrance, GetCaveLookup from troggle.core.models.caves import Cave, Entrance, GetCaveLookup
from troggle.core.models.logbooks import QM from troggle.core.models.logbooks import QM
from troggle.core.models.survex import SurvexBlock, SurvexFile, SurvexPersonRole, SurvexStation, SurvexFix from troggle.core.models.survex import SurvexBlock, SurvexFile, SurvexPersonTeam, SurvexStation, SurvexFix
from troggle.core.models.troggle import DataIssue, Expedition from troggle.core.models.troggle import DataIssue, Expedition
from troggle.core.models.wallets import Wallet from troggle.core.models.wallets import Wallet
from troggle.core.utils import chaosmonkey, get_process_memory from troggle.core.utils import chaosmonkey, get_process_memory
@@ -84,7 +84,7 @@ dataissues = set()
# Caches for ORM minimization # Caches for ORM minimization
survexblock_cache = None # {scanswallet_id: [SurvexBlock, ...]} survexblock_cache = None # {scanswallet_id: [SurvexBlock, ...]}
personrole_cache = None # {survexblock._blockid: [SurvexPersonRole, ...]} personrole_cache = None # {survexblock._blockid: [SurvexPersonTeam, ...]}
wallet_cache = None # {walletname: [Wallet, ...]} wallet_cache = None # {walletname: [Wallet, ...]}
trip_people_cache = {} # indexed by survexblock._blockid, so never needs cleaning out trip_people_cache = {} # indexed by survexblock._blockid, so never needs cleaning out
@@ -200,9 +200,9 @@ def get_team_on_trip(survexblock):
""" """
global trip_people_cache, personrole_cache global trip_people_cache, personrole_cache
if personrole_cache is None: if personrole_cache is None:
# Build cache: {survexblock._blockid: [SurvexPersonRole, ...]} # Build cache: {survexblock._blockid: [SurvexPersonTeam, ...]}
personrole_cache = {} personrole_cache = {}
for pr in SurvexPersonRole.objects.all().select_related("person", "personexpedition"): # WASTEFUL ! Optimise this for pr in SurvexPersonTeam.objects.all().select_related("person", "personexpedition"): # WASTEFUL ! Optimise this
if pr.survexblock._blockid not in personrole_cache: if pr.survexblock._blockid not in personrole_cache:
personrole_cache[pr.survexblock._blockid] = [] personrole_cache[pr.survexblock._blockid] = []
personrole_cache[pr.survexblock._blockid].append(pr) personrole_cache[pr.survexblock._blockid].append(pr)
@@ -668,12 +668,12 @@ class LoadingSurvex:
# pr_save_mysql() # pr_save_mysql()
# return # return
try: try:
SurvexPersonRole.objects.bulk_create(valid_list, SurvexPersonTeam.objects.bulk_create(valid_list,
update_fields = ['survexblock', 'personname', 'person', update_fields = ['survexblock', 'personname', 'person',
'personexpedition'], 'personexpedition'],
unique_fields = ['survexblock', 'personname', 'person', 'personexpedition'] unique_fields = ['survexblock', 'personname', 'person', 'personexpedition']
) )
print(f" - all {len(valid_list)} SurvexPersonRoles bulk-created to db", file=sys.stderr) print(f" - all {len(valid_list)} SurvexPersonTeams bulk-created to db", file=sys.stderr)
except Exception as e: except Exception as e:
message = f"\n ! - EXCEPTION '{e}' - in PR bulk update. Falling back onto sequential updates method" message = f"\n ! - EXCEPTION '{e}' - in PR bulk update. Falling back onto sequential updates method"
print(message) print(message)
@@ -690,7 +690,7 @@ class LoadingSurvex:
continue continue
# Not using on MariaDB yet: tricky to get foreign keys working # Not using on MariaDB yet: tricky to get foreign keys working
# This is not the complete set of fields we need: # This is not the complete set of fields we need:
got_obj, created = SurvexPersonRole.objects.get_or_create( got_obj, created = SurvexPersonTeam.objects.get_or_create(
survexblock=pr.survexblock, survexblock=pr.survexblock,
personname=pr.personname, personname=pr.personname,
person=pr.person, person=pr.person,
@@ -705,12 +705,12 @@ class LoadingSurvex:
got_obj.survexblock = pr.survexblock got_obj.survexblock = pr.survexblock
got_obj.save() got_obj.save()
stash_data_issue(parser="survex", message=f"PR saved {pr}") stash_data_issue(parser="survex", message=f"PR saved {pr}")
print(f" - {ns}/{nc} SurvexPersonRoles saved/created to db", file=sys.stderr) print(f" - {ns}/{nc} SurvexPersonTeams saved/created to db", file=sys.stderr)
pr_list = [] pr_list = []
for blk in self._pending_pr_saves: for blk in self._pending_pr_saves:
pr_list += self._pending_pr_saves[blk] pr_list += self._pending_pr_saves[blk]
print(f" - Saving {len(pr_list):,} SurvexPersonRoles to db.. ({connection.vendor})", file=sys.stderr) print(f" - Saving {len(pr_list):,} SurvexPersonTeams to db.. ({connection.vendor})", file=sys.stderr)
# Now commit to db # Now commit to db
valid_list = [] valid_list = []
@@ -725,7 +725,7 @@ class LoadingSurvex:
parser="survex", parser="survex",
message=message message=message
) )
print(f" - {len(valid_list)} SurvexPersonRoles in list, saving.. ({connection.vendor})", file=sys.stderr) print(f" - {len(valid_list)} SurvexPersonTeams in list, saving.. ({connection.vendor})", file=sys.stderr)
if connection.vendor == 'mysql': if connection.vendor == 'mysql':
pr_save_mysql() pr_save_mysql()
else: else:
@@ -823,12 +823,12 @@ class LoadingSurvex:
def put_personrole_on_trip(self, survexblock, personexpedition, tm): def put_personrole_on_trip(self, survexblock, personexpedition, tm):
""" """
Only used for a single person. Only used for a single person.
Creates a SurvexPersonRole object, but this is not committed to the database until Creates a SurvexPersonTeam object, but this is not committed to the database until
all the survexblocks have been saved. all the survexblocks have been saved.
""" """
try: try:
personrole = SurvexPersonRole( # does not commit to db yet personrole = SurvexPersonTeam( # does not commit to db yet
survexblock=survexblock, # survexblock has no _id yet survexblock=survexblock, # survexblock has no _id yet
person = personexpedition.person, person = personexpedition.person,
personexpedition=personexpedition, personexpedition=personexpedition,
@@ -1296,7 +1296,7 @@ class LoadingSurvex:
survexblock.expedition = expo survexblock.expedition = expo
team = get_team_on_trip(survexblock) # should be empty, should only be in 'pending' team = get_team_on_trip(survexblock) # should be empty, should only be in 'pending'
# team = SurvexPersonRole.objects.filter(survexblock=survexblock) # team = SurvexPersonTeam.objects.filter(survexblock=survexblock)
if len(team) > 0: if len(team) > 0:
message = f"! *team {expo.year} Multiple *date in one block? Already someone on team when *date seen. {survexblock.survexfile.path} ({survexblock}) in '{line}'" message = f"! *team {expo.year} Multiple *date in one block? Already someone on team when *date seen. {survexblock.survexfile.path} ({survexblock}) in '{line}'"
print(self.insp + message) print(self.insp + message)
@@ -2453,8 +2453,8 @@ class LoadingSurvex:
with transaction.atomic(): with transaction.atomic():
self.save_personroles_to_db() self.save_personroles_to_db()
n = SurvexPersonRole.objects.all().count() n = SurvexPersonTeam.objects.all().count()
print(f" + Now {n} SurvexPersonRoles in total", file=sys.stderr) print(f" + Now {n} SurvexPersonTeams in total", file=sys.stderr)
n = QM.objects.all().count() n = QM.objects.all().count()
print(f" - {n} QMs already", file=sys.stderr) print(f" - {n} QMs already", file=sys.stderr)
@@ -3349,7 +3349,7 @@ def survexifywallets():
# Batch add people to wallets to minimize DB hits # Batch add people to wallets to minimize DB hits
from collections import defaultdict from collections import defaultdict
wallet_to_people = defaultdict(set) wallet_to_people = defaultdict(set)
sprsall = SurvexPersonRole.objects.all().select_related("person").select_related("survexblock") sprsall = SurvexPersonTeam.objects.all().select_related("person").select_related("survexblock")
for spr in sprsall: for spr in sprsall:
w = spr.survexblock.scanswallet w = spr.survexblock.scanswallet
if w and spr.person: if w and spr.person:
@@ -3398,13 +3398,13 @@ def survexifywallets():
# Find the survex blocks which are 'ours' i.e. ignore all those (ARGE etc) without expo people attached. # Find the survex blocks which are 'ours' i.e. ignore all those (ARGE etc) without expo people attached.
cuccblocks = set() cuccblocks = set()
sprs = SurvexPersonRole.objects.all() sprs = SurvexPersonTeam.objects.all()
cuccblocks_count = 0 cuccblocks_count = 0
for spr in sprs: for spr in sprs:
cuccblocks.add(spr.survexblock) cuccblocks.add(spr.survexblock)
cuccblocks_count += 1 cuccblocks_count += 1
# if cuccblocks_count % 1000 == 0: # if cuccblocks_count % 1000 == 0:
# print(f" - Processed {cuccblocks_count} SurvexPersonRole for cuccblocks in {time.time() - start:.2f}s", file=sys.stderr) # print(f" - Processed {cuccblocks_count} SurvexPersonTeam for cuccblocks in {time.time() - start:.2f}s", file=sys.stderr)
# Because we have just run set_survexblocks(w), this should only complain if there is no *ref and no wallet that links to its parent file # Because we have just run set_survexblocks(w), this should only complain if there is no *ref and no wallet that links to its parent file
sentinelbad = Wallet.objects.get(walletname="1983#00") sentinelbad = Wallet.objects.get(walletname="1983#00")
@@ -3445,7 +3445,7 @@ def LoadSurvexBlocks():
# https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.on_delete # https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.on_delete
SurvexBlock.objects.all().delete() SurvexBlock.objects.all().delete()
SurvexFile.objects.all().delete() SurvexFile.objects.all().delete()
SurvexPersonRole.objects.all().delete() SurvexPersonTeam.objects.all().delete()
SurvexStation.objects.all().delete() SurvexStation.objects.all().delete()
qms_to_go = QM.objects.filter(loaded_from_csv=False) # the survex QMs, not the CSV QMs qms_to_go = QM.objects.filter(loaded_from_csv=False) # the survex QMs, not the CSV QMs
qms_to_keep = QM.objects.filter(loaded_from_csv=True) # the survex QMs, not the CSV QMs qms_to_keep = QM.objects.filter(loaded_from_csv=True) # the survex QMs, not the CSV QMs

View File

@@ -29,8 +29,8 @@
</td> </td>
<td> <td>
<span style="padding-left:{{personexpedition.survexpersonrole_set.all|length}}0px; background-color:blue"></span> &nbsp; <span style="padding-left:{{personexpedition.survexpersonteam_set.all|length}}0px; background-color:blue"></span> &nbsp;
{{personexpedition.survexpersonrole_set.all|length}} {{personexpedition.survexpersonteam_set.all|length}}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}

View File

@@ -74,7 +74,7 @@ to go to a form to correct the online data.
</td> </td>
<!-- Explorers --> <!-- Explorers -->
<td> <td>
{% for personrole in survexblock.survexpersonrole_set.all %} {% for personrole in survexblock.survexpersonteam_set.all %}
{% if personrole.personexpedition %} {% if personrole.personexpedition %}
<a href="{{personrole.personexpedition.get_absolute_url}}">{{personrole.personname}}</a> <a href="{{personrole.personexpedition.get_absolute_url}}">{{personrole.personname}}</a>
{% else %} {% else %}