Grrrrr

I was using the un nice

    def update_forwarding(self, email_addr, forward_addr, **kwargs):
        active=kwargs.get('active', False)
        keep=kwargs.get('keep', False)

Thanks for the default arguments tips ...


On Jun 20, 11:55 am, "Diez B. Roggisch" <[EMAIL PROTECTED]>
wrote:
> On Wednesday 20 June 2007 11:42, aspineux wrote:
>
>
>
> > It doens't work, and it cannot works !
>
> > I tried this
>
> > class FormForwarding(widgets.TableForm):
> >     fields = [
> >         MultipleHiddenFields('context'),
> >         widgets.CheckBox('active', label="Activate forwarding",
> > validator=validators.StringBool(if_empty=False)),
> >         widgets.TextField('forward_addr', label="Address to forward
> > to", attrs=dict(size=40, maxlength=255), validator=EmailValidator()),
> >         widgets.CheckBox('keep', label="Keep a copy on server",
> > validator=validators.StringBool(if_empty=False, if_invalid=False )),
> >     ]
> >     submit_text = "Update forwarding"
>
> > And added some debuging into StringBool
>
> >     def _to_python(self, value, state):
> >         print "================================================="
> >         if isinstance(value, (str, unicode)):
> >             value = value.strip().lower()
> >             if value in self.true_values:
> >                 return True
> >             if not value or value in self.false_values:
> >                 return False
> >             raise Invalid(self.message("string", state,
> >                                        true=self.true_values[0],
> >                                        false=self.false_values[0]),
> >                           value, state)
> >         return bool(value)
>
> >     def _from_python(self, value, state):
> >         print "================================================="
> >         if value:
> >             return self.true_values[0]
> >         else:
> >             return self.false_values[0]
>
> > When both are checked, I can see the 4 '====' line
> > But when one is missing, non of them.
>
> > This is because the call (that generate the error) is done before the
> > call of the validator !
> > I thins this is because one decorator is taking the signature of the
> > function.
> > And then raise an exception because of missing argument.
>
> > Their is no solution with TG 1.x today for missing value !
>
> > It should be in red flashing in the wiki somewhere !
>
> I doubt there is a different solution with TG x.x - because the simple
> solution to this is to use keyword arguments to give a default value,
> especially to possibly empty values.
>
> And I don't think that there will be a more concise notation of this than the
> built-in one.
>
> Diez


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to