Skip to content

Commit

Permalink
Initialize the field widget manager in the update-step, such that the…
Browse files Browse the repository at this point in the history
… widget update step is only responsible for actually updating the widgets. The change is required to support the situation where you want to change the common widget prefix (which defaults to 'widgets.').
  • Loading branch information
malthe committed Sep 12, 2012
1 parent 88624f0 commit c03de60
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
10 changes: 10 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
CHANGES
=======

In next release ...

- Initialize widgets in ``update`` step. The ``updateWidgets`` method
is now responsible only for actually updating the widgets.

This allows updating the common widgets prefix before the individual
widgets are updated, useful for situations where neither a form, nor
a widgets prefix is desired.


2.8.3 (unreleased)
------------------

Expand Down
4 changes: 2 additions & 2 deletions src/z3c/form/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ def getContent(self):

def updateWidgets(self):
'''See interfaces.IForm'''
self.widgets = zope.component.getMultiAdapter(
(self, self.request, self.getContent()), interfaces.IWidgets)
self.widgets.mode = self.mode
self.widgets.ignoreContext = self.ignoreContext
self.widgets.ignoreRequest = self.ignoreRequest
Expand All @@ -148,6 +146,8 @@ def extractData(self, setErrors=True):

def update(self):
'''See interfaces.IForm'''
self.widgets = zope.component.getMultiAdapter(
(self, self.request, self.getContent()), interfaces.IWidgets)
self.updateWidgets()

def render(self):
Expand Down
13 changes: 4 additions & 9 deletions src/z3c/form/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ def __init__(self, context, request, parentForm):

def updateWidgets(self):
'''See interfaces.IForm'''
self.widgets = zope.component.getMultiAdapter(
(self, self.request, self.getContent()), interfaces.IWidgets)
for attrName in ('mode', 'ignoreRequest', 'ignoreContext',
'ignoreReadonly'):
value = getattr(self.parentForm.widgets, attrName)
Expand All @@ -44,7 +42,7 @@ def updateWidgets(self):

def update(self):
'''See interfaces.IForm'''
self.updateWidgets()
super(Group, self).update()
groups = []
for groupClass in self.groups:
# only instantiate the groupClass if it hasn't already
Expand Down Expand Up @@ -121,9 +119,10 @@ def applyChanges(self, data):

return changed

def update(self):
def updateWidgets(self):
'''See interfaces.IForm'''
self.updateWidgets()
super(GroupForm, self).updateWidgets()

groups = []
for groupClass in self.groups:
# only instantiate the groupClass if it hasn't already
Expand All @@ -135,7 +134,3 @@ def update(self):
group.update()
groups.append(group)
self.groups = tuple(groups)
self.updateActions()
self.actions.execute()
if self.refreshActions:
self.updateActions()

0 comments on commit c03de60

Please sign in to comment.