Back to index

plone3  3.1.7
checkout.py
Go to the documentation of this file.
00001 ##################################################################
00002 #
00003 # (C) Copyright 2006 ObjectRealms, LLC
00004 # All Rights Reserved
00005 #
00006 # This file is part of iterate.
00007 #
00008 # iterate is free software; you can redistribute it and/or modify
00009 # it under the terms of the GNU General Public License as published by
00010 # the Free Software Foundation; either version 2 of the License, or
00011 # (at your option) any later version.
00012 #
00013 # iterate is distributed in the hope that it will be useful,
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 # GNU General Public License for more details.
00017 #
00018 # You should have received a copy of the GNU General Public License
00019 # along with iterate; if not, write to the Free Software
00020 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 ##################################################################
00022 
00023 from zope.component import getMultiAdapter, getAdapters
00024 
00025 from Acquisition import aq_inner
00026 from Products.Five.browser import BrowserView
00027 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
00028 from ZODB.POSException import ConflictError
00029 
00030 from Products.statusmessages.interfaces import IStatusMessage
00031 from Products.CMFPlone import PloneMessageFactory as _
00032 
00033 from plone.app.iterate.interfaces import ICheckinCheckoutPolicy
00034 from plone.app.iterate.interfaces import CheckoutException
00035 from plone.app.iterate.interfaces import IWCContainerLocator
00036 from plone.app.iterate.interfaces import IObjectArchiver
00037 
00038 class Checkout(BrowserView):
00039     
00040     template = ViewPageTemplateFile('checkout.pt')
00041     
00042     def containers(self):
00043         """Get a list of potential containers
00044         """
00045         context = aq_inner(self.context)
00046         for name, locator in getAdapters((context,), IWCContainerLocator):
00047             if locator.available:
00048                 yield dict(name=name, locator=locator)
00049     
00050     def __call__(self):
00051         context = aq_inner(self.context)
00052 
00053         containers = list(self.containers())
00054         if len(containers) == 1:
00055             # Special case for when there's only when folder to select
00056             self.request.form['form.button.Checkout'] = 1
00057             self.request.form['checkout_location'] = containers[0]['name']
00058 
00059         # We want to redirect to a specific template, else we might
00060         # end up downloading a file
00061         if self.request.form.has_key('form.button.Checkout'):
00062             control = getMultiAdapter((context, self.request), name=u"iterate_control")
00063             if not control.checkout_allowed():
00064                 raise CheckoutException(u"Not allowed")
00065 
00066             location = self.request.form.get('checkout_location', None)
00067             locator = None
00068             try:
00069                 locator = [c['locator'] for c in self.containers() if c['name'] == location][0]
00070             except IndexError:
00071                 IStatusMessage(self.request).addStatusMessage(_("Cannot find checkout location"), type='stop')
00072                 view_url = context.restrictedTraverse("@@plone_context_state").view_url()
00073                 self.request.response.redirect(view_url)
00074                 return
00075 
00076             policy = ICheckinCheckoutPolicy(context)
00077             wc = policy.checkout(locator())
00078             
00079             # we do this for metadata update side affects which will update lock info
00080             context.reindexObject('review_state')
00081             
00082             IStatusMessage(self.request).addStatusMessage(_("Check-out created"), type='info')
00083             view_url = wc.restrictedTraverse("@@plone_context_state").view_url()
00084             self.request.response.redirect(view_url)
00085         elif self.request.form.has_key('form.button.Cancel'):
00086             view_url = context.restrictedTraverse("@@plone_context_state").view_url()
00087             self.request.response.redirect(view_url)
00088         else:
00089             return self.template()