"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> Yes, unfortunately 'take action' seems a little complicated when I need
> to pass various POSTed arguments back and forth across methods. With
Why? You use dictionaries for that. You receive a dictionary, pass it to
another method, it then manipulates it and returns another dictionary, etc.
If you're passing and handling individual variables then things can get messy
very fast.
> the 'submit to self' option it's trivial because all your data is in
> POST variables - you handle it accordingly and either redirect if
> successful or use those variables to fill in the form if you need to
> show it again.
Yep. And it's not different with two methods or just one... You'll have to
do the same things. Using two methods makes them smaller -- they are
specialized in doing one part of the whole thing -- and more readable than if
you have to consider what value comes in for X variable if it is a submit or
if it is not, then what should happen on each and every condition where this
form can be reached... Using two methods, one will always have data submitted
to it and the other won't.
> On the other hand, if I submit to a different URL/method, that page
> will receive the POST variables - all good - but in the event of error,
> I then have to redirect back to the original page, and pass in 2 sets
> of data, ie. the POSTed variables plus the set of errors to display.
> Assuming this method is still better than the previous one when using
> TurboGears, what is the cleanest way of doing this? I have seen no
> directly relevant examples in the 20m Wiki or the Getting Started
> guide. Perhaps I missed one?
I believe that I already answered that when I gave you some examples and even
skeleton code. That is my opinion...
> How do I send that data back? I assume I'm going to have to use a
> redirect but how do I form that appropriately, and in a way such that
> the original page will work properly in the absence of that data (ie.
> on the first view)?
When you submit your form, your variables can be grouped in a dictionary.
That is what I showed you with the **kword feature.
Here are some examples in Python, so that you can see how it works.
In [1]: def example(obligatory, *arg, **kwords):
...: print "I got:", obligatory
...: print "I also got:", arg
...: print "And I also got:", kwords
...:
In [2]: example(obligatory = 1)
I got: 1
I also got: ()
And I also got: {}
In [3]: example(1, 2)
I got: 1
I also got: (2,)
And I also got: {}
In [4]: example(1, 2, 3)
I got: 1
I also got: (2, 3)
And I also got: {}
In [5]: example(1, 2, 3, 4)
I got: 1
I also got: (2, 3, 4)
And I also got: {}
In [6]: example(1, 2, 3, 4, a = 5)
I got: 1
I also got: (2, 3, 4)
And I also got: {'a': 5}
In [7]: example(1, 2, 3, 4, a = 5, b = 6)
I got: 1
I also got: (2, 3, 4)
And I also got: {'a': 5, 'b': 6}
The same happens for web forms, but the keywords are the names you use as
"name" attribute and the value is the value they have. So, if you have a form
with an input field named 'test' and with value 'abc', then you'll have the
same thing as passing "test = 'abc'" (without double quotes, of course).
> (I don't think it's any coincidence that when I just put "cherrypy
> redirect" into Google to try and answer this for myself, the first
> result was <http://lion.taoriver.net/?p=10> highlighting pretty much
> the same problems as I'm having.)
Since you're using TurboGears and not cherrypy directly, I'd say you'd better
try solving it with TurboGears instead of low level cherrypy... You'll have
less problems.
Anyway, look for the post he said he had in his Emacs buffer where he stated a
different opinion. You can search for it at this list archives.
> I don't particularly like PHP either but if you need to know how to do
> something, the docs tell you. When it comes to maintenance and pleasure
How long did it take to get there? ;-)
> in writing code, PHP lets me put down ugly but working code in 10
> minutes, because I can find examples in their docs, whereas TurboGears
> seems to make me wait weeks for the pretty and well-maintained code
> because I can't find any example of what I want to do.
You're lucky... Or I am. I had the opposite feeling. Specially with
reinventing the wheel many times in PHP...
> Believe me though, I wouldn't be bothering with this if I actually
> liked PHP.
:-) I dunno. I always try learning something new from time to time. It
keeps my mind open for new technologies and shows me tools that can solve some
part of my problems more efficiently than other.
> I really have gone through both the Wiki and the Getting Started guide.
> The problem is, pretty much as Lion Kimbro said on the blog, when I try
> to do something a little different to what is detailed on the
> walkthroughs, you find that there's nothing telling you how to do it.
So, come here and ask! Tell what you did, what happened, what you expected to
happen, how you did things, etc. People are very helpful here.
> Thanks again for your help,
Anytime I can help, I try doing so.
--
Jorge Godoy <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---