On 29 Jan 2008, at 08:36, Alberto Valverde wrote:
>
> 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
>
Thanks, I didn't know about dispatch_on.
However, this isn't so much of a case of what I want as what I think
should happen by default. The pylons form tutorial teaches the two-URL
way and I think that having two different URLs for displaying the same
form is fundamentally broken (and unnecessary). Are there any
advantages to doing it this way that I've missed?
(My preferred method would actually involve saving the Invalid
exception somewhere and redirecting the user to referrer, but that's a
more fundamental change).
Cheers,
Steven
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---