Independent data model validation with colander

35 views
Skip to first unread message

Andrius Kulbis

unread,
Jun 8, 2016, 8:25:30 AM6/8/16
to pylons-discuss
I started using colander in my pyramid project. Created a simple data model mapping using colander
class DataModel(colander.MappingSchema):
    user_count
= colander.SchemaNode(colander.Integer())
    expiration_date
= colander.SchemaNode(colander.Date())
    comment
= colander.SchemaNode(colander.String())

How can I pass submited form data to this mapping ir order to validate it without using deform? Is it possible to iterate over a validation errors?

model = DataModel()

if 'submit' request.POST:
   form_data
=request.POST.items()
   
???


tonthon

unread,
Jun 8, 2016, 8:46:56 AM6/8/16
to pylons-...@googlegroups.com
Hi,
you may use peppercorn for this purpose :

import peppercorn
controls = request.params.items()
values = peppercorn.parse(controls)
try:
appstruct = schema.deserialize(values)
except colander.Invalid as e:
logger.exception(u"An error occured")

Hope this help,
Regards
Gaston
> --
> You received this message because you are subscribed to the Google
> Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pylons-discus...@googlegroups.com
> <mailto:pylons-discus...@googlegroups.com>.
> To post to this group, send email to pylons-...@googlegroups.com
> <mailto:pylons-...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pylons-discuss/991aaa8d-f540-4dc1-a32a-c72aad959e7c%40googlegroups.com
> <https://groups.google.com/d/msgid/pylons-discuss/991aaa8d-f540-4dc1-a32a-c72aad959e7c%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


Reply all
Reply to author
Forward
0 new messages