Skip to content

Commit

Permalink
Add booking_refuse_message to stringinterp vars
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Oct 17, 2023
1 parent 2702a46 commit 442d551
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/redturtle/prenotazioni/adapters/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@
for="*"
name="booking_url_with_delete_token"
/>
<adapter
factory=".stringinterp.BookingRefuseMessage"
provides="plone.stringinterp.interfaces.IStringSubstitution"
for="*"
name="booking_refuse_message"
/>

<!-- ical adapters -->
<adapter
Expand Down
31 changes: 31 additions & 0 deletions src/redturtle/prenotazioni/adapters/stringinterp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
from plone import api
from plone.app.event.base import default_timezone
from plone.app.layout.viewlets.content import ContentHistoryViewlet
from plone.stringinterp.adapters import BaseSubstitution
from zope.component import adapter
from zope.globalrequest import getRequest
from zope.interface import Interface

from redturtle.prenotazioni import _, logger
Expand Down Expand Up @@ -238,3 +241,31 @@ class BookingOperatorUrlSubstitution(BaseSubstitution):

def safe_call(self):
return self.context.absolute_url()


@adapter(Interface)
class BookingRefuseMessage(BaseSubstitution):
category = _("Booking")
description = _("The booking refuse message")

def safe_call(self):
content_history_viewlet = ContentHistoryViewlet(
self.context, getRequest(), None, None
)
site_url = api.portal.get().absolute_url()
content_history_viewlet.navigation_root_url = site_url
content_history_viewlet.site_url = site_url
history = content_history_viewlet.fullHistory()
refuse_history = sorted(
[
i
for i in history
if i.get("type", "") == "workflow" and i.get("action", "") == "refuse"
],
key=lambda i: i.get("time"),
reverse=True,
)

refuse_message = refuse_history and refuse_history[0].get("comments") or ""

return refuse_message

0 comments on commit 442d551

Please sign in to comment.