On Feb 5, 11:00 am, Thomas Wittek <[EMAIL PROTECTED]> wrote:
> On Feb 5, 11:52 am, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > In my case, I have a
> > CRUD application where I can filter the records listing by various
> > fields which might or might not be present in the URL. Let's assume I
> > can map these in a RESTful way but one would like to edit a record.
> > The REST URL (i.e. /some/resource/55/edit) passed for editing would
> > miss the previous pagination information and, after saving the record,
> > you get back to the beginning of the list with the filtering and page
> > number information lost. [..]
> > Of course, you can save the page number and filtering information in a
> > session but I don't think we need the full power of sessions here,
> > when there is no private information.
>
> I think a session would be the simplest solution here.
> If you save the page in the session, you can easily direct the user to
> the proper resource/page after edit:
>
> @expose()
> def doedit(self, stuff):
> "save stuff"
> raise redirect("/some/resource/page/", session['page'])
>
> I can hardly imagine how it could be easier using some generic state
> framework.
In this particular case, you only have 'page' but we might have other
information like filtering by some query string and the last line
could become (assuming we break REST):
raise redirect(url("some/resource", page = session['page'], q =
session['q']))
The "doedit" function shouldn't be aware of the details of the state
that has to preserve. If we break REST (or if it becomes impossible
because of the number of variables involved), the above function could
become:
@expose()
@state(SomeState)
def doedit(self, state, stuff):
"save stuff"
raise redirect(state.url("/some/resource/page/"))
and state.url() takes care of appending the variables to the URL.
I could also implement this by simply adding **kw to "doedit" and
making sure that the information is passed to the function and
"redirect" uses it but I find it cleaner to wrap this in a State
object which can also handle validation and conversion to Python data.
Anyway, thanks for your comments so far,
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
-~----------~----~----~----~------~----~------~--~---