IMO, FormEncode is one og the best parts of Pylons. It's well designed
and powerful, although I agree more examples are needed in the
documentation, as I had to search thru the code quite a bit to figure
out how to define my own validators, and combine them in complex ways
in a Schema (which is all supported by sparsely documented). It
doesn't help that Pylons documentation is fragmented, where you have a
"complete module reference", the "official docs" that includes doc for
third-party modules like form-encode, as well as a form-encode specifc
website (different then pylons' offical docs/third party)

On Jan 7, 12:21 pm, "Dalius Dobravolskas"
<[email protected]> wrote:
> Hello,
>
> > 1. From what I gather in the docs, it seems FormEncode is directed more
> > at form value validation rather than form generation.
>
> That's right. If you want form generation you can try ToscaWidgets.
>
> > 2. In simple / naive usage mode it requires mixing HTML and code, which
>
> That's not the case. Not sure there you get that from.
>
> > 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.
>
> I don't know. I usually read the code. More fun and both I learn more.
>
> OK. Let's focus on form validation. Some samples from my code:
>
> formencode schema:
>
> class LanguageForm(formencode.Schema):
>     allow_extra_fields = True
>     filter_extra_fields = True
>     name = formencode.validators.UnicodeString(not_empty=True)
>
> Schema says that I expect form with input name that is unicode string
> and is not empty.
>
> Controller code:
>
>     @jsonify
>     @authorize(is_authorized)
>     @validate(LanguageForm())
>     def language_create(self, project):
>         p = 
> model.meta.Session.query(model.Project).filter_by(name=project).first()
>         l = model.Language()
>         l.project = p
>         l.name = self.form_result['name']
>         model.meta.Session.save(l)
>
> What you wanted is simpler access to form parameters. Here you have
> them:  self.form_result['name']
>
> BTW, I think request.params['name'] and request.POST['name'] (if it is
> POST request) will work as well. But with form validation you can get
> correct type in place.
>
> > Should I just write the HTML forms in templates manually or what?
>
> That's one way to do your work :-) As for beginning it is good way. If
> you don't like this way use ToscaWidgets (ToscaWidgets uses FormEncode
> for validation). I'm not sure but I think you can write some routines
> with Mako that could help to generate forms. You will have both
> flexibility and simplicity. That's only my speculation  now but I will
> investigate this approach when I will have time. ToscaWidgets are nice
> and works for me but when I want to add something unusual I have to
> make hacks and other voodoo magic.
>
> --
> Daliushttp://blog.sandbox.lt
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to