38 messages in com.googlegroups.pylons-discussRe: An idea for improving @validate| From | Sent On | Attachments |
|---|---|---|
| Steven Holmes | 28 Jan 2008 17:33 | |
| Mike Orr | 28 Jan 2008 22:33 | |
| Alberto Valverde | 29 Jan 2008 00:35 | |
| Steven Holmes | 29 Jan 2008 01:44 | |
| Qiangning Hong | 29 Jan 2008 03:01 | |
| Dmitry Lipovoi | 29 Jan 2008 03:05 | |
| Steven Holmes | 29 Jan 2008 03:27 | |
| Mike Orr | 29 Jan 2008 08:21 | |
| Steven Holmes | 29 Jan 2008 08:43 | |
| Matt Feifarek | 29 Jan 2008 08:52 | |
| Steven Holmes | 29 Jan 2008 09:05 | |
| Ian Bicking | 29 Jan 2008 09:40 | |
| Mike Orr | 29 Jan 2008 10:50 | |
| Ian Bicking | 29 Jan 2008 11:14 | |
| Mike Orr | 29 Jan 2008 11:25 | |
| Matt Feifarek | 29 Jan 2008 11:35 | |
| Ian Bicking | 29 Jan 2008 11:45 | |
| Mike Orr | 29 Jan 2008 12:32 | |
| Ian Bicking | 29 Jan 2008 12:46 | |
| Ben Bangert | 29 Jan 2008 12:56 | |
| Ben Bangert | 29 Jan 2008 12:57 | |
| Ben Bangert | 29 Jan 2008 13:05 | |
| Ian Bicking | 29 Jan 2008 13:05 | |
| Philip Jenvey | 29 Jan 2008 13:10 | |
| Philip Jenvey | 29 Jan 2008 13:10 | |
| Matt Feifarek | 29 Jan 2008 13:11 | |
| Ben Bangert | 29 Jan 2008 13:19 | |
| Ian Bicking | 29 Jan 2008 13:26 | |
| Ben Bangert | 29 Jan 2008 13:38 | |
| Mike Orr | 29 Jan 2008 14:51 | |
| Steven Holmes | 29 Jan 2008 14:54 | |
| Mike Orr | 29 Jan 2008 15:00 | |
| Mike Orr | 29 Jan 2008 15:17 | |
| Ian Bicking | 29 Jan 2008 15:27 | |
| Ben Bangert | 29 Jan 2008 15:59 | |
| Ian Bicking | 29 Jan 2008 16:05 | |
| Mike Orr | 29 Jan 2008 16:09 | |
| Steven Holmes | 29 Jan 2008 17:07 |
| Subject: | Re: An idea for improving @validate![]() |
|---|---|
| From: | Alberto Valverde (albe...@public.gmane.org) |
| Date: | 01/29/2008 12:35:49 AM |
| List: | com.googlegroups.pylons-discuss |
Steven Holmes wrote:
Hi,
@validate supports separating form rendering and form post processing
into distinct methods. This is convenient, but has a nasty flaw: It requires two separate URLs, a form display URL and a URL to handle the post. When a form post fails to validate, the form is re-displayed, but at the post URL instead of the original form display URL. I find this inconsistent and broken.
Here is a little example:
class AccountController(BaseController): def create_form(self): return render('create_account')
@validate(schema=CreateAccountSchema(), form='create_form') def create(self): return 'Account Created!'
To view the form we go to /account/create_form, then when we submit we
are taken to /account/create, where the form is re-displayed if there were errors. Two different URLs for the same form. This is
unnecessarily exposing a (confusing) implementation detail to the user.
Changing @validate so that it will always internally redirect to create_form if there is no form post would make things more consistent. The form could then be viewed at /account/create and also re-displayed with errors are /account/create, while the nice separation between form display and form processing is maintained.
I don't know what effect this change would have on backwards compatibility, but it can be made with a trivial (two lines or so)
change to @validate. (I can do a quick patch if anybody's interested).
With a little help of pylons.controllers.dispatch_on you can achieve what you want:
@dispatch_on(POST="do_create") def create(self): render("my form")
@validate(schema="something", form="create") def do_create(self): process(self.form_seult)
the form shown at create() can "submit to itself" so the external API only sees the /create url while you avoid branching inside the method to do two different jobs which is cleaner, IMHO.
Alberto




