Back to index

plone3  3.1.7
remove.py
Go to the documentation of this file.
00001 from Acquisition import aq_inner
00002 from base64 import b64encode
00003 from StringIO import StringIO
00004 from ZPublisher.Publish import Retry
00005 
00006 from Products.CMFPlone import PloneMessageFactory as _
00007 from Products.Five import BrowserView
00008 from Products.statusmessages.interfaces import IStatusMessage
00009 
00010 from plone.app.linkintegrity.interfaces import ILinkIntegrityInfo
00011 from plone.app.linkintegrity.utils import decodeRequestData
00012 
00013 
00014 class RemoveReferencedObjectView(BrowserView):
00015 
00016     def __init__(self, context, request):
00017         self.context = context
00018         self.request = request
00019 
00020     def __call__(self):
00021         # this view is intended to provide an action called by the
00022         # confirmation form;  all it does is prepare the request for
00023         # the retry exception and raise it...
00024         context = aq_inner(self.context)
00025         request = aq_inner(self.request)
00026         clicked = request.form.has_key
00027         if clicked('delete') or clicked('delete_all'):
00028             # the user choose to actually delete the referred to object,
00029             # so we reconstruct the original request which we interrupted
00030             # before, store the so far confirmed items and retry it...
00031             body, env = decodeRequestData(request.get('original_request'))
00032             marker = ILinkIntegrityInfo(request).getEnvMarker()
00033             if clicked('delete_all'):
00034                 env[marker] = 'all'
00035             else:
00036                 env[marker] = request.get('confirmed_items')
00037             auth = request._authUserPW()
00038             if auth is not None:
00039                 authtoken = b64encode('%s:%s' % auth)
00040                 env['HTTP_AUTHORIZATION'] = 'Basic %s' % authtoken
00041             env['HTTP_COOKIE'] = request.get('HTTP_COOKIE', '')
00042             setattr(request, 'stdin', StringIO(body))
00043             setattr(request, '_orig_env', env)
00044             raise Retry
00045         else:
00046             # the user choose to cancel the removal, in which case we
00047             # redirect back to the original HTTP_REFERER url...
00048             msg = _(u'Removal cancelled.')
00049             IStatusMessage(request).addStatusMessage(msg, type='info')
00050             request.RESPONSE.redirect(request.get('cancel_url'))
00051