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