From a8498b6859cbd3a54895ce7a76c6c5ebe76e2aa2 Mon Sep 17 00:00:00 2001 From: Jonathan Como Date: Mon, 15 Dec 2014 13:25:15 -0800 Subject: [PATCH] update mongokit patterng --- docs/patterns/mongokit.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/patterns/mongokit.rst b/docs/patterns/mongokit.rst index 860114bf..7d87221a 100644 --- a/docs/patterns/mongokit.rst +++ b/docs/patterns/mongokit.rst @@ -48,12 +48,13 @@ insert query to the next without any problem. MongoKit is just schemaless too, but implements some validation to ensure data integrity. Here is an example document (put this also into :file:`app.py`, e.g.):: + from mongokit import ValidationError def max_length(length): def validate(value): if len(value) <= length: return True - raise Exception('%s must be at most %s characters long' % length) + raise ValidationError('%s must be at most {0} characters long'.format(length)) return validate class User(Document): @@ -75,7 +76,9 @@ Here is an example document (put this also into :file:`app.py`, e.g.):: This example shows you how to define your schema (named structure), a validator for the maximum character length and uses a special MongoKit feature -called `use_dot_notation`. Per default MongoKit behaves like a python +called `use_dot_notation`. When you define a ValidationError, you can add the `%s` +into the format string to have the value placed in there for the final error message. +ValueErrors can also be thrown as an alternative. Per default MongoKit behaves like a python dictionary but with `use_dot_notation` set to ``True`` you can use your documents like you use models in nearly any other ORM by using dots to separate between attributes.