On Wed, Jan 7, 2009 at 11:58 AM, mk <[email protected]> wrote: > > Dalius Dobravolskas wrote: >>> if request.environ.has_key('paste.parsed_formvars'): >>> for item in request.environ['paste.parsed_formvars'][0].items(): >>> do_smth(item) >>> >>> Is there a shorter / proper way to do it? >> Learn FormEncode or ToscaWidgets. I use both but like plain FormEncode more. > > There are three problems with FormEncode: > > 1. From what I gather in the docs, it seems FormEncode is directed more > at form value validation rather than form generation. Author plainly > states in the docs that FormEncode has limitations in the area of form > generation: > > "At one time FormEncode included form generation in addition to > validation. The form generation worked okay; it was reasonably > attractive, and in many ways quite powerful. I might revisit it. But > generation is limited. It works great at first, then you hit a wall – > you want to make a change, and you just can't, it doesn't fit into the > automatic generation."
FormEncode does not do form generation, period. That paragraph must have been written in an early stage of FormEncode's development. The main Pylons solutions for form generation are: 1) A template with a manually-built form. 2) Same but with WebHelpers. 3) ToscaWidgets. 4) FormAlchemy. > 2. In simple / naive usage mode it requires mixing HTML and code, which > I abhor, on top of it being contrary to the principles of 'separation of > layers' in MVC. I'm not sure what "it" means, unless you're objecting to building forms in templates. But a form is intrinsically a user interface object. In some cases the exact look is unimportant enough that a programmatically-generated form (ToscaWidgets) is acceptable. In other cases the form needs so many customizations that it's not worth creating a ToscaWidgets widget set for it. My client is prone to say "put this text here next to this one field, and move these three fields in a row, no, wait, change it back". This is easier to manage with a template+WebHelpers form. > Sure, one could theoretically think about parsing templates and getting > form strings out and then passing them to FormEncode for validation > and/or further generation, or do smth even fancier like storing form > HTML in database and then passing it to FormEncode. But that's > complicated and I'm just a beginner with all the components of Pylons. > Maybe some day. I think FormEncode is easier than than you're making it out to be. The main problem with FormEncode in Pylons is that there's not a good structure for calling htmlfill on the initial form to eliminate the <form:error> tags, while also calling it in a different way if validation fails. @validate works but is not structured that well. So you just have to work around these annoyances if they affect your application. > 3. I don't mean to be ungrateful towards Ian or smth, but I find > FormEncode's documentation to be rather limited to tell the truth. The FormEncode manual is incomplete and was written to introduce FormEncode on the command line. That's not how it's used in Pylons, which is what makes it difficult to learn FormEncode from the manual. The manual does not address the new validators that have been added, how to choose between similar validators, and does not say enough about building your own validators. At the last PyCon, Ian and I brainstormed a list of things that should go into the manual, but nobody has had time to write it. http://wiki.pylonshq.com/display/pylonscookbook/The+other+FormEncode+manual+(UNFINISHED) I and other users may have developed some other techniques in the meantime which have not made it onto this page. If you're having trouble with particular aspects of FormEncode, ask here or on the FormEncode list. -- Mike Orr <[email protected]> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
