Skip to content

Commit

Permalink
add patch to modidify indexing of start index (#87)
Browse files Browse the repository at this point in the history
* add patch to modidify indexing of start index

* isort + zpretty
  • Loading branch information
eikichi18 authored Dec 27, 2023
1 parent 3aacb1a commit 0b4fd93
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/redturtle/volto/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
from Acquisition import aq_base
from plone.app.caching import purge
from plone.app.event.base import dt_start_of_day
from plone.app.event.dx.behaviors import IEventBasic
from plone.app.event.recurrence import Occurrence
from plone.app.multilingual.interfaces import IPloneAppMultilingualInstalled
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 Products.CMFPlone.interfaces import IConstrainTypes
Expand Down Expand Up @@ -60,6 +62,7 @@ def occurrences(self, range_start=None, range_end=None):
else:
duration = event_end - event_start
# END OF PATCH

starts = recurrence_sequence_ical(
event_start,
recrule=event.recurrence,
Expand Down Expand Up @@ -87,6 +90,17 @@ def get_obj(start):
yield get_obj(start)


def _recurrence_upcoming_event(self):
"""Return the next upcoming event"""
adapter = IRecurrenceSupport(self.context)
occs = adapter.occurrences()
try:
return next(occs)
except StopIteration:
# No more future occurrences: passed event
return IEventBasic(self.context)


def _verifyObjectPaste(self, obj, validate_src=True):
self._old__verifyObjectPaste(obj, validate_src=True)
portal_type = getattr(aq_base(obj), "portal_type", None)
Expand Down
7 changes: 7 additions & 0 deletions src/redturtle/volto/monkey.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
description="This fix the problem with Events recurrences"
/>

<monkey:patch
original="_recurrence_upcoming_event"
replacement=".monkey._recurrence_upcoming_event"
class="plone.app.event.dx.behaviors.EventAccessor"
description="This fix the problem with Events recurrences"
/>

<monkey:patch
original="_verifyObjectPaste"
replacement=".monkey._verifyObjectPaste"
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>4300</version>
<version>4301</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 @@ -463,3 +463,12 @@ def to_4200(context):
logger.info("Add redturtle.volto controlpanel")
update_registry(context)
update_controlpanel(context)


def to_4301(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"])
9 changes: 9 additions & 0 deletions src/redturtle/volto/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,13 @@
handler=".setuphandlers.upgrade_robots_txt"
/>

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

</configure>

0 comments on commit 0b4fd93

Please sign in to comment.