2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-21 23:01:52 +00:00

Ongoing work to remove SurvexDirectory as a concept

This commit is contained in:
Philip Sargent 2023-09-05 23:14:48 +03:00
parent 8c721e905a
commit cc9f425fb5
4 changed files with 41 additions and 22 deletions

View File

@ -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
)

View File

@ -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):

View File

@ -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}")

View File

@ -7,16 +7,26 @@
<h1>SurvexDirectory objects</h1>
{% endautoescape %}
<h2>All SurvexDirectories</h2>
<table>
<tr><th>Cave</th><th>CaveID</th><th>Path</th><th>Primary</th></tr>
<tr><th>Dir Path</th><th>Primary svx</th></tr>
{% for sd in survexdirs %}
<tr>
<td><span {% if sd.cavebad %} style="color:red" {% endif %}> {{sd.cave}}</span></td>
<td><em>{{sd.cave.id}}</em></td>
<tr>
<td>{{sd.path}}</td>
<td><a href="/survexfile/{{sd.primarysurvexfile}}"><span {% if sd.pathbad %} style="color:red" {% endif %}>{{sd.primarysurvexfile}}.svx</span></a><span {% if sd.primarybad %} style="color:blue"> <b>MISMATCH</b> {% endif %}</span></td>
</tr>
{% endfor %}
</table>
<p>
<h2>All SurvexFiles</h2>
<table>
<tr><th>Cave</th><th>Dir Path</th><th>svx</th></tr>
{% for f in survexfiles %}
<tr>
<td>{{f.cave}}</td>
<td>{{f.survexdirectory.path}}</td>
<td><a href="/survexfile/{{f.path}}">{{f.path}}.svx</a></td>
</tr>
{% endfor %}
</table>
{% endblock %}