Commit bb1a3bf2 authored by Aurel's avatar Aurel

define cache factory

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13084 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7b418fdb
...@@ -86,7 +86,8 @@ def getFieldDescription():\n ...@@ -86,7 +86,8 @@ def getFieldDescription():\n
return property.get(\'description\', \'\')\n return property.get(\'description\', \'\')\n
return desc\n return desc\n
\n \n
getFieldDescription = CachingMethod(getFieldDescription, (\'getFieldDescription\', form_id, field_id), cache_duration=None)\n getFieldDescription = CachingMethod(getFieldDescription, (\'getFieldDescription\', form_id, field_id), \\\n
cache_factory=\'erp5_user_interface_long\')\n
\n \n
return getFieldDescription()\n return getFieldDescription()\n
</string> </value> </string> </value>
...@@ -144,7 +145,6 @@ return getFieldDescription()\n ...@@ -144,7 +145,6 @@ return getFieldDescription()\n
<string>_getattr_</string> <string>_getattr_</string>
<string>field_id</string> <string>field_id</string>
<string>getFieldDescription</string> <string>getFieldDescription</string>
<string>None</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
...@@ -74,7 +74,7 @@ navigation_box_render = CachingMethod(navigation_box_render,\n ...@@ -74,7 +74,7 @@ navigation_box_render = CachingMethod(navigation_box_render,\n
("ERP5Site_renderCachedNavigationBox",\n ("ERP5Site_renderCachedNavigationBox",\n
context.portal_membership.getAuthenticatedMember().getUserName(),\n context.portal_membership.getAuthenticatedMember().getUserName(),\n
context.Localizer.get_selected_language()\n context.Localizer.get_selected_language()\n
),cache_duration=300)\n ),cache_factory=\'erp5_user_interface_short\')\n
return navigation_box_render()\n return navigation_box_render()\n
</string> </value> </string> </value>
</item> </item>
......
...@@ -122,7 +122,7 @@ def getFormGroupTitleAndId():\n ...@@ -122,7 +122,7 @@ def getFormGroupTitleAndId():\n
\n \n
getFormGroupTitleAndId = CachingMethod(getFormGroupTitleAndId,\n getFormGroupTitleAndId = CachingMethod(getFormGroupTitleAndId,\n
("ERP5Site_getFormGroupTitleAndId", form.id, form.get_groups(include_empty=0)),\n ("ERP5Site_getFormGroupTitleAndId", form.id, form.get_groups(include_empty=0)),\n
cache_duration=None)\n cache_factory=\'erp5_user_interface_long\')\n
return getFormGroupTitleAndId()\n return getFormGroupTitleAndId()\n
</string> </value> </string> </value>
</item> </item>
...@@ -178,7 +178,6 @@ return getFormGroupTitleAndId()\n ...@@ -178,7 +178,6 @@ return getFormGroupTitleAndId()\n
<string>form</string> <string>form</string>
<string>getFormGroupTitleAndId</string> <string>getFormGroupTitleAndId</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>None</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
340 345
\ No newline at end of file \ No newline at end of file
...@@ -140,10 +140,11 @@ class PreferenceMethod(Method) : ...@@ -140,10 +140,11 @@ class PreferenceMethod(Method) :
if found : if found :
return value return value
_getPreference = CachingMethod( _getPreference, _getPreference = CachingMethod( _getPreference,
id='PreferenceTool.CachingMethod.%s' % self._preference_name) id='PreferenceTool.CachingMethod.%s' % self._preference_name,
cache_factory='erp5_user_interface_short')
user_name = getSecurityManager().getUser().getId() user_name = getSecurityManager().getUser().getId()
return _getPreference(user_name=user_name) return _getPreference(user_name=user_name)
class PreferenceTool(BaseTool): class PreferenceTool(BaseTool):
""" """
PreferenceTool manages User Preferences / User profiles. PreferenceTool manages User Preferences / User profiles.
...@@ -206,10 +207,10 @@ class PreferenceTool(BaseTool): ...@@ -206,10 +207,10 @@ class PreferenceTool(BaseTool):
prefs.append(pref) prefs.append(pref)
prefs.sort(lambda b, a: cmp(a.getPriority(), b.getPriority())) prefs.sort(lambda b, a: cmp(a.getPriority(), b.getPriority()))
return prefs return prefs
security.declareProtected(Permissions.View, 'getActivePreference') security.declareProtected(Permissions.View, 'getActivePreference')
def getActivePreference(self) : def getActivePreference(self) :
""" returns the current preference for the user. """ returns the current preference for the user.
Note that this preference may be read only. """ Note that this preference may be read only. """
enabled_prefs = self._getSortedPreferenceList() enabled_prefs = self._getSortedPreferenceList()
if len(enabled_prefs) > 0 : if len(enabled_prefs) > 0 :
...@@ -222,7 +223,7 @@ class PreferenceTool(BaseTool): ...@@ -222,7 +223,7 @@ class PreferenceTool(BaseTool):
""" """
if folder is None: if folder is None:
# as the preference tool is also a Folder, this method is called by # as the preference tool is also a Folder, this method is called by
# page templates to get the list of document templates for self. # page templates to get the list of document templates for self.
folder = self folder = self
# We must set the user_id as a parameter to make sure each # We must set the user_id as a parameter to make sure each
...@@ -236,7 +237,7 @@ class PreferenceTool(BaseTool): ...@@ -236,7 +237,7 @@ class PreferenceTool(BaseTool):
return acceptable_templates return acceptable_templates
_getDocumentTemplateList = CachingMethod(_getDocumentTemplateList, _getDocumentTemplateList = CachingMethod(_getDocumentTemplateList,
'portal_preferences.getDocumentTemplateList', 'portal_preferences.getDocumentTemplateList',
cache_duration=3000) cache_factory='erp5_user_interface_medium')
allowed_content_types = map(lambda pti: pti.id, allowed_content_types = map(lambda pti: pti.id,
folder.allowedContentTypes()) folder.allowedContentTypes())
......
...@@ -170,7 +170,7 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -170,7 +170,7 @@ class OOoDocument(File, ConversionCacheMixin):
def _getServerCoordinate(self): def _getServerCoordinate(self):
""" """
Returns OOo conversion server data from Returns OOo conversion server data from
preferences preferences
""" """
pref = getToolByName(self, 'portal_preferences') pref = getToolByName(self, 'portal_preferences')
...@@ -233,7 +233,8 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -233,7 +233,8 @@ class OOoDocument(File, ConversionCacheMixin):
return [[y,x] for x,y in allowed] # have to reverse tuple order return [[y,x] for x,y in allowed] # have to reverse tuple order
cached_getTargetFormatItemList = CachingMethod(cached_getTargetFormatItemList, cached_getTargetFormatItemList = CachingMethod(cached_getTargetFormatItemList,
id = "OOoDocument_getTargetFormatItemList" ) id = "OOoDocument_getTargetFormatItemList",
cache_factory='erp5_core_short')
return cached_getTargetFormatItemList(self.getContentType()) return cached_getTargetFormatItemList(self.getContentType())
security.declareProtected(Permissions.AccessContentsInformation, 'getTargetFormatList') security.declareProtected(Permissions.AccessContentsInformation, 'getTargetFormatList')
...@@ -292,7 +293,7 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -292,7 +293,7 @@ class OOoDocument(File, ConversionCacheMixin):
sp = self._mkProxy() sp = self._mkProxy()
kw = sp.run_convert(self.getSourceReference(), enc(self._unpackData(self.data))) kw = sp.run_convert(self.getSourceReference(), enc(self._unpackData(self.data)))
self.oo_data = Pdata(dec(kw['data'])) self.oo_data = Pdata(dec(kw['data']))
# now we get text content # now we get text content
text_data = self.extractTextContent() text_data = self.extractTextContent()
self.setTextContent(text_data) self.setTextContent(text_data)
self._setMetaData(kw['meta']) self._setMetaData(kw['meta'])
...@@ -531,5 +532,5 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -531,5 +532,5 @@ class OOoDocument(File, ConversionCacheMixin):
manage_FTPstat = File.manage_FTPstat manage_FTPstat = File.manage_FTPstat
# vim: syntax=python shiftwidth=2 # vim: syntax=python shiftwidth=2
...@@ -179,7 +179,8 @@ class ERP5GroupManager(BasePlugin): ...@@ -179,7 +179,8 @@ class ERP5GroupManager(BasePlugin):
if not NO_CACHE_MODE: if not NO_CACHE_MODE:
_getGroupsForPrincipal = CachingMethod(_getGroupsForPrincipal, _getGroupsForPrincipal = CachingMethod(_getGroupsForPrincipal,
id='ERP5GroupManager_getGroupsForPrincipal') id='ERP5GroupManager_getGroupsForPrincipal',
cache_factory='erp5_core_short')
return _getGroupsForPrincipal( return _getGroupsForPrincipal(
user_name=principal.getId(), user_name=principal.getId(),
......
...@@ -108,7 +108,8 @@ class ERP5UserManager(BasePlugin): ...@@ -108,7 +108,8 @@ class ERP5UserManager(BasePlugin):
return None return None
_authenticateCredentials = CachingMethod(_authenticateCredentials, _authenticateCredentials = CachingMethod(_authenticateCredentials,
id='ERP5UserManager_authenticateCredentials') id='ERP5UserManager_authenticateCredentials',
cache_factory='erp5_core_short')
return _authenticateCredentials( return _authenticateCredentials(
login=credentials.get('login'), login=credentials.get('login'),
password=credentials.get('password'), password=credentials.get('password'),
...@@ -152,7 +153,8 @@ class ERP5UserManager(BasePlugin): ...@@ -152,7 +153,8 @@ class ERP5UserManager(BasePlugin):
return tuple(user_info) return tuple(user_info)
_enumerateUsers = CachingMethod(_enumerateUsers, _enumerateUsers = CachingMethod(_enumerateUsers,
id='ERP5UserManager_enumerateUsers') id='ERP5UserManager_enumerateUsers',
cache_factory='erp5_core_short')
if id is None: if id is None:
id = login id = login
......
...@@ -104,7 +104,7 @@ def _evaluateTales(instance=None, value=None): ...@@ -104,7 +104,7 @@ def _evaluateTales(instance=None, value=None):
econtext = createExpressionContext(instance) econtext = createExpressionContext(instance)
return expression(econtext) return expression(econtext)
evaluateTales = CachingMethod(_evaluateTales, id = 'evaluateTales', cache_duration=300) evaluateTales = CachingMethod(_evaluateTales, id = 'evaluateTales', cache_factory='erp5_core_short')
class Getter(Method): class Getter(Method):
""" """
......
...@@ -467,7 +467,7 @@ class Base( CopyContainer, ...@@ -467,7 +467,7 @@ class Base( CopyContainer,
return getattr(Base.aq_portal_type[ptype], id, None).__of__(self) return getattr(Base.aq_portal_type[ptype], id, None).__of__(self)
return None return None
def manage_historyCompare(self, rev1, rev2, REQUEST, def manage_historyCompare(self, rev1, rev2, REQUEST,
historyComparisonResults=''): historyComparisonResults=''):
return Base.inheritedAttribute('manage_historyCompare')( return Base.inheritedAttribute('manage_historyCompare')(
...@@ -560,7 +560,7 @@ class Base( CopyContainer, ...@@ -560,7 +560,7 @@ class Base( CopyContainer,
'unable to create methods for PreferenceTool', e) 'unable to create methods for PreferenceTool', e)
raise raise
Base.aq_preference_generated = 1 Base.aq_preference_generated = 1
# Always try to return something after generation # Always try to return something after generation
if generated: if generated:
# We suppose that if we reach this point # We suppose that if we reach this point
...@@ -607,11 +607,11 @@ class Base( CopyContainer, ...@@ -607,11 +607,11 @@ class Base( CopyContainer,
""" """
from ZODB.utils import oid_repr from ZODB.utils import oid_repr
return oid_repr(self._p_oid) return oid_repr(self._p_oid)
def getSerial(self): def getSerial(self):
"""Return ODB Serial.""" """Return ODB Serial."""
return self._p_serial return self._p_serial
def getHistorySerial(self): def getHistorySerial(self):
"""Return ODB Serial, in the same format used for history keys""" """Return ODB Serial, in the same format used for history keys"""
return '.'.join([str(x) for x in unpack('>HHHH', self._p_serial)]) return '.'.join([str(x) for x in unpack('>HHHH', self._p_serial)])
...@@ -967,6 +967,7 @@ class Base( CopyContainer, ...@@ -967,6 +967,7 @@ class Base( CopyContainer,
self._aq_dynamic('id') # Make sure _aq_dynamic has been called once self._aq_dynamic('id') # Make sure _aq_dynamic has been called once
if hasattr(Base.aq_portal_type[self.portal_type], accessor_name): if hasattr(Base.aq_portal_type[self.portal_type], accessor_name):
method = getattr(self, accessor_name) method = getattr(self, accessor_name)
LOG("Base.py", 0, "method = %s, name = %s" %(method, accessor_name))
method(value, **kw) method(value, **kw)
return return
if hasattr(Base.aq_portal_type[self.portal_type], public_accessor_name): if hasattr(Base.aq_portal_type[self.portal_type], public_accessor_name):
...@@ -983,7 +984,7 @@ class Base( CopyContainer, ...@@ -983,7 +984,7 @@ class Base( CopyContainer,
else: else:
ERP5PropertyManager._setProperty(self, key, value, type=type) ERP5PropertyManager._setProperty(self, key, value, type=type)
# This should not be there, because this ignore all checks made by # This should not be there, because this ignore all checks made by
# the PropertyManager. If there is problems, please complain to # the PropertyManager. If there is problems, please complain to
# seb@nexedi.com # seb@nexedi.com
#except: #except:
# # This should be removed if we want strict property checking # # This should be removed if we want strict property checking
...@@ -1025,7 +1026,7 @@ class Base( CopyContainer, ...@@ -1025,7 +1026,7 @@ class Base( CopyContainer,
#except ConflictError: #except ConflictError:
# raise # raise
# This should not be there, because this ignore all checks made by # This should not be there, because this ignore all checks made by
# the PropertyManager. If there is problems, please complain to # the PropertyManager. If there is problems, please complain to
# seb@nexedi.com # seb@nexedi.com
#except: #except:
# # This should be removed if we want strict property checking # # This should be removed if we want strict property checking
...@@ -1487,7 +1488,7 @@ class Base( CopyContainer, ...@@ -1487,7 +1488,7 @@ class Base( CopyContainer,
# We have been provided a string # We have been provided a string
path = target path = target
if path.startswith(start_string): path = path[start_string_len:] # Prevent duplicating base category if path.startswith(start_string): path = path[start_string_len:] # Prevent duplicating base category
else: else:
# We have been provided an object # We have been provided an object
# Find the object # Find the object
path = target.getRelativeUrl() path = target.getRelativeUrl()
...@@ -1499,7 +1500,7 @@ class Base( CopyContainer, ...@@ -1499,7 +1500,7 @@ class Base( CopyContainer,
def setDefaultValue(self, id, target, spec=(), filter=None, portal_type=()): def setDefaultValue(self, id, target, spec=(), filter=None, portal_type=()):
self._setDefaultValue(id, target, spec=spec, filter=filter, portal_type=portal_type) self._setDefaultValue(id, target, spec=spec, filter=filter, portal_type=portal_type)
self.reindexObject() self.reindexObject()
security.declareProtected( Permissions.View, '_getDefaultValue' ) security.declareProtected( Permissions.View, '_getDefaultValue' )
def _getDefaultValue(self, id, spec=(), filter=None, portal_type=()): def _getDefaultValue(self, id, spec=(), filter=None, portal_type=()):
path = self._getDefaultCategoryMembership(id, spec=spec, filter=filter, path = self._getDefaultCategoryMembership(id, spec=spec, filter=filter,
...@@ -1607,7 +1608,7 @@ class Base( CopyContainer, ...@@ -1607,7 +1608,7 @@ class Base( CopyContainer,
'getDefaultRelatedProperty' ) 'getDefaultRelatedProperty' )
getDefaultRelatedProperty = _getDefaultRelatedProperty getDefaultRelatedProperty = _getDefaultRelatedProperty
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'_getRelatedPropertyList' ) '_getRelatedPropertyList' )
def _getRelatedPropertyList(self, id, property_name, spec=(), filter=None, def _getRelatedPropertyList(self, id, property_name, spec=(), filter=None,
...@@ -1643,15 +1644,15 @@ class Base( CopyContainer, ...@@ -1643,15 +1644,15 @@ class Base( CopyContainer,
references.append(self.portal_catalog.getObject(uid)) references.append(self.portal_catalog.getObject(uid))
self._setValue(id, references, spec=spec, filter=filter, portal_type=portal_type, keep_default=keep_default) self._setValue(id, references, spec=spec, filter=filter, portal_type=portal_type, keep_default=keep_default)
security.declareProtected( Permissions.ModifyPortalContent, '_setValueUidList' ) security.declareProtected( Permissions.ModifyPortalContent, '_setValueUidList' )
_setValueUids = _setValueUidList # DEPRECATED _setValueUids = _setValueUidList # DEPRECATED
security.declareProtected( Permissions.ModifyPortalContent, 'setValueUidList' ) security.declareProtected( Permissions.ModifyPortalContent, 'setValueUidList' )
def setValueUidList(self, id, uids, spec=(), filter=None, portal_type=(), keep_default=1): def setValueUidList(self, id, uids, spec=(), filter=None, portal_type=(), keep_default=1):
self._setValueUids(id, uids, spec=spec, filter=filter, portal_type=portal_type, keep_default=keep_default) self._setValueUids(id, uids, spec=spec, filter=filter, portal_type=portal_type, keep_default=keep_default)
self.reindexObject() self.reindexObject()
security.declareProtected( Permissions.ModifyPortalContent, 'setValueUidList' ) security.declareProtected( Permissions.ModifyPortalContent, 'setValueUidList' )
setValueUids = setValueUidList # DEPRECATED setValueUids = setValueUidList # DEPRECATED
security.declareProtected( Permissions.ModifyPortalContent, '_setDefaultValueUid' ) security.declareProtected( Permissions.ModifyPortalContent, '_setDefaultValueUid' )
...@@ -1858,7 +1859,7 @@ class Base( CopyContainer, ...@@ -1858,7 +1859,7 @@ class Base( CopyContainer,
security.declareProtected( Permissions.View, 'Title' ) security.declareProtected( Permissions.View, 'Title' )
Title = getTitleOrId Title = getTitleOrId
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getTitleAndId') 'getTitleAndId')
def getTitleAndId(self): def getTitleAndId(self):
...@@ -2314,7 +2315,8 @@ class Base( CopyContainer, ...@@ -2314,7 +2315,8 @@ class Base( CopyContainer,
return getattr(ti, 'acquire_local_roles', True) return getattr(ti, 'acquire_local_roles', True)
cached_getAcquireLocalRoles = CachingMethod(cached_getAcquireLocalRoles, cached_getAcquireLocalRoles = CachingMethod(cached_getAcquireLocalRoles,
id='Base__getAcquireLocalRoles') id='Base__getAcquireLocalRoles',
cache_factory='erp5_core_short')
return cached_getAcquireLocalRoles(portal_type=self.getPortalType()) return cached_getAcquireLocalRoles(portal_type=self.getPortalType())
security.declareProtected(Permissions.View, 'get_local_permissions') security.declareProtected(Permissions.View, 'get_local_permissions')
...@@ -2577,7 +2579,7 @@ class Base( CopyContainer, ...@@ -2577,7 +2579,7 @@ class Base( CopyContainer,
""" """
Provides a quick access to precision without accessing the resource Provides a quick access to precision without accessing the resource
value in ZODB. Here resource is the relative_url of the resource, such as value in ZODB. Here resource is the relative_url of the resource, such as
the result of self.getResource(). the result of self.getResource().
""" """
def cached_getQuantityPrecisionFromResource(resource): def cached_getQuantityPrecisionFromResource(resource):
if resource: if resource:
...@@ -2588,7 +2590,8 @@ class Base( CopyContainer, ...@@ -2588,7 +2590,8 @@ class Base( CopyContainer,
cached_getQuantityPrecisionFromResource = CachingMethod( cached_getQuantityPrecisionFromResource = CachingMethod(
cached_getQuantityPrecisionFromResource, cached_getQuantityPrecisionFromResource,
id='Base_getQuantityPrecisionFromResource') id='Base_getQuantityPrecisionFromResource',
cache_factory='erp5_core_short')
return cached_getQuantityPrecisionFromResource(resource) return cached_getQuantityPrecisionFromResource(resource)
......
...@@ -33,7 +33,7 @@ from CachePlugins.BaseCache import CachedMethodError ...@@ -33,7 +33,7 @@ from CachePlugins.BaseCache import CachedMethodError
from zLOG import LOG, WARNING from zLOG import LOG, WARNING
DEFAULT_CACHE_SCOPE = 'GLOBAL' DEFAULT_CACHE_SCOPE = 'GLOBAL'
DEFAULT_CACHE_FACTORY = 'erp5_user_interface' DEFAULT_CACHE_FACTORY = 'erp5_user_interface_short'
is_cache_initialized = 0 is_cache_initialized = 0
def initializePortalCachingProperties(self): def initializePortalCachingProperties(self):
......
...@@ -37,7 +37,7 @@ class PortalTypeClass(Constraint): ...@@ -37,7 +37,7 @@ class PortalTypeClass(Constraint):
This is usefull to check that all objects of a given portal type are This is usefull to check that all objects of a given portal type are
consistant and that dynamic methods for the portal type can be consistant and that dynamic methods for the portal type can be
attached on the class. attached on the class.
Configuration example: Configuration example:
{ 'id' : 'portal_type_class', { 'id' : 'portal_type_class',
'description' : 'The __class__ must be the same as the portal'\ 'description' : 'The __class__ must be the same as the portal'\
...@@ -91,7 +91,7 @@ class PortalTypeClass(Constraint): ...@@ -91,7 +91,7 @@ class PortalTypeClass(Constraint):
_getClassForPortalTypeCache = CachingMethod( _getClassForPortalTypeCache = CachingMethod(
_getClassForPortalTypeCache, _getClassForPortalTypeCache,
"PortalTypeClass._getClassForPortalTypeCache", "PortalTypeClass._getClassForPortalTypeCache",
cache_duration = 60 * 10 cache_factory = 'erp5_core_medium'
) )
return _getClassForPortalTypeCache(obj.getPortalType()) return _getClassForPortalTypeCache(obj.getPortalType())
...@@ -87,7 +87,7 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -87,7 +87,7 @@ class FolderMixIn(ExtensionClass.Base):
else: else:
new_id = str(id) new_id = str(id)
if portal_type is None: if portal_type is None:
# XXX This feature is very confusing # XXX This feature is very confusing
# And made the code more difficult to update # And made the code more difficult to update
portal_type = container.allowedContentTypes()[0].id portal_type = container.allowedContentTypes()[0].id
...@@ -99,7 +99,7 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -99,7 +99,7 @@ class FolderMixIn(ExtensionClass.Base):
factory_name = 'newTemp%s' %(portal_type.replace(' ', '')) factory_name = 'newTemp%s' %(portal_type.replace(' ', ''))
m = getattr(Document, factory_name) m = getattr(Document, factory_name)
return m(container, new_id) return m(container, new_id)
myType = pt.getTypeInfo(container) myType = pt.getTypeInfo(container)
if myType is not None: if myType is not None:
if not myType.allowType( portal_type ): if not myType.allowType( portal_type ):
...@@ -115,12 +115,12 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -115,12 +115,12 @@ class FolderMixIn(ExtensionClass.Base):
# TODO :the **kw makes it impossible to create content not based on # TODO :the **kw makes it impossible to create content not based on
# ERP5TypeInformation, because factory method often do not support # ERP5TypeInformation, because factory method often do not support
# keywords arguments. # keywords arguments.
new_instance = container[new_id] new_instance = container[new_id]
if kw != {} : new_instance._edit(force_update=1, **kw) if kw != {} : new_instance._edit(force_update=1, **kw)
if immediate_reindex: new_instance.immediateReindexObject() if immediate_reindex: new_instance.immediateReindexObject()
return new_instance return new_instance
security.declareProtected( security.declareProtected(
Permissions.DeletePortalContent, 'deleteContent') Permissions.DeletePortalContent, 'deleteContent')
def deleteContent(self, id): def deleteContent(self, id):
...@@ -144,7 +144,7 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -144,7 +144,7 @@ class FolderMixIn(ExtensionClass.Base):
len(self)+1 to make sure generation works on an empty Folder. len(self)+1 to make sure generation works on an empty Folder.
""" """
return '%X' % (randint(1, 10000 * (len(self) + 1)), ) return '%X' % (randint(1, 10000 * (len(self) + 1)), )
def _generateNextId(self): def _generateNextId(self):
""" """
Get the last generated Id, increment it until no object with generated Get the last generated Id, increment it until no object with generated
...@@ -314,7 +314,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn): ...@@ -314,7 +314,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
manage_options = ( CMFBTreeFolder.manage_options + manage_options = ( CMFBTreeFolder.manage_options +
Historical.manage_options + Historical.manage_options +
CMFCatalogAware.manage_options CMFCatalogAware.manage_options
...@@ -339,7 +339,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn): ...@@ -339,7 +339,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
if self._getOb(id, None) is None : if self._getOb(id, None) is None :
return id return id
return self.generateNewId() return self.generateNewId()
#security.declareProtected( Permissions.DeletePortalContent, 'manage_delObjects' ) #security.declareProtected( Permissions.DeletePortalContent, 'manage_delObjects' )
#manage_delObjects = CopyContainer.manage_delObjects #manage_delObjects = CopyContainer.manage_delObjects
...@@ -689,15 +689,15 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn): ...@@ -689,15 +689,15 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
_getVisibleAllowedContentTypeList = CachingMethod( _getVisibleAllowedContentTypeList = CachingMethod(
_getVisibleAllowedContentTypeList, _getVisibleAllowedContentTypeList,
id=("_getAllowedContentTypeTitleList", user, portal_path, portal_type), id=("_getAllowedContentTypeTitleList", user, portal_path, portal_type),
cache_duration=None) cache_factory='erp5_core_long')
return _getVisibleAllowedContentTypeList() return _getVisibleAllowedContentTypeList()
security.declarePublic('allowedContentTypes') security.declarePublic('allowedContentTypes')
def allowedContentTypes( self ): def allowedContentTypes( self ):
""" List portal_types which can be added in this folder / object. """ List portal_types which can be added in this folder / object.
Cache results. Cache results.
Only paths are cached, because we must not cache objects. Only paths are cached, because we must not cache objects.
This makes the result, even if based on cache, O(n) so it becomes quite This makes the result, even if based on cache, O(n) so it becomes quite
costly with many allowed content types. costly with many allowed content types.
Example: Example:
on Person (12 allowed content types): 1000 calls take 3s. on Person (12 allowed content types): 1000 calls take 3s.
...@@ -717,7 +717,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn): ...@@ -717,7 +717,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
if not getSecurityManager().checkPermission( if not getSecurityManager().checkPermission(
Permissions.AddPortalContent, self): Permissions.AddPortalContent, self):
return [] return []
def _allowedContentTypes( portal_type=None, user=None, portal_path=None ): def _allowedContentTypes( portal_type=None, user=None, portal_path=None ):
# Sort the list for convenience -yo # Sort the list for convenience -yo
# XXX This is not the best solution, because this does not take # XXX This is not the best solution, because this does not take
...@@ -727,7 +727,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn): ...@@ -727,7 +727,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
type_list = CMFBTreeFolder.allowedContentTypes(self) type_list = CMFBTreeFolder.allowedContentTypes(self)
type_list.sort(compareTypes) type_list.sort(compareTypes)
return ['/'.join(x.getPhysicalPath()) for x in type_list] return ['/'.join(x.getPhysicalPath()) for x in type_list]
_allowedContentTypes = CachingMethod( _allowedContentTypes, _allowedContentTypes = CachingMethod( _allowedContentTypes,
id = 'allowedContentTypes', id = 'allowedContentTypes',
cache_duration = None) cache_duration = None)
...@@ -874,7 +874,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn): ...@@ -874,7 +874,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
""" """
return self.getPortalObject().portal_preferences\ return self.getPortalObject().portal_preferences\
.getDocumentTemplateList(self) .getDocumentTemplateList(self)
security.declareProtected(Permissions.ModifyPortalContent, 'makeTemplate') security.declareProtected(Permissions.ModifyPortalContent, 'makeTemplate')
def makeTemplate(self): def makeTemplate(self):
""" """
...@@ -899,7 +899,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn): ...@@ -899,7 +899,7 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
for o in self.objectValues(): for o in self.objectValues():
if getattr(aq_base(o), 'makeTemplateInstance', None) is not None: if getattr(aq_base(o), 'makeTemplateInstance', None) is not None:
o.makeTemplateInstance() o.makeTemplateInstance()
def _delObject(self, id, dp=1): def _delObject(self, id, dp=1):
""" """
_delObject is redefined here in order to make sure _delObject is redefined here in order to make sure
......
...@@ -1016,7 +1016,7 @@ class Catalog( Folder, ...@@ -1016,7 +1016,7 @@ class Catalog( Folder,
keys = keys.keys() keys = keys.keys()
keys.sort() keys.sort()
return keys return keys
return CachingMethod(_getColumnIds, id='SQLCatalog.getColumnIds', cache_duration=None)() return CachingMethod(_getColumnIds, id='SQLCatalog.getColumnIds', cache_factory='erp5_core_long')()
def getColumnMap(self): def getColumnMap(self):
""" """
...@@ -1035,7 +1035,7 @@ class Catalog( Folder, ...@@ -1035,7 +1035,7 @@ class Catalog( Folder,
if not keys.has_key(key): keys[key] = [] if not keys.has_key(key): keys[key] = []
keys[key].append(table) # Is this inconsistent ? keys[key].append(table) # Is this inconsistent ?
return keys return keys
return CachingMethod(_getColumnMap, id='SQLCatalog.getColumnMap', cache_duration=None)() return CachingMethod(_getColumnMap, id='SQLCatalog.getColumnMap', cache_factory='erp5_core_long')()
def getResultColumnIds(self): def getResultColumnIds(self):
""" """
...@@ -1696,7 +1696,7 @@ class Catalog( Folder, ...@@ -1696,7 +1696,7 @@ class Catalog( Folder,
%(table_index, table)) %(table_index, table))
return table_index return table_index
return CachingMethod(_getTableIndex, id='SQLCatalog.getTableIndex', \ return CachingMethod(_getTableIndex, id='SQLCatalog.getTableIndex', \
cache_duration=None)(table=table) cache_factory='erp5_core_long')(table=table)
def getIndex(self, table, column_list): def getIndex(self, table, column_list):
...@@ -1731,7 +1731,7 @@ class Catalog( Folder, ...@@ -1731,7 +1731,7 @@ class Catalog( Folder,
LOG("SQLCatalog.getIndex", ERROR, "best_index = %s for table %s and columns %s" \ LOG("SQLCatalog.getIndex", ERROR, "best_index = %s for table %s and columns %s" \
%(best_index, table, column_list)) %(best_index, table, column_list))
return best_index return best_index
return CachingMethod(_getIndex, id='SQLCatalog.getIndex', cache_duration=None)\ return CachingMethod(_getIndex, id='SQLCatalog.getIndex', cache_factory='erp5_core_long')\
(table=table, column_list=column_list) (table=table, column_list=column_list)
def buildSQLQuery(self, query_table='catalog', REQUEST=None, def buildSQLQuery(self, query_table='catalog', REQUEST=None,
......
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