diff --git a/core/admin.py b/core/admin.py index 5dfa6a8..1c3718e 100644 --- a/core/admin.py +++ b/core/admin.py @@ -9,7 +9,7 @@ from troggle.core.models.survex import ( SingleScan, SurvexBlock, SurvexFile, - SurvexPersonRole, + SurvexPersonTeam, SurvexStation, ) from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition @@ -38,7 +38,7 @@ class TroggleModelAdmin(admin.ModelAdmin): # class RoleInline(admin.TabularInline): - # model = SurvexPersonRole + # model = SurvexPersonTeam # extra = 4 @@ -118,7 +118,7 @@ admin.site.register(Entrance, EntranceAdmin) admin.site.register(DrawingFile, DrawingFileAdmin) admin.site.register(Expedition) admin.site.register(Person, PersonAdmin) -admin.site.register(SurvexPersonRole) +admin.site.register(SurvexPersonTeam) admin.site.register(SurvexFile, SurvexFileAdmin) admin.site.register(SurvexBlock, SurvexBlockAdmin) admin.site.register(SurvexStation, SurvexStationAdmin) diff --git a/core/models/survex.py b/core/models/survex.py index 47e0ef5..4c1d8d7 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -280,8 +280,8 @@ class SurvexBlock(models.Model): return index -class SurvexPersonRole(models.Model): - """The CASCADE means that if a SurvexBlock or a Person is deleted, then the SurvexPersonRole +class SurvexPersonTeam(models.Model): + """The CASCADE means that if a SurvexBlock or a Person is deleted, then the SurvexPersonTeam is deleted too """ survexblock = models.ForeignKey("SurvexBlock", on_delete=models.CASCADE, db_index=True) diff --git a/core/models/troggle.py b/core/models/troggle.py index 1aaa753..b0cd344 100644 --- a/core/models/troggle.py +++ b/core/models/troggle.py @@ -205,5 +205,5 @@ class PersonExpedition(TroggleModel): def surveyedleglength(self): """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)]) diff --git a/core/views/logbooks.py b/core/views/logbooks.py index e6802d1..3a79428 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -127,7 +127,7 @@ def expedition(request, expeditionname): personexpodays = [] for personexpedition in expo.personexpedition_set.all().prefetch_related('person'): expotrips = allpersonlogentries.filter(personexpedition=personexpedition) # lazy - expoblocks = blocks.filter(survexpersonrole__personexpedition=personexpedition) + expoblocks = blocks.filter(survexpersonteam__personexpedition=personexpedition) prow = [] @@ -204,7 +204,7 @@ def get_person_chronology(personexpedition): a = res.setdefault(personlogentry.logbook_entry.date, {}) 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 a = res.setdefault(personrole.survexblock.date, {}) a.setdefault("personroles", []).append(personrole.survexblock) diff --git a/core/views/scans.py b/core/views/scans.py index 225f18e..a885db6 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -8,7 +8,7 @@ from django.http import HttpResponse from django.shortcuts import render 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.wallets import Wallet from troggle.core.utils import DatabaseResetOngoing, current_expo @@ -198,7 +198,7 @@ def walletslistperson(request, slug): manywallets = set() # 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: w = sp.survexblock.scanswallet if w: diff --git a/core/views/statistics.py b/core/views/statistics.py index ec228b4..119bde6 100644 --- a/core/views/statistics.py +++ b/core/views/statistics.py @@ -7,7 +7,7 @@ from django.shortcuts import render import troggle.settings as settings from troggle.core.models.caves import Cave, Entrance 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.wallets import Wallet from troggle.core.utils import current_expo @@ -72,7 +72,7 @@ def legs_and_lengths(expos): # print(f" WILD {sb.survexfile} {sb.date}") wildlength += sb.legslength sb.year = f"{expedition}" - people = SurvexPersonRole.objects.filter(survexblock=sb) + people = SurvexPersonTeam.objects.filter(survexblock=sb) team = [] for p in people: team.append(p.personname) diff --git a/core/views/wallets_edit.py b/core/views/wallets_edit.py index 4fad419..deba0d3 100644 --- a/core/views/wallets_edit.py +++ b/core/views/wallets_edit.py @@ -16,7 +16,7 @@ from django.shortcuts import render import settings from troggle.core.models.caves import Cave 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.wallets import YEAR_RANGE, Wallet, make_valid_date from troggle.core.utils import ( @@ -575,7 +575,7 @@ def walletedit(request, path=None): blocknames.append(str(b.name) + "|" + str(b.title)) else: blocknames.append(str(b.name)) - QSpeople = SurvexPersonRole.objects.filter(survexblock=b) + QSpeople = SurvexPersonTeam.objects.filter(survexblock=b) # print(f" - - {QSpeople=}") for p in QSpeople: # print(f" - - {p.personname} ") diff --git a/parsers/locations.py b/parsers/locations.py index 083a5da..81cb083 100644 --- a/parsers/locations.py +++ b/parsers/locations.py @@ -10,7 +10,7 @@ from pathlib import Path import troggle.settings as settings from troggle.core.models.caves import Cave, Entrance 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.wallets import Wallet from troggle.core.utils import chaosmonkey, get_process_memory diff --git a/parsers/survex.py b/parsers/survex.py index 2ea0cbb..1af6c2a 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -17,7 +17,7 @@ from django.db import transaction import troggle.settings as settings from troggle.core.models.caves import Cave, Entrance, GetCaveLookup 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.wallets import Wallet from troggle.core.utils import chaosmonkey, get_process_memory @@ -84,7 +84,7 @@ dataissues = set() # Caches for ORM minimization survexblock_cache = None # {scanswallet_id: [SurvexBlock, ...]} -personrole_cache = None # {survexblock._blockid: [SurvexPersonRole, ...]} +personrole_cache = None # {survexblock._blockid: [SurvexPersonTeam, ...]} wallet_cache = None # {walletname: [Wallet, ...]} 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 if personrole_cache is None: - # Build cache: {survexblock._blockid: [SurvexPersonRole, ...]} + # Build cache: {survexblock._blockid: [SurvexPersonTeam, ...]} 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: personrole_cache[pr.survexblock._blockid] = [] personrole_cache[pr.survexblock._blockid].append(pr) @@ -668,12 +668,12 @@ class LoadingSurvex: # pr_save_mysql() # return try: - SurvexPersonRole.objects.bulk_create(valid_list, + SurvexPersonTeam.objects.bulk_create(valid_list, update_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: message = f"\n ! - EXCEPTION '{e}' - in PR bulk update. Falling back onto sequential updates method" print(message) @@ -690,7 +690,7 @@ class LoadingSurvex: continue # Not using on MariaDB yet: tricky to get foreign keys working # 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, personname=pr.personname, person=pr.person, @@ -705,12 +705,12 @@ class LoadingSurvex: got_obj.survexblock = pr.survexblock got_obj.save() 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 = [] for blk in self._pending_pr_saves: 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 valid_list = [] @@ -725,7 +725,7 @@ class LoadingSurvex: parser="survex", 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': pr_save_mysql() else: @@ -823,12 +823,12 @@ class LoadingSurvex: def put_personrole_on_trip(self, survexblock, personexpedition, tm): """ 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. """ try: - personrole = SurvexPersonRole( # does not commit to db yet + personrole = SurvexPersonTeam( # does not commit to db yet survexblock=survexblock, # survexblock has no _id yet person = personexpedition.person, personexpedition=personexpedition, @@ -1296,7 +1296,7 @@ class LoadingSurvex: survexblock.expedition = expo 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: 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) @@ -2453,8 +2453,8 @@ class LoadingSurvex: with transaction.atomic(): self.save_personroles_to_db() - n = SurvexPersonRole.objects.all().count() - print(f" + Now {n} SurvexPersonRoles in total", file=sys.stderr) + n = SurvexPersonTeam.objects.all().count() + print(f" + Now {n} SurvexPersonTeams in total", file=sys.stderr) n = QM.objects.all().count() print(f" - {n} QMs already", file=sys.stderr) @@ -3349,7 +3349,7 @@ def survexifywallets(): # Batch add people to wallets to minimize DB hits from collections import defaultdict 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: w = spr.survexblock.scanswallet 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. cuccblocks = set() - sprs = SurvexPersonRole.objects.all() + sprs = SurvexPersonTeam.objects.all() cuccblocks_count = 0 for spr in sprs: cuccblocks.add(spr.survexblock) cuccblocks_count += 1 # 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 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 SurvexBlock.objects.all().delete() SurvexFile.objects.all().delete() - SurvexPersonRole.objects.all().delete() + SurvexPersonTeam.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_keep = QM.objects.filter(loaded_from_csv=True) # the survex QMs, not the CSV QMs diff --git a/templates/person.html b/templates/person.html index 9accb29..c61af9f 100644 --- a/templates/person.html +++ b/templates/person.html @@ -29,8 +29,8 @@ -   - {{personexpedition.survexpersonrole_set.all|length}} +   + {{personexpedition.survexpersonteam_set.all|length}} {% endfor %} diff --git a/templates/svxcaves.html b/templates/svxcaves.html index 7c481b6..1d568c3 100644 --- a/templates/svxcaves.html +++ b/templates/svxcaves.html @@ -74,7 +74,7 @@ to go to a form to correct the online data. - {% for personrole in survexblock.survexpersonrole_set.all %} + {% for personrole in survexblock.survexpersonteam_set.all %} {% if personrole.personexpedition %} {{personrole.personname}} {% else %}