Skip to content

Commit

Permalink
When the_object=True, attrName may be a callable.
Browse files Browse the repository at this point in the history
See #PM-4168
  • Loading branch information
gbastien committed Apr 19, 2024
1 parent 91fe501 commit d543927
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Expand Up @@ -5,8 +5,8 @@ Changelog
2.27 (unreleased)
-----------------

- Nothing changed yet.

- When `the_object=True`, `attrName` may be a callable.
[gbastien]

2.26 (2023-11-27)
-----------------
Expand Down
5 changes: 4 additions & 1 deletion src/collective/eeafaceted/z3ctable/columns.py
Expand Up @@ -69,7 +69,10 @@ class BaseColumn(column.GetAttrColumn):
def getValue(self, item):
""" """
if self.the_object:
return safe_unicode(base_getattr(self._getObject(item), self.attrName))
attr = safe_unicode(base_getattr(self._getObject(item), self.attrName))
if callable(attr):
return attr()
return attr
else:
return super(BaseColumn, self).getValue(item)

Expand Down
5 changes: 5 additions & 0 deletions src/collective/eeafaceted/z3ctable/tests/test_columns.py
Expand Up @@ -414,6 +414,11 @@ def test_TheObjectVocabularyColumn(self):
column.vocabulary = "collective.eeafaceted.z3ctable.testingvocabulary"
column.full_vocabulary = "collective.eeafaceted.z3ctable.testingfullvocabulary"
self.assertEqual(column.renderCell(brain), u"Existing v\xe9lue 1")
# if a callable is defined, it is called
self.eea_folder.setTitle([u'existing_key1', u'existing_key2'])
self.eea_folder.reindexObject()
column.attrName = 'Title'
self.assertEqual(column.renderCell(brain), u'Existing v\xe9lue 1, Existing v\xe9lue 2')
# will raise if attrName does not exist
column.attrName = "unknown"
self.assertEqual(column.renderCell(brain), u'-')
Expand Down

0 comments on commit d543927

Please sign in to comment.