From 73e9ae54faed4135b09ae3f9691b88b3c7abe54c Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 15 Jul 2022 16:17:40 +0300 Subject: [PATCH] cleaner survexdirectory creation --- parsers/survex.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/parsers/survex.py b/parsers/survex.py index 3deef71..8fc7e24 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -12,7 +12,7 @@ from django.utils.timezone import get_current_timezone from django.utils.timezone import make_aware import troggle.settings as settings -from troggle.core.models.caves import Entrance, QM, LogbookEntry +from troggle.core.models.caves import Cave, Entrance, QM, LogbookEntry from troggle.core.utils import get_process_memory, chaosmonkey from troggle.parsers.people import GetPersonExpeditionNameLookup from troggle.parsers.logbooks import GetCaveLookup @@ -1446,9 +1446,14 @@ def FindAndLoadSurvex(survexblockroot): def MakeSurvexFileRoot(): """Returns a file_object.path = SURVEX_TOPNAME associated with directory_object.path = SURVEX_DATA """ + # find a cave, any cave.. + c = Cave.objects.all() + fileroot = SurvexFile(path=settings.SURVEX_TOPNAME, cave=None) fileroot.save() - directoryroot = SurvexDirectory(path=settings.SURVEX_DATA, cave=None, primarysurvexfile=fileroot) + directoryroot = SurvexDirectory(path=settings.SURVEX_DATA, cave=c[0], primarysurvexfile=fileroot) + # MariaDB doesn't like this hack. Complains about non-null cave_id EVEN THOUGH our model file says this is OK: + # cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.SET_NULL) directoryroot.save() fileroot.survexdirectory = directoryroot # i.e. SURVEX_DATA/SURVEX_TOPNAME fileroot.save() # mutually dependent objects need a double-save like this