예제 #1
0
파일: expression.py 프로젝트: pegl/examples
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])

예제 #2
0
파일: user.py 프로젝트: pegl/examples
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])