Skip to content

Commit

Permalink
Merge pull request #400 from plone/erral-issue-399
Browse files Browse the repository at this point in the history
Fix calendar portlet to work when selected item is a Collection
  • Loading branch information
davisagli authored Jul 24, 2024
2 parents a98840d + bfee507 commit 3608882
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/399.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix calendar portlet to work when selected item is a Collection [erral]
9 changes: 3 additions & 6 deletions plone/app/event/portlets/portlet_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,9 @@ def cal_data(self):
sort_order=None,
)

# restrict start/end with those from query, if given.
if "start" in query and query["start"] > start:
start = query["start"]
if "end" in query and query["end"] < end:
end = query["end"]

# When having a collection as context, we should use the configured query
# except the start and the end, which should be
# taken from the current calendar start and end
start, end = _prepare_range(self.search_base, start, end)
query.update(start_end_query(start, end))
events = self.search_base.results(
Expand Down
106 changes: 106 additions & 0 deletions plone/app/event/tests/test_portlet_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,109 @@ def test_invalid_request(self):
r.update()
today = localized_today(self.portal)
self.assertEqual(r.year_month_display(), (today.year, today.month))

def test_with_collection_as_source(self):
"""When selecting a Collection as source, the events in that collection
are used to build the calendar
"""
tz = pytz.timezone(TZNAME)
start = tz.localize(datetime.now())
end = start + timedelta(hours=1)

createContentInContainer(self.portal, PTYPE, title="e1", start=start, end=end)

createContentInContainer(self.portal, PTYPE, title="e2", start=start, end=end)

# starts yesterday, ends yesterday
start_yesterday = tz.localize(datetime.now() - timedelta(days=1))
end_yesterday = start + timedelta(hours=1)

createContentInContainer(
self.portal,
PTYPE,
title="e3",
start=start_yesterday,
end=end_yesterday,
)

# starts today, ends tomorrow
start_today = tz.localize(datetime.now())
end_tomorrow = start + timedelta(days=1)

createContentInContainer(
self.portal,
PTYPE,
title="e4",
start=start_today,
end=end_tomorrow,
)

# starts yesterday, ends tomorrow
start_yesterday = tz.localize(datetime.now() - timedelta(days=1))
end_tomorrow = tz.localize(datetime.now()) + timedelta(days=1)

createContentInContainer(
self.portal,
PTYPE,
title="e5",
start=start_yesterday,
end=end_tomorrow,
)

# starts tomorrow, ends tomorrow + 1
start_tomorrow = tz.localize(datetime.now() + timedelta(days=1))
end_tomorrow_1 = start_tomorrow + timedelta(days=1)

createContentInContainer(
self.portal,
PTYPE,
title="e6",
start=start_tomorrow,
end=end_tomorrow_1,
)

# self.wft.doActionFor(self.portal.e1, "publish")
self.wft.doActionFor(self.portal.e2, "publish")
self.wft.doActionFor(self.portal.e3, "publish")
self.wft.doActionFor(self.portal.e4, "publish")
self.wft.doActionFor(self.portal.e5, "publish")
self.wft.doActionFor(self.portal.e6, "publish")

self.portal.invokeFactory(
"Collection",
"eventcollection",
query=[
{
"i": "portal_type",
"o": "plone.app.querystring.operation.selection.any",
"v": [PTYPE],
},
{
"i": "end",
"o": "plone.app.querystring.operation.date.afterToday",
"v": "",
},
{
"i": "review_state",
"o": "plone.app.querystring.operation.selection.any",
"v": ["published"],
},
],
)

r = self.renderer(
# context=self.portal.eventcollection,
assignment=portlet_calendar.Assignment(
state=("published",),
search_base_uid=self.portal.eventcollection.UID(),
),
)
r.update()
rd = r.render()

self.assertTrue("e1" not in rd)
self.assertTrue("e2" in rd)
self.assertTrue("e3" in rd)
self.assertTrue("e4" in rd)
self.assertTrue("e5" in rd)
self.assertTrue("e6" in rd)

0 comments on commit 3608882

Please sign in to comment.