From cc9f425fb5fa82ac26db4f14c4c484fb7fd85cf6 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Tue, 5 Sep 2023 23:14:48 +0300 Subject: [PATCH] Ongoing work to remove SurvexDirectory as a concept --- core/models/survex.py | 2 +- core/views/survex.py | 19 +++++++++++++------ parsers/survex.py | 22 ++++++++++++---------- templates/survexdir.html | 20 +++++++++++++++----- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/core/models/survex.py b/core/models/survex.py index 7c0f38e..835d31d 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -17,7 +17,7 @@ class SurvexDirectory(models.Model): all relate to the same Cave """ path = models.CharField(max_length=200) - cave = models.ForeignKey("Cave", blank=True, null=True, on_delete=models.SET_NULL) + # cave = models.ForeignKey("Cave", blank=True, null=True, on_delete=models.SET_NULL) # apparently NEVER USED primarysurvexfile = models.ForeignKey( "SurvexFile", related_name="primarysurvexfile", blank=True, null=True, on_delete=models.SET_NULL ) diff --git a/core/views/survex.py b/core/views/survex.py index 7ac206a..bd9df25 100644 --- a/core/views/survex.py +++ b/core/views/survex.py @@ -645,23 +645,30 @@ def survexcaveslist(request): def survexdir(request): """report on all the SurvexDirectory objects We are trying to find out how mismatches have crept in. + and whether the whole SUrvexDirectory class is actually redundant + as the info it holds is always embedded in the survexFile path directories """ - sds = SurvexDirectory.objects.all().order_by("cave") + sds = SurvexDirectory.objects.all() #.order_by("cave") for sd in sds: sd.primarybad = True if f"{sd.primarysurvexfile}".startswith(str(sd.path)): sd.primarybad = False - sd.cavebad = True - munge = f"caves-{sd.cave}".lower() - if str(sd.path).lower().replace("/","-").startswith(munge): - sd.cavebad = False + # sd.cavebad = True + # munge = f"caves-{sd.cave}".lower() + # if str(sd.path).lower().replace("/","-").startswith(munge): + # sd.cavebad = False sd.pathbad = True if Path(settings.SURVEX_DATA, f"{sd.primarysurvexfile}.svx").is_file(): sd.pathbad = False - return render(request, "survexdir.html", {"survexdirs": sds}) + + survexfiles = SurvexFile.objects.all().order_by("cave") + # for f in survexfiles: + # if f.cave: + # print(f, f.cave) + return render(request, "survexdir.html", {"survexdirs": sds, "survexfiles": survexfiles}) def survexcavesingle(request, survex_cave): diff --git a/parsers/survex.py b/parsers/survex.py index 52ecc70..a5a9959 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -1293,7 +1293,7 @@ class LoadingSurvex: #try again cave = IdentifyCave(headpath) if cave: - newdirectory.cave = cave + # newdirectory.cave = cave # turns uout to be never used newfile.cave = cave # print(f"\n - New directory '{newdirectory}' for cave '{cave}'",file=sys.stderr) @@ -2351,7 +2351,8 @@ def display_contents(blocks): sfs = SurvexFile.objects.filter(survexblock=b) for sf in sfs: print(f" SF {sf}") - print(f" SD {sf.survexdirectory} {sf.survexdirectory.cave}") + # print(f" SD {sf.survexdirectory} {sf.survexdirectory.cave}") + print(f" SD {sf.survexdirectory} {sf.survexdirectory.path}") ws = Wallet.objects.filter(survexblock=b) for w in ws: @@ -2499,7 +2500,8 @@ def MakeSurvexFileRoot(): fileroot = SurvexFile(path=settings.SURVEX_TOPNAME, cave=None) fileroot.save() - directoryroot = SurvexDirectory(path=settings.SURVEX_DATA, cave=smk[0], primarysurvexfile=fileroot) + #directoryroot = SurvexDirectory(path=settings.SURVEX_DATA, cave=smk[0], primarysurvexfile=fileroot) + directoryroot = SurvexDirectory(path=settings.SURVEX_DATA, 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() @@ -2526,13 +2528,13 @@ def MakeFileRoot(fn): fileroot.survexdirectory = None - if cave: - # But setting the SurvexDirectory does work ! - # The fluffy stuff is because of errors in the original setting of survex directories - # which needs to be cleaned up.. - for sd in cave.survexdirectory_set.filter(cave=cave): - if f"{sd.primarysurvexfile}".replace("caves-","").startswith(f"{sd.cave}"[:4]): - fileroot.survexdirectory = sd + # if cave: + # # But setting the SurvexDirectory does work ! + # # The fluffy stuff is because of errors in the original setting of survex directories + # # which needs to be cleaned up.. + # for sd in cave.survexdirectory_set.filter(cave=cave): + # if f"{sd.primarysurvexfile}".replace("caves-","").startswith(f"{sd.cave}"[:4]): + # fileroot.survexdirectory = sd fileroot.save() fileroot.cave = cave print(f" - new fileroot {type(fileroot)} for {fn} with cave {cave} - {fileroot}") diff --git a/templates/survexdir.html b/templates/survexdir.html index 7600077..f0cbf11 100644 --- a/templates/survexdir.html +++ b/templates/survexdir.html @@ -7,16 +7,26 @@

SurvexDirectory objects

{% endautoescape %} - +

All SurvexDirectories

- + {% for sd in survexdirs %} - - - + {% endfor %}
CaveCaveIDPathPrimary
Dir PathPrimary svx
{{sd.cave}}{{sd.cave.id}}
{{sd.path}} {{sd.primarysurvexfile}}.svx MISMATCH {% endif %}
+

+

All SurvexFiles

+ + +{% for f in survexfiles %} + + + + + +{% endfor %} +
CaveDir Pathsvx
{{f.cave}}{{f.survexdirectory.path}}{{f.path}}.svx
{% endblock %}