Hi,
I'm pretty new to web development and some ideas might look unnatural.
I'm playing a bit with TurboGears (which, BTW, is great) and I would
like a more unified way to manage state in an application (on either
the client or server side). Currently, one can add extra arguments to
the urls built in the template, use cookies or just server-side state
(which might not scale or it wouldn't make sense for simple data).
An example can be a simple CRUD application listing the records using
pagination. Editing a record and saving it would lose the pagination
state. The workaround is to add a form hidden field with this
information or passing it to the "action" form parameter (haven't
tried this) and ensure that saving redirects to it. However, I find
this pretty complicated and error-prone.
The idea is to have a common State class, defined in something like
turbogears.state and one can define the variable needed by subclassing
State (not tested):
class MyState(State):
page = URLVar(validators = ...) # the validators can also do
the conversion
other1 = CookieVar()
other2 = ServerVar()
class MyController(RootController):
@expose(...)
@state(MyState)
def somefunc(self, state, arg1, arg2, **kw):
...
state.page = 1
...
return dict(...)
The @state decorator should take care of extracting the state
variables from the calling parameters, cookies or server state and it
should create the "state" object to be passed to the called function.
At return, it should add the state to the dictionary (so that the
template can access it) and also set the cookies or server session
variables.
For the URL variables, we can define a state.url() function (similar
to tg.url) which would encode the corresponding variables (like /
somefunc?arg1=a&arg2=b&page=10). The state.url() function should also
allow the overriding of some URL variables directly so that we don't
have to write a separate function for a link accessing the next page
for example.
Thanks for comments,
Catalin
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---