From 4f2861308a3de6312a00ac405793464d972ab8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Tue, 16 May 2017 14:50:36 +0200 Subject: [PATCH] describe locationgroup choices in editor forms --- src/c3nav/editor/forms.py | 3 +++ src/c3nav/mapdata/models/locations.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/c3nav/editor/forms.py b/src/c3nav/editor/forms.py index 31f1033f..f8aabd24 100644 --- a/src/c3nav/editor/forms.py +++ b/src/c3nav/editor/forms.py @@ -24,6 +24,9 @@ class MapitemFormMixin(ModelForm): if not creating: self.initial['geometry'] = json.dumps(mapping(self.instance.geometry), separators=(',', ':')) + if 'groups' in self.fields: + self.fields['groups'].label_from_instance = lambda obj: obj.title_for_forms + # parse titles self.titles = None if hasattr(self.instance, 'titles'): diff --git a/src/c3nav/mapdata/models/locations.py b/src/c3nav/mapdata/models/locations.py index c1835700..0ff5d8b6 100644 --- a/src/c3nav/mapdata/models/locations.py +++ b/src/c3nav/mapdata/models/locations.py @@ -146,6 +146,24 @@ class LocationGroup(Location, EditorFormMixin, models.Model): result['compiled_area'] = self.compiled_area return result + @property + def title_for_forms(self): + attributes = [] + if self.can_search: + attributes.append(_('search')) + if self.can_describe: + attributes.append(_('describe')) + if self.color: + attributes.append(_('color')) + if not attributes: + attributes.append(_('internal')) + if self.compiled_room: + attributes.append(_('comp. room')) + if self.compiled_area: + attributes.append(_('comp. area')) + return self.title + ' ('+', '.join(str(s) for s in attributes)+')' + + class LocationRedirect(LocationSlug): target = models.ForeignKey(LocationSlug, verbose_name=_('target'), related_name='redirects')