From e71939fe00598586de508d26f360a1fe0f51f740 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 6 Mar 2023 22:30:36 +0000 Subject: [PATCH] restore lookup() function --- core/models/survex.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/core/models/survex.py b/core/models/survex.py index b82bd90..6c63034 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -69,7 +69,7 @@ class SurvexFile(models.Model): class SurvexStationLookUpManager(models.Manager): - """Don't know what this does, + """what this does, https://docs.djangoproject.com/en/dev/topics/db/managers/ This changes the .objects thinggy to use a case-insensitive match name__iexact so that now SurvexStation.objects.lookup() works as a case-insensitive match @@ -104,26 +104,27 @@ class SurvexStation(models.Model): def __str__(self): return self.name and str(self.name) or "no name" - # # Single SurvexBlock # -# class SurvexBlockLookUpManager(models.Manager): - # """Don't know what this does, - # https://docs.djangoproject.com/en/dev/topics/db/managers/ +class SurvexBlockLookUpManager(models.Manager): + """what this does, + https://docs.djangoproject.com/en/dev/topics/db/managers/ - # This changes the .objects_set thinggy to use a case-insensitive match name__iexact - # so that now SurvexBlock.objects.lookup() works as a case-insensitive match UNUSED - # """ - # def lookup(self, name): - # if name == "": - # blocknames = [] - # else: - # blocknames = name.split(".") - # # block = SurvexBlock.objects.get(parent=None, survexfile__path=settings.SURVEX_TOPNAME) - # for blockname in blocknames: - # block = SurvexBlock.objects.get(parent=block, name__iexact=blockname) - # return block + This adds a method to the .objects thinggy to use a case-insensitive match name__iexact + so that now SurvexBlock.objects.lookup() works as a case-insensitive match. + This is used in lookup() in SurvexStationLookUpManager() + which is used in Entrance().other_location() which is used in the Cave webpage + """ + def lookup(self, name): + if name == "": + blocknames = [] + else: + blocknames = name.split(".") + # block = SurvexBlock.objects.get(parent=None, survexfile__path=settings.SURVEX_TOPNAME) + for blockname in blocknames: + block = SurvexBlock.objects.get(parent=block, name__iexact=blockname) + return block class SurvexBlock(models.Model):