On Wednesday 22 August 2007 11:48:00 Glauco wrote:
> there is a lot of confusion about workflow control in controllers, in ML
> and in the TG book is not well clarified how is the correct procedure,
> and infact i've a lot of doubt about different use of:
>
> return self.page( tg_errors, data )
> and
> raise tg.redirect( tg.url("page", tg_errors=tg_errors, **data) )
>
>
> In a controller we must do frequently something like:
>
> @tg.expose()
> @tg.validate( form = previous_page )
> def page(self, tg_errors=None, **data):
> if tg_errors:
> pass # some error handling
>
> if not data.get('my_submit_button_pressed'):
> # this is the case of autosubmit widget
> return self.previous_page( tg_errors, **data )
> raise tg.redirect( tg.url("previous_page",
> tg_errors=tg_errors, **data) )
> else:
> # proceed with workflow
> pass
>
> This is the main structure of our workflow-controller-process.
>
>
> Now ..some consideration !
> ------------------------------------------------------------------------
> return self.previous_page( tg_errors, **data )
> Data is well passed to previous_page, validated and correclty converted
> (single , nested_widget, repeating widget, shuttle select, fieldset,
> etc..). But this have a strange behaviour, if the form is used in KID with
> "${form(**form_params)}" the form_params contain always the original value
> submitted, so a command like:
>
> data['value']['mywidget'] = 'foo'
> is absolutlely ignored !
>
> i found that something like this:
> <B>${form_params['value']['mywidget']}</B>
> render different value from
> ${form(**form_params)}
>
> where Kid get original value, is a mistery for me....
>
> ------------------------------------------------------------------------
> raise tg.redirect( tg.url("previous_page", tg_errors=tg_errors, **data) )
> This is the tecnique described in the docuementation, but this have
> other problem:
>
> First of all, a big form create an impressive and too long URL !
> Second the url_quote procedure convert correclty ONLY first level of
> data, if your form is a complicated tree of data (nested widget like
> fieldset or select_shuttle) all value under the first level are all
> converted in unicode !
> only solution i found is a non good pythonic solution !
> if isinstance ( data.get('mywidgetvalue'), unicode):
> data['mywidgetvalue'] = eval(data['mywidgetvalue']) # FIXME:
> TERRIBLE !
There are several options here. I can't comment on the url_quoting without
further testing on my own.
But redirection with post-data in general is an issue. You can tackle that in
various ways.
First of all, you can create a session or otherwise temporary storage for the
data with a unique key. Then the redirect url gets that key instead of all
parameters, and fetches the data from that key. Using a custom decorator, you
can automate that for all of your exposed controller methods.
Alternatively, you can rid yourself of the redirect and simply call the
desired method in question. Granted, this can be somewhat tricky sometimes,
because to do so you must
- invoke the method
- somehow know the destination template to use
- set that template in your result, so that TG will use it instead
of the originally exposed one.
Diez
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---