Commit f66b5fcb authored by Yoshinori Okuji's avatar Yoshinori Okuji

Use CachingMethod in allowedContentTypes.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1040 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a1a34a5f
......@@ -36,6 +36,7 @@ from Products.ERP5Type.Base import Base
from Products.ERP5Type.CopySupport import CopyContainer
from Products.ERP5Type import PropertySheet, Permissions
from Products.ERP5Type.XMLExportImport import Folder_asXML
from Products.ERP5Type.Cache import CachingMethod
from Products.BTreeFolder2.CMFBTreeFolder import CMFBTreeFolder
......@@ -43,9 +44,6 @@ import os
from zLOG import LOG
# Optimized Menu
cached_allowed_content_types = {}
# Dummy Functions for update / upgrade
def dummyFilter(object,REQUEST=None):
return 1
......@@ -249,6 +247,9 @@ be a problem)."""
security.declareProtected( Permissions.ModifyPortalContent, '_edit' )
_edit = Base._edit
#security.declareProtected( Permissions.DeletePortalContent, 'manage_delObjects' )
#manage_delObjects = CopyContainer.manage_delObjects
# Implementation
# security.declarePrivate('_setObject')
# def _setObject(self, id, object, roles=None, user=None, set_owner=1):
......@@ -539,26 +540,20 @@ be a problem)."""
List portal_types which can be added in this folder / object.
Cache results. This requires restarting Zope to update values.
"""
LOG("ERP5Type", 0, "in allowedContentTypes")
user = str(_getAuthenticatedUser(self))
portal_type = self.getPortalType()
if not cached_allowed_content_types.has_key((portal_type, user)):
def _allowedContentTypes(portal_type=None, user=None):
# Sort the list for convenience -yo
# XXX This is not the best solution, because this does not take account i18n into consideration.
# XXX So sorting should be done in skins, after translation is performed.
def compareTypes(a, b): return cmp(a.title or a.id, b.title or b.id)
type_list = CMFBTreeFolder.allowedContentTypes(self)
type_list.sort(compareTypes)
cached_allowed_content_types[(portal_type, user)] = type_list
return cached_allowed_content_types[(portal_type, user)]
return type_list
_allowedContentTypes = CachingMethod(_allowedContentTypes, id='allowedContentTypes', cache_duration = 300)
user = str(_getAuthenticatedUser(self))
portal_type = self.getPortalType()
return _allowedContentTypes(portal_type=portal_type, user=user)
# Flush the cache in Menu System
security.declareProtected(Permissions.ManagePortal, 'emptyCache')
def emptyCache( self ):
"""
Empty the cache of allowed content types in the menu system.
"""
cached_allowed_content_types = {}
# Multiple Inheritance Priority Resolution
_setProperty = Base._setProperty
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment