Hello,
I’ve been trying to use Plone’s status messages (from Products.statusmessages) to show pop-ups for users on a few screens like the Batch - Batchbook to show messages about that screen.
By default, status messages display on the NEXT screen after being added which was undesirable since the message is based on the current screen (not the workflow leading into the screen). However, there is a show()
function that supposed can be called to display the messages on the current screen. My plan was to use this feature to show a few niche conditional notifications on the Batchbook that would help users on that screen.
My issue is that when I try to use the show()
function during rendering on a Senaite site, the status messages end up not showing up at all (even on the next screen). my guess is that I am calling the function in the wrong location, but I’ve tried calling it during init()
, update()
, folderitems()
, and before_render
, but all gave the same result - no messages show on the screen nor the next screen.
example:
def folderitems(self):
items = super(BatchBookView, self).folderitems()
message = IStatusMessage(self.request)
# Using Products.statusmessages directly
from Products.statusmessages.interfaces import IStatusMessage
# This will show the message on the NEXT screen if `show` is never called.
message.add("Test Message", type="info")
# I would expect this to show the message on the CURRENT screen when called like in Plone
# but it makes nothing show instead. Message cookie expires before render
message.show()
#Same thing happens with the API
from plone import api as plapi
papi.portal.show_message("Test message", request = self.request, type="info")
Anyone have any thoughts, solutions, or known issues? It looks like the statusmessage cookie in the session expires before the screen is rendered when show()
is called directly, so I’m curious if it’s a compatibility issue with the JS in senaite.app.listing
.
I know I could create a custom template macro with the errors callable that way (similar to the Invalidated Sample warning at the top of the Sample view screen), but I’m curious if there’s a way to leverage the show()
function of this core feature to work in Senaite it’s a very convenient and useful API tool for user alerts.