diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-05-09 16:16:20 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-12 08:44:18 +0200 |
commit | caf2b22574186edd08891eca8bec7971abab8c07 (patch) | |
tree | da54bcbaf7fb2c6009cce587fed610d4d12c6e18 /ishtar_common/forms_common.py | |
parent | 3fa05261531e768630aefff507b4ab29f9a96083 (diff) | |
download | Ishtar-caf2b22574186edd08891eca8bec7971abab8c07.tar.bz2 Ishtar-caf2b22574186edd08891eca8bec7971abab8c07.zip |
Only one main image is possible (refs #4076)
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r-- | ishtar_common/forms_common.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 49054ebac..9e082bccf 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1121,3 +1121,21 @@ class BaseImageForm(ManageOldType): if not data: return 0 return len(get_data_from_formset(data)) + + +class BaseImageFormset(FormSet): + def clean(self): + """ + Verify that no two images are main image + """ + if any(self.errors): + return + have_main = False + for form in self.forms: + is_main = form.cleaned_data.get('is_main', False) + if not is_main: + continue + if is_main and have_main: + raise forms.ValidationError(_(u"Only one image can be a main " + u"image")) + have_main = True
\ No newline at end of file |