From aa74655d5af284b409fc675c5d45a6981e7d83fd Mon Sep 17 00:00:00 2001 From: Gauthier Bastien Date: Fri, 20 Oct 2023 16:43:37 +0200 Subject: [PATCH] In `DateColumn.renderCell`, no need to manage a `DateTime` as it is supported by `api.portal.get_localized_time`. See #MOD-968 --- CHANGES.rst | 5 +++-- src/collective/eeafaceted/z3ctable/columns.py | 5 ++--- .../eeafaceted/z3ctable/tests/test_columns.py | 14 +++++++++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index dc31b7d..24864ee 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ----------------- diff --git a/src/collective/eeafaceted/z3ctable/columns.py b/src/collective/eeafaceted/z3ctable/columns.py index 5199c09..5021634 100644 --- a/src/collective/eeafaceted/z3ctable/columns.py +++ b/src/collective/eeafaceted/z3ctable/columns.py @@ -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 diff --git a/src/collective/eeafaceted/z3ctable/tests/test_columns.py b/src/collective/eeafaceted/z3ctable/tests/test_columns.py index 1bd4513..304cfbd 100644 --- a/src/collective/eeafaceted/z3ctable/tests/test_columns.py +++ b/src/collective/eeafaceted/z3ctable/tests/test_columns.py @@ -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 @@ -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 @@ -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'))