diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2023-03-06 22:30:36 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2023-03-06 22:30:36 +0000 |
commit | e71939fe00598586de508d26f360a1fe0f51f740 (patch) | |
tree | b9291165768c0cc2f5a0d5717661a821f55f0d05 /core/models/survex.py | |
parent | 859a28b4eeabaa4b98ea1ff9c583d7006db6baa2 (diff) | |
download | troggle-e71939fe00598586de508d26f360a1fe0f51f740.tar.gz troggle-e71939fe00598586de508d26f360a1fe0f51f740.tar.bz2 troggle-e71939fe00598586de508d26f360a1fe0f51f740.zip |
restore lookup() function
Diffstat (limited to 'core/models/survex.py')
-rw-r--r-- | core/models/survex.py | 35 |
1 files 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): |