forms.py: Add the dynamic field in __init__

If we add the field like this, we can control its existence in tests.
In other case, since classes are compiled once, even if we set
TERMS_OF_SERVICE to False in tests, terms field would still continue
to exist in the form class.
This commit is contained in:
Umair Khan
2017-06-15 14:35:04 +05:00
committed by Tim Abbott
parent af7e08acb0
commit 2e1ccabb88

View File

@@ -63,8 +63,11 @@ class RegistrationForm(forms.Form):
(Realm.CORPORATE, 'Corporate')),
initial=Realm.COMMUNITY, required=False)
def __init__(self, *args, **kwargs):
# type: (*Any, **Any) -> None
super(RegistrationForm, self).__init__(*args, **kwargs)
if settings.TERMS_OF_SERVICE:
terms = forms.BooleanField(required=True)
self.fields['terms'] = forms.BooleanField(required=True)
def clean_full_name(self):
# type: () -> Text