from mongokit import Connection, Document from db import connection def max_length(length): def validate(value): if len(value) <= length: return True raise Exception('%s must be at most %s characters long' % length) return validate class Expression(Document): structure = { 'en': unicode, 'de': unicode, 'fr': unicode, 'pl': unicode } validators = { 'en': max_length(100), 'de': max_length(100), 'fr': max_length(100), 'pl': max_length(100) } use_dot_notation = True def __repr__(self): return '<Expression %r>' % self.value # register the Expression document with our current connection connection.register([Expression])
from flask import Flask from mongokit import Connection, Document from db import connection def max_length(length): def validate(value): if len(value) <= length: return True raise Exception('%s must be at most %s characters long' % length) return validate class User(Document): structure = { 'name': unicode, 'email': unicode } validators = { 'name': max_length(50), 'email': max_length(120) } use_dot_notation = True def __repr__(self): return '<User %r>' % (self.name) # register the User document with our current connection connection.register([User])