Created
May 16, 2013 11:40
-
-
Save j2labs/5591135 to your computer and use it in GitHub Desktop.
Testing the plain-vanilla Schematics branch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import hashlib | |
from schematics.models import Model | |
from schematics.serialize import whitelist, blacklist | |
from schematics.types import MD5Type, StringType | |
from schematics.exceptions import ValidationError | |
class User(Model): | |
secret = MD5Type() | |
name = StringType(required=True, max_length=50) | |
bio = StringType(max_length=100) | |
class Options: | |
roles = { | |
'owner': blacklist(), | |
'public': whitelist('name', 'bio'), | |
} | |
def set_password(self, plaintext): | |
hash_string = hashlib.md5(plaintext).hexdigest() | |
self.secret = hash_string | |
u = User() | |
#u.secret = 'whatevz' | |
u.set_password('whatevz') | |
#u.name = 'this name is going to be much, much, much too long for this field' | |
u.name = 'James' | |
try: | |
u.validate() | |
print ' SUCCESS' | |
except ValidationError, ve: | |
print ' FAILED:', ve | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment