Back to index

plone3  3.1.7
Portal.py
Go to the documentation of this file.
00001 from Products.CMFDefault.Portal import CMFSite
00002 
00003 from Products.CMFCore import permissions
00004 from Products.CMFCore.utils import _checkPermission
00005 from Products.CMFCore.utils import getToolByName
00006 from Products.CMFDefault import DublinCore
00007 from Products.CMFDynamicViewFTI.browserdefault import BrowserDefaultMixin
00008 from Products.CMFPlone import PloneMessageFactory as _
00009 from Products.CMFPlone.PloneFolder import OrderedContainer
00010 
00011 import Globals
00012 
00013 from AccessControl import ClassSecurityInfo
00014 from AccessControl import Unauthorized
00015 from Acquisition import aq_base
00016 from ComputedAttribute import ComputedAttribute
00017 from webdav.NullResource import NullResource
00018 from Products.CMFPlone.PloneFolder import ReplaceableWrapper
00019 from Products.CMFPlone.interfaces import IPloneSiteRoot
00020 
00021 from plone.i18n.locales.interfaces import IMetadataLanguageAvailability
00022 from zope.interface import implements
00023 from zope.component import queryUtility
00024 
00025 member_indexhtml="""\
00026 member_search=context.restrictedTraverse('member_search_form')
00027 return member_search()
00028 """
00029 
00030 class PloneSite(CMFSite, OrderedContainer, BrowserDefaultMixin):
00031     """
00032     Make PloneSite subclass CMFSite and add some methods.
00033     This will be useful for adding more things later on.
00034     """
00035     security=ClassSecurityInfo()
00036     meta_type = portal_type = 'Plone Site'
00037 
00038     implements(IPloneSiteRoot)
00039 
00040     __implements__ = DublinCore.DefaultDublinCoreImpl.__implements__ + \
00041                      OrderedContainer.__implements__ + \
00042                      BrowserDefaultMixin.__implements__
00043 
00044     manage_renameObject = OrderedContainer.manage_renameObject
00045 
00046     moveObject = OrderedContainer.moveObject
00047     moveObjectsByDelta = OrderedContainer.moveObjectsByDelta
00048 
00049     # Switch off ZMI ordering interface as it assumes a slightly
00050     # different functionality
00051     has_order_support = 0
00052     _default_sort_key = 'id'
00053 
00054     def __browser_default__(self, request):
00055         """ Set default so we can return whatever we want instead
00056         of index_html """
00057         return getToolByName(self, 'plone_utils').browserDefault(self)
00058 
00059     def index_html(self):
00060         """ Acquire if not present. """
00061         request = getattr(self, 'REQUEST', None)
00062         if request and request.has_key('REQUEST_METHOD'):
00063             if request.maybe_webdav_client:
00064                 method = request['REQUEST_METHOD']
00065                 if method in ('PUT',):
00066                     # Very likely a WebDAV client trying to create something
00067                     return ReplaceableWrapper(NullResource(self, 'index_html'))
00068                 elif method in ('GET', 'HEAD', 'POST'):
00069                     # Do nothing, let it go and acquire.
00070                     pass
00071                 else:
00072                     raise AttributeError, 'index_html'
00073         # Acquire from skin.
00074         _target = self.__getattr__('index_html')
00075         return ReplaceableWrapper(aq_base(_target).__of__(self))
00076 
00077     index_html = ComputedAttribute(index_html, 1)
00078 
00079     def manage_beforeDelete(self, container, item):
00080         """ Should send out an Event before Site is being deleted """
00081         self.removal_inprogress=1
00082         PloneSite.inheritedAttribute('manage_beforeDelete')(self, container, item)
00083 
00084     security.declareProtected(permissions.DeleteObjects, 'manage_delObjects')
00085     def manage_delObjects(self, ids=[], REQUEST=None):
00086         """We need to enforce security."""
00087         if isinstance(ids, basestring):
00088             ids = [ids]
00089         for id in ids:
00090             item = self._getOb(id)
00091             if not _checkPermission(permissions.DeleteObjects, item):
00092                 raise Unauthorized, (
00093                     "Do not have permissions to remove this object")
00094         return CMFSite.manage_delObjects(self, ids, REQUEST=REQUEST)
00095 
00096     def _management_page_charset(self):
00097         """ Returns default_charset for management screens """
00098         properties = getToolByName(self, 'portal_properties', None)
00099         # Let's be a bit careful here because we don't want to break the ZMI
00100         # just because people screw up their Plone sites (however thoroughly).
00101         if properties is not None:
00102             site_properties = getattr(properties, 'site_properties', None)
00103             if site_properties is not None:
00104                 getProperty = getattr(site_properties, 'getProperty', None)
00105                 if getProperty is not None:
00106                     return getProperty('default_charset', 'utf-8')
00107         return 'utf-8'
00108 
00109     management_page_charset = ComputedAttribute(_management_page_charset, 1)
00110 
00111     def view(self):
00112         """ Ensure that we get a plain view of the object, via a delegation to
00113         __call__(), which is defined in BrowserDefaultMixin
00114         """
00115         return self()
00116 
00117     security.declareProtected(permissions.AccessContentsInformation,
00118                           'folderlistingFolderContents')
00119     def folderlistingFolderContents(self, contentFilter=None):
00120         """Calls listFolderContents in protected only by ACI so that
00121         folder_listing can work without the List folder contents permission,
00122         as in CMFDefault.
00123 
00124         This is copied from Archetypes Basefolder and is needed by the
00125         reference browser.
00126         """
00127         return self.listFolderContents(contentFilter)
00128 
00129     security.declarePublic('availableLanguages')
00130     def availableLanguages(self):
00131         util = queryUtility(IMetadataLanguageAvailability)
00132         languages = util.getLanguageListing()
00133         languages.sort(lambda x,y:cmp(x[1], y[1]))
00134         # Put language neutral at the top.
00135         languages.insert(0,(u'',_(u'Language neutral (site default)')))
00136         return languages
00137 
00138 Globals.InitializeClass(PloneSite)