Skip to content

Commit

Permalink
Merge branch 'master' into adamg-objectwidget
Browse files Browse the repository at this point in the history
# Conflicts:
#	setup.py
#	src/z3c/form/browser/radio.py
  • Loading branch information
agroszer committed Mar 9, 2016
2 parents ce2ea35 + 57c5346 commit dd8c315
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 29 deletions.
12 changes: 12 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CHANGES
=======

3.3.0 (unreleased)
3.2.11 (unreleased)
-------------------

- *MAJOR* overhaul of ObjectWidget:
Expand All @@ -17,6 +18,17 @@ CHANGES
* added high level integration tests


3.2.10 (2016-03-09)
-------------------

- RadioWidget items are better determined when they are needed [agroszer]

- CheckBoxWidget items are better determined when they are needed [agroszer]

- Bugfix: The ``ChoiceTerms`` adapter blindly assumed that the passed in field
is unbound, which is not necessarily the case in interesting ObjectWidget
scenarios. Not it checks for a non-None field context first. [srichter]

3.2.9 (2016-02-01)
------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def alltests():

setup(
name='z3c.form',
version='3.3.0.dev0',
version='3.2.11.dev0',
author="Stephan Richter, Roger Ineichen and the Zope Community",
author_email="zope-dev@zope.org",
description="An advanced form and widget framework for Zope 3",
Expand Down
27 changes: 15 additions & 12 deletions src/z3c/form/browser/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ class CheckBoxWidget(widget.HTMLInputWidget, SequenceWidget):
def isChecked(self, term):
return term.token in self.value

def update(self):
"""See z3c.form.interfaces.IWidget."""
super(CheckBoxWidget, self).update()
widget.addFieldClass(self)
# XXX: this is to early for setup items. See select widget how this
# sould be done. Setup the items here doens't allow to override the
# widget.value in updateWidgets, ri
self.items = []
def items(self):
if self.terms is None:
return ()
items = []
for count, term in enumerate(self.terms):
checked = self.isChecked(term)
id = '%s-%i' % (self.id, count)
Expand All @@ -56,16 +52,23 @@ def update(self):
default=term.title)
else:
label = util.toUnicode(term.value)
self.items.append(
{'id':id, 'name':self.name + ':list', 'value':term.token,
'label':label, 'checked':checked})
items.append(
{'id': id, 'name': self.name + ':list', 'value': term.token,
'label': label, 'checked': checked})
return items

def update(self):
"""See z3c.form.interfaces.IWidget."""
super(CheckBoxWidget, self).update()
widget.addFieldClass(self)

def json_data(self):
data = super(CheckBoxWidget, self).json_data()
data['options'] = self.items
data['options'] = list(self.items())
data['type'] = 'check'
return data


@zope.component.adapter(zope.schema.interfaces.IField, interfaces.IFormLayer)
@zope.interface.implementer(interfaces.IFieldWidget)
def CheckBoxFieldWidget(field, request):
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/form/browser/checkbox.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ the value (which is used as a backup label) contains non-ASCII characters:
>>> terms = SimpleVocabulary.fromValues([b'yes\012', b'no\243'])
>>> widget.terms = terms
>>> widget.update()
>>> pprint(widget.items)
>>> pprint(list(widget.items()))
[{'checked': False,
'id': 'widget-id-0',
'label': 'yes\n',
Expand Down
26 changes: 13 additions & 13 deletions src/z3c/form/browser/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class RadioWidget(widget.HTMLInputWidget, SequenceWidget):

klass = u'radio-widget'
css = u'radio'
items = ()

def isChecked(self, term):
return term.token in self.value
Expand All @@ -60,14 +59,10 @@ def renderForValue(self, value):
IPageTemplate, name=self.mode + '_single')
return template(self, item)

def update(self):
"""See z3c.form.interfaces.IWidget."""
super(RadioWidget, self).update()
# XXX: this is to early for setup items. See select widget how this
# should be done. Setup the items here doesn't allow to override the
# widget.value in updateWidgets, ri
widget.addFieldClass(self)
self.items = []
def items(self):
if self.terms is None:
return

for count, term in enumerate(self.terms):
checked = self.isChecked(term)
id = '%s-%i' % (self.id, count)
Expand All @@ -76,16 +71,21 @@ def update(self):
default=term.title)
else:
label = util.toUnicode(term.value)
self.items.append(
{'id':id, 'name':self.name, 'value':term.token,
'label':label, 'checked':checked})
yield {'id': id, 'name': self.name, 'value': term.token,
'label': label, 'checked': checked}

def update(self):
"""See z3c.form.interfaces.IWidget."""
super(RadioWidget, self).update()
widget.addFieldClass(self)

def json_data(self):
data = super(RadioWidget, self).json_data()
data['options'] = self.items
data['options'] = list(self.items())
data['type'] = 'radio'
return data


@zope.component.adapter(zope.schema.interfaces.IField, interfaces.IFormLayer)
@zope.interface.implementer(interfaces.IFieldWidget)
def RadioFieldWidget(field, request):
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/form/browser/radio.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ the value (which is used as a backup label) contains non-ASCII characters:
>>> terms = SimpleVocabulary.fromValues([b'yes\012', b'no\243'])
>>> widget.terms = terms
>>> widget.update()
>>> pprint(widget.items)
>>> pprint(list(widget.items()))
[{'checked': False,
'id': 'widget-id-0',
'label': 'yes\n',
Expand Down
3 changes: 2 additions & 1 deletion src/z3c/form/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def __contains__(self, value):
zope.schema.interfaces.IChoice,
interfaces.IWidget)
def ChoiceTerms(context, request, form, field, widget):
field = field.bind(context)
if field.context is None:
field = field.bind(context)
terms = field.vocabulary
return zope.component.queryMultiAdapter(
(context, request, form, field, terms, widget),
Expand Down

0 comments on commit dd8c315

Please sign in to comment.