Commit d8e79e9d authored by Julien Muchembled's avatar Julien Muchembled

Performance: get tools from the portal instead of relying on acquisition

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39184 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b2177399
......@@ -29,7 +29,6 @@
from zLOG import LOG
from Products.ERP5Type.PsycoWrapper import psyco
from Acquisition import aq_base
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.Accessor.Base import func_code, ATTRIBUTE_PREFIX, evaluateTales, Getter as BaseGetter, Method
from Products.ERP5Type.Accessor import Accessor, AcquiredProperty
......@@ -72,7 +71,7 @@ class TranslatedPropertyGetter(BaseGetter):
default = self._default
if self._language is None:
language = kw.get('language') or getToolByName(instance, 'Localizer').get_selected_language()
language = kw.get('language') or instance.getPortalObject().Localizer.get_selected_language()
else:
language = self._language
try:
......@@ -83,7 +82,7 @@ class TranslatedPropertyGetter(BaseGetter):
value = instance.getProperty(self._property_id)
if domain == '' or (value in ('', None)):
return value
localizer = getToolByName(instance, 'Localizer')
localizer = instance.getPortalObject().Localizer
message_catalog = getattr(localizer, domain, None)
if message_catalog is not None:
return message_catalog.gettext(unicode(value, 'utf8'), lang=self._language).encode('utf8')
......@@ -246,7 +245,7 @@ class TranslatedPropertyTester(Method):
if domain==TRANSLATION_DOMAIN_CONTENT_TRANSLATION:
if self._language is None:
language = kw.get('language') or getToolByName(instance, 'Localizer').get_selected_language()
language = kw.get('language') or instance.getPortalObject().Localizer.get_selected_language()
else:
language = self._language
try:
......
......@@ -26,7 +26,6 @@
#
##############################################################################
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.PsycoWrapper import psyco
from Base import Getter as BaseGetter, Setter as BaseSetter
from warnings import warn
......@@ -54,7 +53,7 @@ class Getter(BaseGetter):
self._key = key
def __call__(self, instance):
portal_workflow = getToolByName(instance, 'portal_workflow')
portal_workflow = instance.getPortalObject().portal_workflow
wf = portal_workflow.getWorkflowById(self._key)
return wf._getWorkflowStateOf(instance, id_only=1)
......@@ -79,7 +78,7 @@ class TitleGetter(BaseGetter):
self._key = key
def __call__(self, instance):
portal_workflow = getToolByName(instance, 'portal_workflow')
portal_workflow = instance.getPortalObject().portal_workflow
wf = portal_workflow.getWorkflowById(self._key)
return wf._getWorkflowStateOf(instance).title
......@@ -90,13 +89,12 @@ class TranslatedGetter(Getter):
"""
def __call__(self, instance):
portal_workflow = getToolByName(instance, 'portal_workflow')
localizer = getToolByName(instance, 'Localizer')
wf = portal_workflow.getWorkflowById(self._key)
portal = instance.getPortalObject()
wf = portal.portal_workflow.getWorkflowById(self._key)
state_id = wf._getWorkflowStateOf(instance, id_only=1)
warn('Translated workflow state getters, such as %s are deprecated' %
self._id, DeprecationWarning)
return localizer.erp5_ui.gettext(state_id).encode('utf8')
return portal.localizer.erp5_ui.gettext(state_id).encode('utf8')
psyco.bind(__call__)
......@@ -106,10 +104,10 @@ class TranslatedTitleGetter(TitleGetter):
"""
def __call__(self, instance):
portal_workflow = getToolByName(instance, 'portal_workflow')
localizer = getToolByName(instance, 'Localizer')
portal = instance.getPortalObject()
localizer = portal.Localizer
wf_id = self._key
wf = portal_workflow.getWorkflowById(wf_id)
wf = portal.portal_workflow.getWorkflowById(wf_id)
selected_language = localizer.get_selected_language()
state_title = wf._getWorkflowStateOf(instance).title
msg_id = '%s [state in %s]' % (state_title, wf_id)
......
......@@ -2647,9 +2647,8 @@ class Base( CopyContainer,
"""
This returns the translated portal_type
"""
portal_type = self.portal_type
localizer = getToolByName(self, 'Localizer')
return localizer.erp5_ui.gettext(portal_type).encode('utf8')
localizer = self.getPortalObject().Localizer
return localizer.erp5_ui.gettext(self.portal_type).encode('utf8')
security.declareProtected(Permissions.AccessContentsInformation, 'getMetaType')
def getMetaType(self):
......
......@@ -25,7 +25,6 @@ from OFS.CopySupport import _cb_encode, _cb_decode, cookie_path
from OFS.CopySupport import sanity_check
from Products.ERP5Type import Permissions
from Acquisition import aq_base, aq_inner, aq_parent
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter
from Products.ERP5Type.Globals import PersistentMapping, MessageDialog
from Products.ERP5Type.Utils import get_request
......@@ -157,11 +156,10 @@ class CopyContainer:
ob = self._getOb(id)
# Make sure there is no activities pending on that object
try:
portal_activities = getToolByName(self, 'portal_activities')
portal_activities = self.getPortalObject().portal_activities
except AttributeError:
# There is no activity tool
portal_activities = None
if portal_activities is not None:
pass # There is no activity tool
else:
if portal_activities.countMessage(path=ob.getPath())>0:
raise ActivityPendingError, 'Sorry, pending activities prevent ' \
+ 'changing id at this current stage'
......@@ -249,8 +247,8 @@ class CopyContainer:
self_base = aq_base(self)
#LOG("After Clone ",0, "self:%s item:%s" % (repr(self), repr(item)))
#LOG("After Clone ",0, "self:%s item:%s" % (repr(self), repr(self.getPortalObject().objectIds())))
portal_catalog = getToolByName(self.getPortalObject(), 'portal_catalog')
self_base.uid = portal_catalog.newUid()
portal = self.getPortalObject()
self_base.uid = portal.portal_catalog.newUid()
# Give the Owner local role to the current user, zope only does this if no
# local role has been defined on the object, which breaks ERP5Security
......@@ -286,7 +284,7 @@ class CopyContainer:
# Add info about copy to edit workflow
REQUEST = get_request()
pw = getToolByName(self, 'portal_workflow')
pw = portal.portal_workflow
if 'edit_workflow' in pw.getChainFor(self)\
and (REQUEST is None or
not REQUEST.get('is_business_template_installation', 0)):
......@@ -362,7 +360,7 @@ class CopyContainer:
Unindex the object from the portal catalog.
"""
if self.isIndexable:
catalog = getToolByName(self, 'portal_catalog', None)
catalog = getattr(self.getPortalObject(), 'portal_catalog', None)
if catalog is not None:
# Make sure there is not activity for this object
self.flushActivity(invoke=0)
......@@ -400,7 +398,7 @@ class CopyContainer:
# Update the modification date.
if getattr(aq_base(self), 'notifyModified', _marker) is not _marker:
self.notifyModified()
catalog = getToolByName(self.getPortalObject(), 'portal_catalog', None)
catalog = getattr(self.getPortalObject(), 'portal_catalog', None)
if catalog is not None:
catalog.moveObject(self, idxs=idxs)
......@@ -511,8 +509,8 @@ class CopyContainer:
def _postDuplicate(self):
self_base = aq_base(self)
portal_catalog = getToolByName(self.getPortalObject(), 'portal_catalog')
self_base.uid = portal_catalog.newUid()
portal = self.getPortalObject()
self_base.uid = portal.portal_catalog.newUid()
# Give the Owner local role to the current user, zope only does this if no
# local role has been defined on the object, which breaks ERP5Security
......
......@@ -33,7 +33,6 @@ from Acquisition import aq_base, aq_parent, aq_inner
from OFS.History import Historical
import ExtensionClass
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.exceptions import AccessControl_Unauthorized
from Products.CMFCore.CMFCatalogAware import CMFCatalogAware
from Products.CMFCore.PortalFolder import ContentFilter
......@@ -1553,7 +1552,7 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn,
def _verifyObjectPaste(self, object, validate_src=1):
# To paste in an ERP5Type folder, we need to check 'Add permission'
# that might be defined on the sub object type information.
pt = getToolByName(self, 'portal_types')
pt = self.getPortalObject().portal_types
subobject_type = pt.getTypeInfo(object)
if subobject_type is not None:
sm = getSecurityManager()
......@@ -1592,10 +1591,10 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn,
CMF 2.2
"""
ti = self.getTypeInfo()
utool = getToolByName(self, 'portal_url')
url = self.getPortalObject().portal_url()
if ti is None:
return '%s/misc_/OFSP/dtmldoc.gif' % utool()
return '%s/%s' % (utool(), ti.getTypeIcon())
return '%s/misc_/OFSP/dtmldoc.gif' % url
return '%s/%s' % (url, ti.getTypeIcon())
# We browse all used class from btree and hbtree and set not implemented
# class if one method defined on a class is not defined on other, thus if
......
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