from Products.Five.browser import BrowserView
from Products.ploneundelete.interfaces import IUndeleteSupport

class UndeleteContainerView(BrowserView):
    def __init__(self, context, request):
        super(UndeleteContainerView, self).__init__(context, request)
        self.undeleter = IUndeleteSupport(context)

    def listDeleted(self):
        return self.undeleter.listDeleted()

    def undelete(self, uids=None):
        req = self.request
        if uids is None:
            uids = req.get('uids', ())
        if not uids:
            self.request.RESPONSE.redirect(self.context.absolute_url() +
                                   '/@@undelete_view?portal_status_message='\
                                   'Please select an object to restore')
        message="You have restored the following items: "
        title_list = []
        for uid in uids:
            meta = self.undeleter.getMetadataFor(uid)
            self.undeleter.undelete(uid)
            title_list.append(meta['title'] or meta['id'])
        message = message + ', '.join(title_list)
        self.request.RESPONSE.redirect(self.context.absolute_url() +
                                       '?portal_status_message=' + message)