Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/plone/app/content/browser/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
from Acquisition import aq_inner
from Acquisition import aq_parent
from OFS.CopySupport import CopyError
from plone.app.content.utils import get_recycle_bin_message
from plone.base import PloneMessageFactory as _
from plone.base.interfaces.recyclebin import IRecycleBin
from plone.base.utils import get_user_friendly_types
from plone.base.utils import safe_text
from plone.locking.interfaces import ILockable
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
Expand All @@ -19,6 +22,7 @@
from zope import schema
from zope.component import getMultiAdapter
from zope.component import queryMultiAdapter
from zope.component import queryUtility
from zope.container.interfaces import INameChooser
from zope.event import notify
from zope.interface import Interface
Expand Down Expand Up @@ -85,9 +89,24 @@ def handle_delete(self, action):
# unlock object as it is locked by current user
ILockable(self.context).unlock()
parent.manage_delObjects(self.context.getId())
IStatusMessage(self.request).add(
_("${title} has been deleted.", mapping={"title": title})
)

# Check if recycle bin is enabled and show appropriate message
recycle_bin = queryUtility(IRecycleBin)
recycling_enabled = recycle_bin.is_enabled() if recycle_bin else False

if recycling_enabled:
# Get retention period from registry
registry = queryUtility(IRegistry)
retention_period = registry["recyclebin-controlpanel.retention_period"]

message = get_recycle_bin_message(
title=title, retention_period=retention_period
)
IStatusMessage(self.request).add(message)
else:
IStatusMessage(self.request).add(
_("${title} has been deleted.", mapping={"title": title})
)
else:
IStatusMessage(self.request).add(
_('"${title}" has already been deleted', mapping={"title": title})
Expand Down
21 changes: 20 additions & 1 deletion src/plone/app/content/browser/contents/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
from AccessControl.Permissions import delete_objects
from plone.app.content.browser.contents import ContentsBaseAction
from plone.app.content.interfaces import IStructureAction
from plone.app.content.utils import get_recycle_bin_message
from plone.base import PloneMessageFactory as _
from plone.base.interfaces.recyclebin import IRecycleBin
from plone.locking.interfaces import ILockable
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.component import getMultiAdapter
from zope.component import queryUtility
from zope.component.hooks import getSite
from zope.i18n import translate
from zope.interface import implementer
Expand Down Expand Up @@ -43,9 +47,24 @@ def get_options(self):

class DeleteActionView(ContentsBaseAction):
required_obj_permission = delete_objects
success_msg = _("Successfully delete items")
failure_msg = _("Failed to delete items")

@property
def success_msg(self):
"""Dynamic success message that includes recycle bin information."""
# Check if recycle bin is enabled
recycle_bin = queryUtility(IRecycleBin)
recycling_enabled = recycle_bin.is_enabled() if recycle_bin else False

if not recycling_enabled:
return _("Successfully deleted items")

# Get retention period from registry
registry = queryUtility(IRegistry)
retention_period = registry["recyclebin-controlpanel.retention_period"]

return get_recycle_bin_message(retention_period=retention_period)

def __call__(self):
if self.request.form.get("render") == "yes":
confirm_view = getMultiAdapter(
Expand Down
37 changes: 37 additions & 0 deletions src/plone/app/content/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,40 @@ def json_dumps(data):

# can eventually provide custom handling here if we want
json_loads = simplejson.loads


def get_recycle_bin_message(title=None, retention_period=0):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would turn this into get_deleted_success_message, and also move the check for the recycle bin and the retention period in this function, so it doesn't have to be duplicated either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 6a83a04

sorry @davisagli for responding late!

"""Generate appropriate message for recycled items based on retention period.

Args:
title: The title of the deleted item (optional, for single item messages)
retention_period: Number of days to retain items (0 = indefinite)

Returns:
Translated message string
"""
from plone.base import PloneMessageFactory as _

if title:
# Single item message
if retention_period == 0:
return _(
"${title} has been moved to the recycle bin. It can be restored by administrators.",
mapping={"title": title},
)
else:
return _(
"${title} has been moved to the recycle bin. It can be restored by administrators and will be permanently deleted after ${days} days.",
mapping={"title": title, "days": retention_period},
)
else:
# Multiple items message
if retention_period == 0:
return _(
"Successfully moved items to recycle bin. Items can be restored by administrators."
)
else:
return _(
"Successfully moved items to recycle bin. Items can be restored by administrators and will be permanently deleted after ${days} days.",
mapping={"days": retention_period},
)
Loading