[EMAIL PROTECTED] wrote:
> But between showing the original form, and showing the altered data,
> you don't normally want to show an intermediate page, do you? So it
> makes sense not to have that intermediate page or method.
>
> I want to have pseudocode like this:
>
> # Page 1
> if form has been submitted:
> if submitted values are ok:
> perform database modification/whatever action
> redirect to Page 2
> else:
> generate error strings
> display error strings, if they exist
> display form, which submits to itself, with inline form data if it
> exists
>
> http://www.livejournal.com/login.bml is one good example of how this
> should appear to the user.
>
> Now, I appreciate that this is a method that is the best for ASP and
> PHP where the template and the logic are in the same file, and that it
> may not be the best way for TurboGears. However, I don't see a /simple/
> way of replacing this functionality. These are my requirements:
>
> - I want the same URL in the address bar both when it's the first
> time you visit the page and see an empty form, or when you've already
> submitted data and are returned to the page (perhaps because some of
> the data was wrong)
> - I want the form to be populated with the previously entered data,
> if it exists (eg. if they entered a valid address but an invalid
> telephone number, I want to keep the address). Obviously the form still
> has to work if that data isn't provided yet (ie. on the first visit).
> - I don't want the user to ever see an intermediate 'redirecting'
> page or anything like that
> - The code should be shorter than the PHP equivalent (or there's no
> point me using TurboGears)
>
> These seem like obvious requirements for any login system or ordering
> system where you enter a shipping address, but I am having trouble
> finding clear examples of how to do it.
>
> I don't need separate save/update/delete functionality and trying to
> understand that in the example just confused matters for me. I'm not
> doing database manipulation, just web form handling. I only have 1
> thing to do with this form - submit it. It either succeeds and moves to
> the next page, or it doesn't and it stays on this page for the user to
> try again. It should be simple. It probably /is/ simple, but TurboGears
> isn't telling me how.
>
> Sadly I'm wasting multiple hours on this when it would have taken less
> than one hour in PHP :( If I can't get this working soon without
> spending way too much time on trial and error then I will give up and
> use something better documented instead.
Have you considered spiting your functionality into 2 methods as
suggested (mostly for brevity sake) and adding a third (one being
exposed and consequently determening the URL) to dispatch according to
cherrypy.request.method:
def some_page(self, *args, **kw):
if "POST" == cherrypy.request.method:
return self.some_page_submit(*args, **kw)
else:
return self.some_page_view(*args, **kw)
If you are frequently using this idiom a getter or even a metaclass or
mix-in class (multiple inheritance) might be in order:
class Root(turbogears.RootController):
...
def __getattr__(self, name):
try:
return object.__getattribute__(self, name)
except AttributeError:
if "POST" == cherrypy.request.method.upper():
return object.__getattribute__(self, name + "_submit")
else:
return object.__getattribute__(self, name + "_view")
Cheers,
Simon
P.S. haven't bothered to test the code. I do hope, at the very least, it
will give you an idea what I am talking about.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---