diff --git a/parsers/survex.py b/parsers/survex.py index 69fd8cf..ffced3d 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -2652,10 +2652,20 @@ def parse_one_file(fpath): # --------------------------------------in progress-- """ cave = find_cave_from_path(svxpath) if cave: - cave_svxpath = cave.survex_file[:-4] # remove .svx - fileroot = SurvexFile.objects.get(path=cave_svxpath) - print(f" - Setting the root survexfile for this import: {svxpath} to be that for cave {cave}") + if cave.survex_file: # i.e. cave has been fully created and has a value for this + cave_svxpath = cave.survex_file[:-4] # remove .svx + else: + cave.survex_file = svxpath + ".svx" + save(cave) + cave_svxpath = svxpath + try: + fileroot = SurvexFile.objects.get(path=cave_svxpath) + except: + fileroot = SurvexFile.objects.create(path=cave_svxpath, cave=cave) + print(f" !! - No SurvexFile object found for {svxpath=}, making a new one..") + print(f" - Setting the root survexfile for this import: {svxpath} to be that for cave {cave} {cave.survex_file=}") return fileroot + # make a dummy SurvexFile object, which will be removed later dummyroot = SurvexFile(path=svxpath)