From 89d0e1723ec57c5472eb1073fc1af5bb587bb7dc Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 29 Jan 2023 21:45:51 +0000 Subject: [PATCH] fixing cyclic import problem --- core/TESTS/test_imports.py | 4 ++-- core/models/caves.py | 6 ++---- core/models/logbooks.py | 7 ++++++- core/views/caves.py | 4 ++-- core/views/logbooks.py | 15 ++++++++------- core/views/uploads.py | 5 +---- parsers/caves.py | 3 ++- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/core/TESTS/test_imports.py b/core/TESTS/test_imports.py index bc0c3ee..a4a4cfb 100644 --- a/core/TESTS/test_imports.py +++ b/core/TESTS/test_imports.py @@ -62,7 +62,7 @@ class SimpleTest(SimpleTestCase): from django.utils.timezone import get_current_timezone, make_aware from parsers.people import GetPersonExpeditionNameLookup - from troggle.core.models.logbooks import LogbookEntry, PersonTrip + from troggle.core.models.logbooks import CaveSlug, QM, LogbookEntry, PersonTrip from troggle.core.models.troggle import DataIssue, Expedition def test_import_core_views_caves(self): from django.conf import settings @@ -74,7 +74,7 @@ class SimpleTest(SimpleTestCase): from troggle.core.forms import (CaveAndEntranceFormSet, CaveForm, EntranceForm, EntranceLetterForm) from troggle.core.models.caves import (Area, Cave, CaveAndEntrance, - CaveSlug, Entrance, + Entrance, EntranceSlug, SurvexStation) from troggle.core.models.troggle import Expedition from troggle.core.views.auth import login_required_if_public diff --git a/core/models/caves.py b/core/models/caves.py index af215a7..b99140b 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -74,10 +74,7 @@ class CaveAndEntrance(models.Model): def __str__(self): return str(self.cave) + str(self.entrance_letter) -class CaveSlug(models.Model): - cave = models.ForeignKey('Cave',on_delete=models.CASCADE) - slug = models.SlugField(max_length=50, unique = True) - primary = models.BooleanField(default=False) + class Cave(TroggleModel): # too much here perhaps, @@ -164,6 +161,7 @@ class Cave(TroggleModel): def get_QMs(self): '''Searches for all QMs that reference this cave. ''' + #qms = self.qm_set.all().order_by('expoyear', 'block__date') qms = QM.objects.filter(cave=self).order_by('expoyear', 'block__date') # a QuerySet, see https://docs.djangoproject.com/en/4.0/ref/models/querysets/#order-by return qms # a QuerySet diff --git a/core/models/logbooks.py b/core/models/logbooks.py index b7aa5e3..9903db5 100644 --- a/core/models/logbooks.py +++ b/core/models/logbooks.py @@ -21,7 +21,7 @@ from django.template import Context, loader from django.urls import reverse import settings -#from troggle.core.models.caves import CaveSlug +#from troggle.core.models.qm import CaveSlug from troggle.core.models.survex import SurvexStation from troggle.core.models.troggle import (DataIssue, Expedition, Person, PersonExpedition, TroggleModel) @@ -113,6 +113,11 @@ class PersonTrip(TroggleModel): def __str__(self): return f'{self.personexpedition} ({self.logbook_entry.date})' +class CaveSlug(models.Model): + cave = models.ForeignKey('Cave',on_delete=models.CASCADE) + slug = models.SlugField(max_length=50, unique = True) + primary = models.BooleanField(default=False) + class QM(TroggleModel): """This is based on qm.csv in trunk/expoweb/1623/204 which has the fields: "Number","Grade","Area","Description","Page reference","Nearest station","Completion description","Comment" diff --git a/core/views/caves.py b/core/views/caves.py index b7b800a..df85579 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -18,9 +18,9 @@ import troggle.settings as settings from troggle.core.forms import (CaveAndEntranceFormSet, CaveForm, EntranceForm, EntranceLetterForm) from troggle.core.models.caves import (Area, Cave, CaveAndEntrance, - CaveSlug, Entrance, EntranceSlug, + Entrance, EntranceSlug, GetCaveLookup, SurvexStation) -from troggle.core.models.logbooks import QM +from troggle.core.models.logbooks import CaveSlug, QM from troggle.core.models.troggle import DataIssue, Expedition from troggle.core.utils import write_and_commit, writetrogglefile from troggle.core.views import expo diff --git a/core/views/logbooks.py b/core/views/logbooks.py index c1ba965..a0a2efe 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -17,6 +17,7 @@ import troggle.settings as settings from troggle.core.models.logbooks import LogbookEntry, PersonTrip from troggle.core.models.survex import SurvexBlock from troggle.core.models.troggle import Expedition, Person, PersonExpedition +from troggle.core.models.wallets import Wallet from troggle.core.utils import TROG from troggle.parsers.imports import import_logbook from troggle.parsers.people import GetPersonExpeditionNameLookup @@ -206,13 +207,13 @@ def logbookentry(request, date, slug): jwallets = allwallets.filter(walletdate=date) for j in jwallets: wallets.add(j) - thisexpo = this_expedition = Expedition.objects.get(year=int(date[0:4])) - if thisexpo: - expeditionday = thisexpo.get_expedition_day(date) - svxothers = SurvexBlock.objects.filter(expeditionday=expeditionday) - else: - svxothers = None - + # thisexpo = Expedition.objects.get(year=int(date[0:4])) + # if thisexpo: + # #expeditionday = thisexpo.get_expedition_day(date) + # svxothers = SurvexBlock.objects.filter(date=date) + # else: + # svxothers = None + svxothers = SurvexBlock.objects.filter(date=date) this_logbookentry=this_logbookentry[0] # This is the only page that uses presontrip_next and persontrip_prev # and it is calculated on the fly in the model diff --git a/core/views/uploads.py b/core/views/uploads.py index cceafc9..63f6de3 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -655,10 +655,7 @@ def scanupload(request, path=None): thisexpo = Expedition.objects.get(year=int(year)) if samedate: - expeditionday = thisexpo.get_expedition_day(samedate) - #print(f' - {thisexpo=} {expeditionday=}') - svxothers = SurvexBlock.objects.filter(expeditionday=expeditionday) - #print(f' - {thisexpo=} {expeditionday=} {svxothers=}') + svxothers = SurvexBlock.objects.filter(date=samedate) trips = LogbookEntry.objects.filter(date=samedate) else: svxothers = None diff --git a/parsers/caves.py b/parsers/caves.py index f7f16b3..b2a6e54 100644 --- a/parsers/caves.py +++ b/parsers/caves.py @@ -5,7 +5,8 @@ from pathlib import Path from django.conf import settings from django.db import transaction -from troggle.core.models.caves import Area, Cave, CaveAndEntrance, CaveSlug, Entrance, EntranceSlug, GetCaveLookup +from troggle.core.models.caves import Area, Cave, CaveAndEntrance, Entrance, EntranceSlug, GetCaveLookup +from troggle.core.models.logbooks import CaveSlug from troggle.core.models.troggle import DataIssue from troggle.settings import CAVEDESCRIPTIONS, ENTRANCEDESCRIPTIONS, EXPOWEB, SURVEX_DATA