Login

Snippets by garywilson

Snippet List

use oldforms validators in newforms forms

Using the `run_oldforms_validators` function, you can run oldforms validators in your newforms `clean_XXX` methods. Usage example: class PasswordForm(forms.Form): password = forms.CharField(widget=forms.PasswordInput()) def clean_password(self): validator_list = [ isStrongPassword, isValidLength, SomeValidators( num_required=3, validator_list=[hasLower, hasUpper, hasNumeric, hasSpecial], error_message="Password must contain at least 3 of: lowercase, uppercase, numeric, and/or special characters." ) ] run_oldforms_validators('password', self, validator_list) return self.clean_data['password'] Above, `isStrongPassword`, `isValidLength`, etc. are oldforms validators. If you are interested in seeing the implementation of `isStrongPassword`, please see my [Using CrackLib to require stronger passwords](http://gdub.wordpress.com/2006/08/26/using-cracklib-to-require-stronger-passwords/) blog post.

  • newforms
  • validators
  • oldforms
Read More

garywilson has posted 1 snippet.