Skip to content

Commit

Permalink
In DateColumn.renderCell, no need to manage a DateTime as it is s…
Browse files Browse the repository at this point in the history
…upported by `api.portal.get_localized_time`.

See #MOD-968
  • Loading branch information
gbastien committed Oct 20, 2023
1 parent 4e6d572 commit aa74655
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ Changelog
2.25 (unreleased)
-----------------

- Nothing changed yet.

- In `DateColumn.renderCell`, no need to manage a `DateTime` as it is supported
by `api.portal.get_localized_time`.
[gbastien]

2.24 (2023-10-19)
-----------------
Expand Down
5 changes: 2 additions & 3 deletions src/collective/eeafaceted/z3ctable/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,14 @@ class DateColumn(BaseColumn):

def renderCell(self, item):
value = self.getValue(item)
if isinstance(value, DateTime):
value = value.asdatetime().date()
if not value or value == 'None' or value == self.ignored_value:
return u'-'
if self.use_caching:
res = self._get_cached_result(value)
if res:
return res
res = api.portal.get_localized_time(datetime=value, long_format=self.long_format, time_only=self.time_only)
res = api.portal.get_localized_time(
datetime=value, long_format=self.long_format, time_only=self.time_only)
if self.use_caching:
self._store_cached_result(value, res)
return res
Expand Down
14 changes: 9 additions & 5 deletions src/collective/eeafaceted/z3ctable/tests/test_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from collective.eeafaceted.z3ctable.tests.views import CALL_RESULT
from datetime import date
from datetime import datetime
from DateTime import DateTime
from imio.prettylink.interfaces import IPrettyLink
from plone import api
from plone.app.testing import login
Expand Down Expand Up @@ -86,7 +87,6 @@ def test_BaseColumn(self):
def test_HeaderColumn(self):
"""The header will behave correctly with the faceted query, especially regarding sorting."""
table = self.faceted_z3ctable_view
# use the CreationDateC
column = BaseColumn(self.portal, self.portal.REQUEST, table)
table.nameColumn(column, 'Title')
# if column is sortable, header is rendered with relevant arrows
Expand Down Expand Up @@ -187,15 +187,19 @@ def test_DateColumn(self):
brain = self.portal.portal_catalog(UID=self.eea_folder.UID())[0]
# if no attrName, u'-' is returned
self.assertEqual(column.renderCell(brain), u'-')
# right, use CreationDate as attrName
column.attrName = 'CreationDate'
self.assertIn(column.renderCell(brain), (u'May 05, 2015', '2015-05-05'))
# right, use a DateTime as attrName
self.eea_folder.a_DateTime = DateTime('2023/10/20 15:15')
column.attrName = 'a_DateTime'
column.the_object = True
self.assertEqual(column.renderCell(brain), u'Oct 20, 2023')
column.long_format = True
self.assertEqual(column.renderCell(brain), u'Oct 20, 2023 03:15 PM')
column.the_object = False
# test with an ignored value
column.ignored_value = brain.CreationDate
self.assertEqual(column.renderCell(brain), u'-')
column.ignored_value = None
# test the long_format parameter
column.long_format = True
self.assertIn(column.renderCell(brain), (u'May 05, 2015 12:30 PM', '2015-05-05 12:30'))
column.time_only = True
self.assertIn(column.renderCell(brain), (u'12:30', u'12:30 PM'))
Expand Down

0 comments on commit aa74655

Please sign in to comment.