[ckan-dev] Forms in CKAN

Rufus Pollock rufus.pollock at okfn.org
Fri Jan 14 14:47:17 UTC 2011


On 14 January 2011 13:44, Seb Bacon <seb.bacon at gmail.com> wrote:
> Hi,
>
> Next week I plan to review the way we currently generate forms in
> CKAN, with a view to improving them.
>
> In preparation for that, I would love to know what people think about
> the current situation: what works, and what doesn't? What are the
> properties of a decent form generating system?

Libraries I have used: FormEncode, FormAlchemy (what we are currently
using, before that formencode).

Neither seemed perfect but I think the form issue is a 'hard' problem
(perhaps with no perfect answer) [1]. FormAlchemy, in retrospect, was
probably a mistake as it merges too much model/validation/form
generation into one thing.

At least 3 functions involved:

1. Generating (or just filling) a form template with 'form data' (and errors)
2. Converting model data to form data (also happens for APIs in fact)
-- let's call this 'dict-ization'
3. Converting form data to model data (and validating) (inverse of
previous step)

I think one can and should separate 1 from 2+3 (and one of problems
with formalchemy is it doesn't -- the attraction being you don't
repeat yourself as forms get generated from model but I think this is
actually a false economy in medium-term).

I'm not specifically recommending the following as I haven't used them
but I've looked through docs, they are active and reasonably mature:

1. Flatland: http://discorporate.us/projects/flatland/docs/tip/
  * Only does 2+3 which is a good thing IMO

2. WTForms: http://wtforms.simplecodes.com/
  * Used in standard flask docs: <http://flask.pocoo.org/docs/patterns/wtforms/>

Regards,

Rufus

[1]: http://blog.ianbicking.org/on-form-libraries.html




More information about the ckan-dev mailing list