From 2e1ccabb8840589c7b28034b71a8d5bdadad15a8 Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Thu, 15 Jun 2017 14:35:04 +0500 Subject: [PATCH] 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. --- zerver/forms.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/zerver/forms.py b/zerver/forms.py index 7150655b23..f9692b06f8 100644 --- a/zerver/forms.py +++ b/zerver/forms.py @@ -63,8 +63,11 @@ class RegistrationForm(forms.Form): (Realm.CORPORATE, 'Corporate')), initial=Realm.COMMUNITY, required=False) - if settings.TERMS_OF_SERVICE: - terms = forms.BooleanField(required=True) + def __init__(self, *args, **kwargs): + # type: (*Any, **Any) -> None + super(RegistrationForm, self).__init__(*args, **kwargs) + if settings.TERMS_OF_SERVICE: + self.fields['terms'] = forms.BooleanField(required=True) def clean_full_name(self): # type: () -> Text