FormEncode is nice (Validators are so much nicer than coding everything oneself)


Dipping my toes in the waters of FormEncode today. Basically decided I needed a break from financial aspects, so spent some time roughing out a simple list and add view for Inventory objects (in this particular case, phone numbers/DIDs). Most of the work was:

Figuring out that All and Any values are applied in reverse order. Argh.

Figuring out error handling with the error_handler decorator. Basically you decorate the post-handling method with:
@turbogears.error_handler( index )

where index is the method that handles the display of the validation errors. Normally that will be the same page as produced the post. You add a tg_errors=None to the signature of that page and then you can pass that value into your template for formatting. You can check for errors with py:if="errors" and you can pull out errors for a given field by parameter name.

Figuring out that FormEncode (or maybe it was CherryPy) automatically turns 'select.num' parameters into dictionaries as 'select': {'num': value,...}.

Still need the ability to search for a given number and to display the assigned configuration... well, really, need the whole application still, this was just a spike test, really.

Comments

  1. Ian Bicking

    Ian Bicking on 07/08/2006 5:25 p.m. #


    The reverse order thing is... well, an unfortunate artifact of history, and now I'm not quite sure how to fix it without breaking everything. Maybe completely different objects from Any and All that act in a more sensible (but not backward compatible) manner.<br />
    <br />
    select.num and other key unpacking is handled by formencode.variabledecode. select-1 would create a list.<br />

Comments are closed.

Pingbacks

Pingbacks are closed.