From c92b68872edbce98025beffc0cafce88da6e8223 Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Fri, 11 Jan 2019 13:43:57 +0100 Subject: [PATCH] Fix radius options, force to set a vlan when adding a policy which requires it. --- preferences/forms.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/preferences/forms.py b/preferences/forms.py index fd052edd..7e644808 100644 --- a/preferences/forms.py +++ b/preferences/forms.py @@ -231,6 +231,27 @@ class EditRadiusOptionForm(ModelForm): model = RadiusOption fields = '__all__' + def clean(self): + cleaned_data = super().clean() + ignored=('radius_general_policy', 'vlan_decision_ok') + fields = ( + f for f in self.fields.keys() + if 'vlan' not in f and f not in ignored + ) + for f in fields: + choice = cleaned_data.get(f) + vlan = cleaned_data.get(f+'_vlan') + if choice == RadiusOption.SET_VLAN and vlan is None: + self.add_error( + f, + _("You chose to set vlan but did not set any VLAN."), + ) + self.add_error( + f+'_vlan', + _("Please, choose a VLAN."), + ) + return cleaned_data + class ServiceForm(ModelForm): """Edition, ajout de services sur la page d'accueil"""