crud.create() serializes into an HTML form, not JSON. There's nothing built
in that does what you want. I think you would just have to write a custom
function/module to convert either a FORM object or DAL table object into
the desired JSON.
Anthony
On Tuesday, January 15, 2013 12:03:06 PM UTC-5, Alec Taylor wrote:
>
> How do I expose validators as JSON?
>
> I am not using web2py views in any capacity. Instead I am using AngularJS.
>
> So with web2py I am exposing my models RESTfully as JSON, and then
> consuming them with AngularJS.
>
> To reduce double-typing, how do I send field validators such as
> `IS_EMAIL` as JSON?
>
> # Model
> db.define_table(
> 'foo',
> Field('email', requires=IS_EMAIL())
> )
>
> # Controller
> @service.json
> def foo_form():
> return dict(my_foo_form=crud.create(db.foo))
>
> # Output I want
> { 'my_foo_form': { 'type': 'form', 'fields' { 'email',
> 'validator:IS_EMAIL'}, 'csrf': <uid> } }
>
> ----
>
> With this I can then write the equivalent functions in JavaScript and
> attach them to their corresponding fields.
>
> How do I do this with web2py?
>
> Thanks for all suggestions,
>
> Alec Taylor
>
--