Commits

danjac  committed 4eff770

moved example to colander

  • Participants
  • Parent commits dc17ec5

Comments (0)

Files changed (3)

File docs/index.rst

 
     renderer = FormRenderer(form)
     renderer.start_hidden_tag('mapping', 'series')
-    >>> <<div style="display:none;">input type="hidden" name="__start__" value="series:mapping" /></div>
+    >>> <<div style="display:none;"><input type="hidden" name="__start__" value="series:mapping" /></div>
 
     renderer.end_hidden_tag()
     >>> <div style="display:none;"><input type="hidden" name="__end__" /></div>
 
 See the `Peppercorn`_ docs for more information.
 
+[TBD: full example]
 
 CSRF Validation
 ---------------

File examples/simplesite/db.sqlite

Binary file modified.

File examples/simplesite/simplesite/handlers.py

 import logging
+import colander
 
 from pyramid_handlers import action
 from pyramid.url import route_url
 from pyramid.httpexceptions import HTTPFound
-from pyramid_simpleform import Form
+from pyramid_simpleform.form import Form
 from pyramid_simpleform.renderers import FormRenderer
 
-from formencode import Schema, validators
-
 from simplesite.models import MyModel, Session
 
-class MyModelSchema(Schema):
+class MyModelSchema(colander.MappingSchema):
 
-    filter_extra_fields = True
-    allow_extra_fields = True
 
-    name = validators.MinLength(5, not_empty=True)
-    value = validators.Int(not_empty=True)
+    name = colander.SchemaNode(
+        colander.String(),
+        validator=colander.Length(min=5)
+    )
+
+    value = colander.SchemaNode(
+        colander.Int()
+    )
 
 
 log = logging.getLogger(__name__)
         item_id = self.request.matchdict['item_id']
         item = session.query(MyModel).get(item_id)
 
-        form = Form(self.request, schema=MyModelSchema, obj=item)
+        form = Form(self.request, schema=MyModelSchema(), obj=item)
 
         if form.validate():
             
     @action(renderer='submit.html')
     def submit(self):
         
-        form = Form(self.request, schema=MyModelSchema)
+        form = Form(self.request, schema=MyModelSchema())
 
         if form.validate():