Skip to content

Commit

Permalink
Merge pull request #52 from zopefoundation/browser-items-property-master
Browse files Browse the repository at this point in the history
Turned `items` into a property again on all widgets.
  • Loading branch information
Michael Howitz committed Sep 29, 2016
2 parents b3b8298 + e258f63 commit 32db40c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ CHANGES
3.3.1 (unreleased)
------------------

- Turned ``items`` into a property again on all widgets.
For the select widget it was a method since 2.9.0.
For the radio and checkbox widgets it was a method since 3.2.10.
For orderedselect and multi it was always a property.
Fixes https://github.com/zopefoundation/z3c.form/issues/44
[maurits]

- Fix handling of missing terms in collections. (See version 2.9 describing
this feature.)

Expand All @@ -25,6 +32,8 @@ CHANGES

* added high level integration tests

- Removed ``z3c.coverage`` from ``test`` extra. [gforcada, maurits]


3.2.10 (2016-03-09)
-------------------
Expand Down
3 changes: 2 additions & 1 deletion src/z3c/form/browser/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CheckBoxWidget(widget.HTMLInputWidget, SequenceWidget):
def isChecked(self, term):
return term.token in self.value

@property
def items(self):
if self.terms is None:
return ()
Expand All @@ -64,7 +65,7 @@ def update(self):

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

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(list(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/browser/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def renderForValue(self, value):
IPageTemplate, name=self.mode + '_single')
return template(self, item)

@property
def items(self):
if self.terms is None:
return
Expand All @@ -81,7 +82,7 @@ def update(self):

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

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(list(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/browser/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def update(self):
super(SelectWidget, self).update()
widget.addFieldClass(self)

@property
def items(self):
if self.terms is None: # update() has not been called yet
return ()
Expand Down Expand Up @@ -98,7 +99,7 @@ def addItem(idx, term, prefix=''):

def json_data(self):
data = super(SelectWidget, self).json_data()
data['options'] = self.items()
data['options'] = self.items
data['type'] = 'select'
return data

Expand Down

0 comments on commit 32db40c

Please sign in to comment.