comparison pylons_app/model/forms.py @ 475:9dd38344c466 celery

Added validation for uniq email address
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 13 Sep 2010 01:38:14 +0200
parents a3d9d24acbec
children 460ad816820d
comparison
equal deleted inserted replaced
474:a3d9d24acbec 475:9dd38344c466
207 msg = _('You need to specify * or ** at the end of path (ie. /tmp/*)') 207 msg = _('You need to specify * or ** at the end of path (ie. /tmp/*)')
208 208
209 raise formencode.Invalid(msg, value, state, 209 raise formencode.Invalid(msg, value, state,
210 error_dict={'paths_root_path':msg}) 210 error_dict={'paths_root_path':msg})
211 211
212 class UniqSystemEmail(formencode.validators.FancyValidator):
213 def to_python(self, value, state):
214 sa = meta.Session
215 try:
216 user = sa.query(User).filter(User.email == value).scalar()
217 if user:
218 raise formencode.Invalid(_("That e-mail address is already taken") ,
219 value, state)
220 finally:
221 meta.Session.remove()
222
223 return value
224
212 class ValidSystemEmail(formencode.validators.FancyValidator): 225 class ValidSystemEmail(formencode.validators.FancyValidator):
213 def to_python(self, value, state): 226 def to_python(self, value, state):
214 sa = meta.Session 227 sa = meta.Session
215 try: 228 try:
216 user = sa.query(User).filter(User.email == value).scalar() 229 user = sa.query(User).filter(User.email == value).scalar()
261 else: 274 else:
262 password = All(UnicodeString(strip=True, min=8, not_empty=True), ValidPassword) 275 password = All(UnicodeString(strip=True, min=8, not_empty=True), ValidPassword)
263 active = StringBoolean(if_missing=False) 276 active = StringBoolean(if_missing=False)
264 name = UnicodeString(strip=True, min=3, not_empty=True) 277 name = UnicodeString(strip=True, min=3, not_empty=True)
265 lastname = UnicodeString(strip=True, min=3, not_empty=True) 278 lastname = UnicodeString(strip=True, min=3, not_empty=True)
266 email = Email(not_empty=True) 279 email = All(Email(not_empty=True), UniqSystemEmail())
267 280
268 return _UserForm 281 return _UserForm
269 282
270 RegisterForm = UserForm 283 RegisterForm = UserForm
271 284