X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/9b7822cca75d3fdd36f5a4cfa858272214621578..a0273ff358d8725b4f137dfa95754c3c43379ecb:/forum/forms/general.py diff --git a/forum/forms/general.py b/forum/forms/general.py index aa4282e..01c528b 100644 --- a/forum/forms/general.py +++ b/forum/forms/general.py @@ -126,6 +126,32 @@ class UserEmailField(forms.EmailField): else: return email +class UserRealNameField(StrippedNonEmptyCharField): + def __init__(self, db_model=User, db_field='real_name', must_exist=True, skip_clean=False, label=_('Your real name'),**kw): + self.must_exist = must_exist + self.skip_clean = skip_clean + self.db_model = db_model + self.db_field = db_field + error_messages={'required':_('Real name is required') + } + if 'error_messages' in kw: + error_messages.update(kw['error_messages']) + del kw['error_messages'] + super(UserRealNameField,self).__init__(max_length=100, + widget=forms.TextInput(attrs=login_form_widget_attrs), + label=label, + error_messages=error_messages, + **kw + ) + + def clean(self, real_name): + if self.skip_clean == True: + return real_name + try: + return super(UserRealNameField, self).clean(real_name) + except forms.ValidationError: + raise forms.ValidationError(self.error_messages['required']) + class SetPasswordForm(forms.Form): password1 = forms.CharField(widget=forms.PasswordInput(attrs=login_form_widget_attrs), label=_('choose password'),