Add function arguments. For example, if you have:
def thing(self):
...and your form sends "a=3&b=4&c=5", augment your function signature:
def thing(self, a, b, c=1):
In this example, a and b are required. c will default to 1 if not
supplied. Alternately, you can use keyword-args [1] to do the same
thing:
def thing(self, **kwargs):
a = kwargs['a']
b = kwargs['b']
c = kwargs.get('c', 1)
> b) is there a best practice in gathering values from the "control
> panel"? in qt it's easy to work of the changed values only in an
event-
> driven manner using signal/slots. in my new cherrypy world, it seems
> like i need to process the set of values every time. please tell me
> that i'm wrong.
There are three approaches:
1. Compare all the new values to the existing values. **kwargs can help
here:
for k, v in kwargs.iteritems():
if current[k] != v:
process_a_change(k, v)
2. Make a separate form (and cherrypy handler function) for each
control, or at least subsets of all controls.
3. Use AJAX [2] to send an individual message when each control
changes, rather than using a big 'submit' button. This will also imply a
separate cherrypy handler function for each control, but will not
require a complete refresh of the page for each request.
I would choose 3, most likely, but that will take more work on your part
if you're a web newbie.
Robert Brewer
fuma...@aminus.org
[1] http://docs.python.org/ref/calls.html#tok-keyword_arguments
[2] http://en.wikipedia.org/wiki/AJAX