Skip to content

Commit

Permalink
Fix: occurrences indexing (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamico authored Feb 2, 2024
1 parent a14d4d8 commit 204ee16
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
5.4.4 (unreleased)
------------------

- Nothing changed yet.
- Fix: occurrences indexing
[mamico]


5.4.3 (2024-01-30)
Expand Down
24 changes: 16 additions & 8 deletions src/redturtle/volto/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from plone.event.interfaces import IEventAccessor
from plone.event.interfaces import IRecurrenceSupport
from plone.event.recurrence import recurrence_sequence_ical
from plone.event.utils import pydt

# from plone.event.utils import pydt
from Products.CMFPlone.interfaces import IConstrainTypes
from zope.globalrequest import getRequest

Expand Down Expand Up @@ -75,13 +76,20 @@ def occurrences(self, range_start=None, range_end=None):
# but doing it for backwards compatibility as views/templates
# still rely on acquisition-wrapped objects.
def get_obj(start):
if pydt(event_start.replace(microsecond=0)) == start:
# If the occurrence date is the same as the event object, the
# occurrence is the event itself. return it as such.
# Dates from recurrence_sequence_ical are explicitly without
# microseconds, while event.start may contain it. So we have to
# remove it for a valid comparison.
return self.context
# THIS IS THE PATCH
#
# -- questa parte è stata commentata, altrtimenti se lo start date coincide con la data di inizio dell'evento
# -- la funzione ritorna l'evento stesso, invece che la sua occorrenza e l'indice end non contiene
# -- tutte le date di end, ma solo quella dell'evento stesso
#
# if pydt(event_start.replace(microsecond=0)) == start:
# # If the occurrence date is the same as the event object, the
# # occurrence is the event itself. return it as such.
# # Dates from recurrence_sequence_ical are explicitly without
# # microseconds, while event.start may contain it. So we have to
# # remove it for a valid comparison.
# return self.context
# END OF PATCH
return Occurrence(
id=str(start.date()), start=start, end=start + duration
).__of__(self.context)
Expand Down
2 changes: 1 addition & 1 deletion src/redturtle/volto/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<version>4302</version>
<version>4303</version>
<dependencies>
<dependency>profile-plone.volto:default</dependency>
<dependency>profile-plone.app.caching:with-caching-proxy</dependency>
Expand Down
9 changes: 9 additions & 0 deletions src/redturtle/volto/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,12 @@ def to_4302(context):
for brain in brains:
event = brain.getObject()
event.reindexObject(idxs=["start", "end"])


def to_4303(context):
brains = api.content.find(portal_type="Event")
logger.info("Reindexing {} Events".format(len(brains)))

for brain in brains:
event = brain.getObject()
event.reindexObject(idxs=["start", "end"])
11 changes: 10 additions & 1 deletion src/redturtle/volto/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,21 @@
/>

<genericsetup:upgradeStep
title="Rendex start index"
title="Rendex start/end index"
description=""
profile="redturtle.volto:default"
source="4301"
destination="4302"
handler=".upgrades.to_4302"
/>

<genericsetup:upgradeStep
title="Rendex start/end index"
description=""
profile="redturtle.volto:default"
source="4302"
destination="4303"
handler=".upgrades.to_4303"
/>

</configure>

0 comments on commit 204ee16

Please sign in to comment.