Back to index

plone3  3.1.7
confirmation.py
Go to the documentation of this file.
00001 from Acquisition import aq_inner
00002 from Products.Five import BrowserView
00003 from Products.CMFCore.utils import getToolByName, _checkPermission
00004 from Products.CMFCore.permissions import AccessContentsInformation
00005 
00006 from plone.app.linkintegrity.interfaces import ILinkIntegrityInfo
00007 from plone.app.linkintegrity.utils import encodeRequestData
00008 
00009 
00010 class RemoveConfirmationView(BrowserView):
00011 
00012     def __init__(self, context, request):
00013         # since this is a view adapting an exception and a request (instead
00014         # of a regular content object and a request), the exception object
00015         # was passed as the context;  therefore we need to construct a
00016         # proper context in order to render the template in a sane manner;
00017         # to do this we will assume that the desired context was passed as
00018         # the first exception value...
00019         self.exception = context
00020         self.context, = context.args
00021         self.request = request
00022 
00023     def originalRequest(self):
00024         # in order to interrupt the current request with a confirmation
00025         # question about removing the referred to object we need to save
00026         # the original request to be able to possibly continue it later on,
00027         # so we pickle and encode its body and environment...
00028         self.request.stdin.seek(0)
00029         body = self.request.stdin.getvalue()    # zope2 request body...
00030         env = dict(self.request._orig_env)
00031         for key in 'HTTP_AUTHORIZATION', 'HTTP_COOKIE':
00032             if env.has_key(key):
00033                 del env[key]
00034         return encodeRequestData((body, env))
00035 
00036     def integrityBreaches(self):
00037         info = ILinkIntegrityInfo(self.request).getIntegrityBreaches()
00038         byTitle = lambda a,b: cmp(a.Title(), b.Title())
00039         breaches = []
00040         for target, sources in info.items():
00041             breaches.append({
00042                 'title': target.Title(),
00043                 'type': target.getPortalTypeName(),
00044                 'url': target.absolute_url(),
00045                 'sources': sorted(sources, byTitle),
00046             })
00047         return sorted(breaches, lambda a,b: cmp(a['title'], b['title']))
00048 
00049     def isAccessible(self, obj):
00050         return _checkPermission(AccessContentsInformation, obj)
00051 
00052     def confirmedItems(self):
00053         info = ILinkIntegrityInfo(self.request)
00054         targets = info.getIntegrityBreaches().keys()
00055         return info.encodeConfirmedItems(additions=targets)
00056 
00057     def callbackURL(self):
00058         portal = getToolByName(aq_inner(self.context), "portal_url")
00059         return portal() + '/removeConfirmationAction'
00060 
00061     def cancelURL(self):
00062         url = self.request.environ.get('HTTP_REFERER', None)
00063         if url is None:
00064             url = getToolByName(aq_inner(self.context), "portal_url")()
00065         return url
00066