Skip to content

Commit

Permalink
extract setupWidgets to allow subclasses to override widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
agroszer committed Feb 20, 2016
1 parent c6991bd commit ef04bff
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/z3c/form/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,10 @@ def mode(self, mode):
for w in self.widgets.values():
w.mode = mode

def updateWidgets(self, setErrors=True):
if self.field is None:
raise ValueError("%r .field is None, that's a blocking point" % self)

def setupWidgets(self):
self.prefix = self.name
self.fields = Fields(self.field.schema)

if self._value is interfaces.NO_VALUE:
value = ObjectWidgetValue()
else:
value = self._value

self.widgets = field.FieldWidgets(self, self.request, None)
self.widgets.mode = self.mode
# very-very important! otherwise the update() tries to set
Expand All @@ -222,10 +214,16 @@ def updateWidgets(self, setErrors=True):
self.widgets.ignoreRequest = self.ignoreRequest
self.widgets.update()

def updateWidgets(self, setErrors=True):
if self.field is None:
raise ValueError("%r .field is None, that's a blocking point" % self)

self.setupWidgets()

if not self._value is interfaces.NO_VALUE:
for name, widget in self.widgets.items():
try:
v = value[name]
v = self._value[name]
except KeyError:
pass
else:
Expand All @@ -238,7 +236,7 @@ def applyValue(self, widget, value):
responsible for validating the given value and setup an error message.
This is internal apply value and validation process is needed because
nothing outside this multi widget does know something about our
nothing outside this widget does know something about our
internal sub widgets.
"""
if value is not interfaces.NO_VALUE:
Expand Down

0 comments on commit ef04bff

Please sign in to comment.