From 2c469718f60a11c0038ec15fb186eac275509b8b Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 19 Jun 2020 00:26:15 +0100 Subject: [PATCH] caves, scans, survex work in databaseRest --- parsers/survex.py | 15 +++++++++++++-- utils.py | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/parsers/survex.py b/parsers/survex.py index 508ab26..aebcd31 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -25,6 +25,8 @@ rx_line_length = re.compile(r"[\d\-+.]+$") survexlegsalllength = 0.0 survexlegsnumber = 0 survexblockroot = None +ROOTBLOCK = "rootblock" + def LoadSurvexLineLeg(survexblock, stardata, sline, comment, cave): global survexlegsalllength @@ -460,7 +462,7 @@ def LoadAllSurvexBlocks(): #Load all # this is the first so id=1 - survexblockroot = models_survex.SurvexBlock(name="rootblock", survexpath="", cave=None, survexfile=survexfile, + survexblockroot = models_survex.SurvexBlock(name=ROOTBLOCK, survexpath="", cave=None, survexfile=survexfile, legsall=0, legssplay=0, legssurfc=0, totalleglength=0.0) survexblockroot.save() fin = survexfile.OpenFile() @@ -556,7 +558,16 @@ def LoadPos(): posfile = open("%s.pos" % (topdata)) posfile.readline() #Drop header - survexblockroot = models_survex.SurvexBlock.objects.get(id=1) + try: + survexblockroot = models_survex.SurvexBlock.objects.get(name=ROOTBLOCK) + except: + try: + survexblockroot = models_survex.SurvexBlock.objects.get(id=1) + except: + message = ' ! FAILED to find root SurvexBlock' + print(message) + models.DataIssue.objects.create(parser='survex', message=message) + raise for line in posfile.readlines(): r = poslineregex.match(line) if r: diff --git a/utils.py b/utils.py index 4fc14e9..329efe5 100644 --- a/utils.py +++ b/utils.py @@ -45,6 +45,7 @@ def save_carefully(objectType, lookupAttribs={}, nonLookupAttribs={}): defined in core.models.TroggleModel. """ + print(" !! - SAVE CAREFULLY Django 1.11.29 ", objectType) instance, created = objectType.objects.get_or_create(defaults=nonLookupAttribs, **lookupAttribs) if not created and not instance.new_since_parsing: