summaryrefslogtreecommitdiff
path: root/chimere/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-05-26 17:24:35 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-05-26 17:24:35 +0200
commit1af69d67f354b62cafdd49b9b4d4453c6b5354b1 (patch)
tree348340661a466900161376d81300eb0500848102 /chimere/forms.py
parent58c181b8792466834512c85f8f19b8daf1d79c2d (diff)
downloadChimère-1af69d67f354b62cafdd49b9b4d4453c6b5354b1.tar.bz2
Chimère-1af69d67f354b62cafdd49b9b4d4453c6b5354b1.zip
Forms: do not choose between categories if only one is available
Diffstat (limited to 'chimere/forms.py')
-rw-r--r--chimere/forms.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/chimere/forms.py b/chimere/forms.py
index 580fb09..74b7aa0 100644
--- a/chimere/forms.py
+++ b/chimere/forms.py
@@ -296,6 +296,15 @@ class MarkerAdminFormBase(forms.ModelForm):
self.fields['categories'].choices = subcategories
elif hasattr(self, 'categories_choices'):
self.fields['categories'].choices = self.categories_choices
+ # auto select if there is only one category
+ self.fields['categories'].label = ""
+ if (len(self.fields['categories'].choices) == 1):
+ self.fields['categories'].widget = forms.MultipleHiddenInput()
+ choices = self.fields['categories'].choices
+ self.fields['categories'].label = u"{} / {}".format(
+ choices[0][0], choices[0][1][0][1])
+ self.fields['categories'].initial = \
+ [self.fields['categories'].choices[0][1][0][0]]
if not settings.CHIMERE_SEARCH_ENGINE and 'keywords' in self.fields:
self.fields.pop('keywords')
if not settings.CHIMERE_DAYS_BEFORE_EVENT: