Skip to content

Instantly share code, notes, and snippets.

@j2labs
Created May 16, 2013 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j2labs/5591135 to your computer and use it in GitHub Desktop.
Save j2labs/5591135 to your computer and use it in GitHub Desktop.
Testing the plain-vanilla Schematics branch.
#!/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