Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix date conversion when collection context has start/end date queries #404

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/404.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix date conversion between collection query and ``expand_events`` filtering.
[petschki]
9 changes: 8 additions & 1 deletion plone/app/event/browser/event_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ def _expand_events_start_end(self, start, end):
# XXX: This actually fits most needs, but not all. Maybe someone
# wants to come up with some edgecases!
se = dict(start=None, end=None)

def safe_dt(val):
# convert value from DateTime to datetime
if hasattr(val, "asdatetime"):
return val.asdatetime()
return val

if start:
q = start.get("query")
r = start.get("range")
Expand All @@ -238,7 +245,7 @@ def _expand_events_start_end(self, start, end):
r = end.get("range")
if r == "min":
se["start"] = q
return se["start"], se["end"]
return safe_dt(se["start"]), safe_dt(se["end"])

def formatted_date(self, occ):
provider = getMultiAdapter(
Expand Down
28 changes: 28 additions & 0 deletions plone/app/event/tests/test_event_listing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from DateTime import DateTime
from plone.app.event.base import localized_today
from plone.app.event.testing import make_fake_response
from plone.app.event.testing import PAEventDX_INTEGRATION_TESTING
Expand Down Expand Up @@ -151,3 +152,30 @@ def test_no_date_filtering(self):
"mode_day",
]:
self.assertTrue(_class not in out)

@mock.patch("plone.app.event.browser.event_listing.localized_now", new=PN)
@mock.patch("plone.app.event.base.localized_now", new=PN)
def test_end_date_filtering(self):
"""Test date conversion between collection query and 'expand_events'
filtering.
"""
# plone.app.contenttypes ICollection type
self.portal.invokeFactory("Collection", "col_with_date_criterion", title="Col")
collection = self.portal.col_with_date_criterion
collection.query = [
{
"i": "portal_type",
"o": "plone.app.querystring.operation.selection.any",
"v": ["Event", "plone.app.event.dx.event"],
},
{
"i": "end",
"o": "plone.app.querystring.operation.date.largerThan",
"v": DateTime(PN()),
},
]

view = self.portal.col_with_date_criterion.restrictedTraverse("@@event_listing")
view()

self.assertIs(len(self.portal.col_with_date_criterion.results()), 3)