Back to index

plone3  3.1.7
PortalContent.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ PortalContent: Base class for all CMF content.
00014 
00015 $Id: PortalContent.py 77186 2007-06-28 19:06:19Z yuppie $
00016 """
00017 
00018 from AccessControl import ClassSecurityInfo
00019 from Acquisition import aq_base
00020 from Globals import InitializeClass
00021 from OFS.SimpleItem import SimpleItem
00022 from webdav.WriteLockInterface import WriteLockInterface as z2IWriteLock
00023 from zope.interface import implements
00024 
00025 from CMFCatalogAware import CMFCatalogAware
00026 from DynamicType import DynamicType
00027 from exceptions import NotFound
00028 from exceptions import ResourceLockedError
00029 from interfaces import IContentish
00030 from interfaces.Contentish import Contentish as z2IContentish
00031 from permissions import FTPAccess
00032 from permissions import View
00033 from utils import Message as _
00034 
00035 
00036 class PortalContent(DynamicType, CMFCatalogAware, SimpleItem):
00037 
00038     """ Base class for portal objects.
00039 
00040         Provides hooks for reviewing, indexing, and CMF UI.
00041 
00042         Derived classes must implement the interface described in
00043         interfaces/DublinCore.py.
00044     """
00045 
00046     implements(IContentish)
00047     __implements__ = (z2IContentish, z2IWriteLock, DynamicType.__implements__)
00048 
00049     manage_options = ( ( { 'label'  : 'Dublin Core'
00050                          , 'action' : 'manage_metadata'
00051                          }
00052                        , { 'label'  : 'Edit'
00053                          , 'action' : 'manage_edit'
00054                          }
00055                        , { 'label'  : 'View'
00056                          , 'action' : 'view'
00057                          }
00058                        )
00059                      + CMFCatalogAware.manage_options
00060                      + SimpleItem.manage_options
00061                      )
00062 
00063     security = ClassSecurityInfo()
00064 
00065     security.declareObjectProtected(View)
00066 
00067     # The security for FTP methods aren't set up by default in our
00068     # superclasses...  :(
00069     security.declareProtected(FTPAccess, 'manage_FTPstat')
00070     security.declareProtected(FTPAccess, 'manage_FTPlist')
00071 
00072     def failIfLocked(self):
00073         """ Check if isLocked via webDav.
00074         """
00075         if self.wl_isLocked():
00076             raise ResourceLockedError(_(u'This resource is locked via '
00077                                         u'webDAV.'))
00078         return 0
00079 
00080     #
00081     #   Contentish interface methods
00082     #
00083     security.declareProtected(View, 'SearchableText')
00084     def SearchableText(self):
00085         """ Returns a concatination of all searchable text.
00086 
00087         Should be overriden by portal objects.
00088         """
00089         return "%s %s" % (self.Title(), self.Description())
00090 
00091     def __call__(self):
00092         """ Invokes the default view.
00093         """
00094         ti = self.getTypeInfo()
00095         method_id = ti and ti.queryMethodID('(Default)', context=self)
00096         if method_id and method_id!='(Default)':
00097             method = getattr(self, method_id)
00098             if getattr(aq_base(method), 'isDocTemp', 0):
00099                 return method(self, self.REQUEST, self.REQUEST['RESPONSE'])
00100             else:
00101                 return method()
00102         else:
00103             raise NotFound( 'Cannot find default view for "%s"' %
00104                             '/'.join( self.getPhysicalPath() ) )
00105 
00106 InitializeClass(PortalContent)