Back to index

plone3  3.1.7
containers.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.interface import implements
00024 from zope.component import adapts
00025 
00026 from Acquisition import aq_inner, aq_parent
00027 from AccessControl import getSecurityManager
00028 from Products.CMFCore.interfaces import IDynamicType
00029 from Products.CMFCore.utils import getToolByName
00030 from Products.CMFCore.permissions import AddPortalContent
00031 
00032 from plone.app.iterate.interfaces import IWCContainerLocator
00033 
00034 class HomeFolderLocator(object):
00035     """Locate the current user's home folder, if possible.
00036     """
00037     implements(IWCContainerLocator)
00038     adapts(IDynamicType)
00039     
00040     def __init__(self, context):
00041         self.context = context
00042     
00043     title = u"Home folder"
00044     
00045     @property
00046     def available(self):
00047         return self() is not None
00048         
00049     def __call__(self):
00050         return getToolByName(self.context, 'portal_membership').getHomeFolder()
00051         
00052 class ParentFolderLocator(object):
00053     """Locate the parent of the context, if the user has the
00054     Add portal content permission.
00055     """
00056     implements(IWCContainerLocator)
00057     adapts(IDynamicType)
00058     
00059     def __init__(self, context):
00060         self.context = context
00061     
00062     title = u"Parent folder"
00063     
00064     @property
00065     def available(self):
00066         return bool(getSecurityManager().checkPermission(AddPortalContent, aq_inner(self.context)))
00067         
00068     def __call__(self):
00069         if not self.available:
00070             return None
00071         return aq_parent(aq_inner(self.context))