From 0aec6f8ad9adf32d0ef4fb2975eda2bf9e21b07f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 24 2015 09:22:02 +0000 Subject: Adjust the UserEmailForm form so that it does a first validation This validation prevents an user from trying to add an email they already use --- diff --git a/pagure/forms.py b/pagure/forms.py index ce3847e..9f691b1 100644 --- a/pagure/forms.py +++ b/pagure/forms.py @@ -271,18 +271,15 @@ class UserEmailForm(wtf.Form): 'email', [wtforms.validators.Required()] ) - def __init__(self, emails, *args, **kwargs): - wtf.Form.__init__(self, *args, **kwargs) - self.emails = emails - print self.emails - - def validate(self): - rv = wtf.Form.validate(self) - if not rv: - return False - if self.email.data in self.emails: - self.email.errors.append('the email %s is already associated to you' % self.email.data) - return False + def __init__(self, *args, **kwargs): + super(UserEmailForm, self).__init__(*args, **kwargs) + if 'emails' in kwargs: + if kwargs['emails']: + self.email.validators.append( + wtforms.validators.NoneOf(kwargs['emails']) + ) + else: + self.email.validators = [wtforms.validators.Required()] class ProjectCommentForm(wtf.Form):