[Checkins] SVN: z3c.form/branches/adamg-objectwidget/src/z3c/form/ made setErrors go recursive over forms and widgets
Brian Sutherland
brian at vanguardistas.net
Mon Jan 5 04:06:01 EST 2009
On Sun, Jan 04, 2009 at 06:01:02PM +0100, Adam GROSZER wrote:
> Hello Brian,
>
> I hope I solved it... please check...
Yeah, it looks like you solved my backwards compatibility issue in
94501. Thanks!
>
> Monday, December 22, 2008, 1:28:59 PM, you wrote:
>
> BS> Apologies if this has come up before, but this change breaks backwards
> BS> compatibility for and existing widget I have (error described below).
>
> BS> Was the change to IWidget discussed anywhere?
>
> BS> On Tue, Oct 14, 2008 at 12:30:08PM -0400, Adam Groszer wrote:
> >> Log message for revision 92198:
> >> made setErrors go recursive over forms and widgets
> >>
> >>
> >> Changed:
> >> U z3c.form/branches/adamg-objectwidget/src/z3c/form/browser/image.py
> >> U z3c.form/branches/adamg-objectwidget/src/z3c/form/browser/object.txt
> >> U z3c.form/branches/adamg-objectwidget/src/z3c/form/field.py
> >> U z3c.form/branches/adamg-objectwidget/src/z3c/form/form.py
> >> U z3c.form/branches/adamg-objectwidget/src/z3c/form/interfaces.py
> >> U z3c.form/branches/adamg-objectwidget/src/z3c/form/object.py
> >> U z3c.form/branches/adamg-objectwidget/src/z3c/form/widget.py
> >>
> >> -=-
>
> BS> <snip>
>
> >> Modified:
> >> z3c.form/branches/adamg-objectwidget/src/z3c/form/interfaces.py
> >> ===================================================================
> >> --- z3c.form/branches/adamg-objectwidget/src/z3c/form/interfaces.py
> >> 2008-10-14 15:22:29 UTC (rev 92197)
> >> +++ z3c.form/branches/adamg-objectwidget/src/z3c/form/interfaces.py
> >> 2008-10-14 16:30:08 UTC (rev 92198)
> >> @@ -404,7 +404,7 @@
> >> default=False,
> >> required=False)
> >>
> >> - def extract(default=NOVALUE):
> >> + def extract(default=NOVALUE, setErrors=True):
> >> """Extract the string value(s) of the widget from the form.
> >>
> >> The return value may be any Python construct, but is
> >> typically a
> >> @@ -414,10 +414,12 @@
> >>
> >> If an error occurs during the extraction, the default value
> >> should be
> >> returned. Since this should never happen, if the widget is
> >> properly
> >> - designed and used, it is okay to not raise an error here,
> >> since we do
> >> + designed and used, it is okay to NOT raise an error here,
> >> since we do
> >> not want to crash the system during an inproper request.
> >>
> >> If there is no value to extract, the default is to be
> >> returned.
> >> +
> >> + setErrors: needs to be passed on to possible sub-widgets
> >> """
> >>
> >> def update():
> >> @@ -582,8 +584,11 @@
> >> def update():
> >> """Setup widgets."""
> >>
> >> - def extract():
> >> + def extract(setErrors=True):
> >> """Extract the values from the widgets and validate them.
> >> +
> >> + setErrors: decides whether to set errors on self and on the
> >> widgets
> >> + also needs to be passed on to sub-widgets
> >> """
> >>
> >>
> >> @@ -843,9 +848,11 @@
> >> mainly meant to be a hook for subclasses.
> >> '''
> >>
> >> - def extractData():
> >> - '''Extract the data of the form.'''
> >> + def extractData(setErrors=True):
> >> + '''Extract the data of the form.
> >>
> >> + setErrors: needs to be passed to extract() and to
> >> sub-widgets'''
> >> +
> >> def update():
> >> '''Update the form.'''
> >>
> >>
>
> BS> <snip>
>
> >> Modified: z3c.form/branches/adamg-objectwidget/src/z3c/form/widget.py
> >> ===================================================================
> >> --- z3c.form/branches/adamg-objectwidget/src/z3c/form/widget.py 2008-10-14 15:22:29 UTC (rev 92197)
> >> +++ z3c.form/branches/adamg-objectwidget/src/z3c/form/widget.py 2008-10-14 16:30:08 UTC (rev 92198)
> >> @@ -77,7 +77,9 @@
> >> lookForDefault = False
> >> # Step 1.1: If possible, get a value from the request
> >> if not self.ignoreRequest:
> >> - widget_value = self.extract()
> >> + #at this turn we do not need errors to be set on widgets
> >> + #errors will be set when extract gets called from form.extractData
> >> + widget_value = self.extract(setErrors=False)
>
> BS> This raises:
>
> BS> TypeError: extract() got an unexpected keyword argument 'setErrors'
>
> BS> For an existing widget that implements the extract method.
>
> >> if widget_value is not interfaces.NOVALUE:
> >> # Once we found the value in the request, it takes precendence
> >> # over everything and nothing else has to be done.
> >> @@ -136,7 +138,7 @@
> >> IPageTemplate, name=self.mode)
> >> return template(self)
> >>
> >> - def extract(self, default=interfaces.NOVALUE):
> >> + def extract(self, default=interfaces.NOVALUE, setErrors=True):
> >> """See z3c.form.interfaces.IWidget."""
> >> return self.request.get(self.name, default)
> >>
> >> @@ -195,7 +197,7 @@
> >> self.updateTerms()
> >> super(SequenceWidget, self).update()
> >>
> >> - def extract(self, default=interfaces.NOVALUE):
> >> + def extract(self, default=interfaces.NOVALUE, setErrors=True):
> >> """See z3c.form.interfaces.IWidget."""
> >> if (self.name not in self.request and
> >> self.name+'-empty-marker' in self.request):
> >> @@ -338,7 +340,7 @@
> >> self.updateWidgets()
> >> return property(get, set)
> >>
> >> - def extract(self, default=interfaces.NOVALUE):
> >> + def extract(self, default=interfaces.NOVALUE, setErrors=True):
> >> # This method is responsible to get the widgets value based on the
> >> # request and nothing else.
> >> # We have to setup the widgets for extract their values, because we
> >>
> >> _______________________________________________
> >> Checkins mailing list
> >> Checkins at zope.org
> >> http://mail.zope.org/mailman/listinfo/checkins
>
>
>
> --
> Best regards,
> Adam GROSZER mailto:agroszer at gmail.com
> --
> Quote of the day:
> Some people think it's holding on that makes one strong. Sometimes it's letting go.
> - Sylvia Robinson
>
--
Brian Sutherland
More information about the Checkins
mailing list