本文整理汇总了Python中utils.getToolByName函数的典型用法代码示例。如果您正苦于以下问题:Python getToolByName函数的具体用法?Python getToolByName怎么用?Python getToolByName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getToolByName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: afterCreate
def afterCreate(ob):
wf = getToolByName(ob, 'portal_workflow', None)
if ob is not None:
wf.notifyCreated(ob)
catalog = getToolByName(ob, 'portal_catalog', None)
if catalog is not None:
catalog.reindexObject(ob)
示例2: updateSkinCookie
def updateSkinCookie(self):
'''
If needed, updates the skin cookie based on the member preference.
'''
pm = getToolByName(self, 'portal_membership')
pu = getToolByName(self, 'portal_url')
member = pm.getAuthenticatedMember()
if hasattr(aq_base(member), 'portal_skin'):
mskin = member.portal_skin
if mskin:
req = self.REQUEST
cookie = req.cookies.get(self.request_varname, None)
if cookie != mskin:
resp = req.RESPONSE
portalPath = '/' + pu.getPortalObject().absolute_url(1)
if not self.cookie_persistence:
# *Don't* make the cookie persistent!
resp.setCookie( self.request_varname, mskin, path=portalPath )
else:
expires = ( DateTime( 'GMT' ) + 365 ).rfc822()
resp.setCookie( self.request_varname
, mskin
, path=portalPath
, expires=expires
)
# Ensure updateSkinCookie() doesn't try again
# within this request.
req.cookies[self.request_varname] = mskin
req[self.request_varname] = mskin
return 1
return 0
示例3: __call__
def __call__(self, instance, *args, **kw):
'''
Invokes the method.
'''
wf = getToolByName(instance, 'portal_workflow', None)
if wf is None or not hasattr(wf, 'wrapWorkflowMethod'):
# No workflow tool found.
try:
res = apply(self._m, (instance,) + args, kw)
except ObjectDeleted, ex:
res = ex.getResult()
else:
catalog = getToolByName(instance, 'portal_catalog', None)
if catalog is not None:
catalog.reindexObject(ob)
示例4: searchMemberDataContents
def searchMemberDataContents( self, search_param, search_term ):
""" Search members. This method will be deprecated soon. """
# XXX: this method violates the rules for tools/utilities:
# it depends on a non-utility tool
res = []
if search_param == 'username':
search_param = 'id'
mtool = getToolByName(self, 'portal_membership')
for member_id in self._members.keys():
user_wrapper = mtool.getMemberById( member_id )
if user_wrapper is not None:
memberProperty = user_wrapper.getProperty
searched = memberProperty( search_param, None )
if searched is not None and searched.find(search_term) != -1:
res.append( { 'username': memberProperty( 'id' )
, 'email' : memberProperty( 'email', '' )
}
)
return res
示例5: reindexObjectSecurity
def reindexObjectSecurity(self):
"""
Reindex security-related indexes on the object
(and its descendants).
"""
catalog = getToolByName(self, 'portal_catalog', None)
if catalog is not None:
path = '/'.join(self.getPhysicalPath())
for brain in catalog.unrestrictedSearchResults(path=path):
brain_path = brain.getPath()
# self is treated at the end of the method
# Optimization in case of an indexable container
if brain_path == path:
continue
# Get the object
if hasattr(aq_base(brain), '_unrestrictedGetObject'):
ob = brain._unrestrictedGetObject()
else:
# BBB older Zope
ob = self.unrestrictedTraverse(brain_path, None)
if ob is None:
# Ignore old references to deleted objects.
LOG('reindexObjectSecurity', PROBLEM,
"Cannot get %s from catalog" % brain_path)
continue
s = getattr(ob, '_p_changed', 0)
catalog.reindexObject(ob, idxs=['allowedRolesAndUsers'],
update_metadata=0)
if s is None: ob._p_deactivate()
# Reindex the object itself, as the PathIndex only gave us
# the descendants.
catalog.reindexObject(self, idxs=['allowedRolesAndUsers'],
update_metadata=0)
示例6: manage_doCustomize
def manage_doCustomize(self, folder_path, RESPONSE=None):
"""Makes a ZODB Based clone with the same data.
Calls _createZODBClone for the actual work.
"""
obj = self._createZODBClone()
id = obj.getId()
fpath = tuple(split(folder_path, '/'))
portal_skins = getToolByName(self,'portal_skins')
folder = portal_skins.restrictedTraverse(fpath)
if id in folder.objectIds():
# we cant catch the badrequest so
# we'll that to check before hand, which makes
# sense anyway...
obj = folder._getOb(id)
if RESPONSE is not None:
RESPONSE.redirect('%s/manage_main?manage_tabs_message=%s' % (
obj.absolute_url(), html_quote("An object with this id already exists")
))
else:
folder._verifyObjectPaste(obj, validate_src=0)
folder._setObject(id, obj)
if RESPONSE is not None:
RESPONSE.redirect('%s/%s/manage_main' % (
folder.absolute_url(), id))
示例7: manage_addActionForm
def manage_addActionForm(self):
"""Form for adding a new CMF Action object.
"""
profiles = []
stool = getToolByName(self, 'portal_setup', None)
if stool:
for info in stool.listContextInfos():
action_paths = []
context = stool._getImportContext(info['id'])
body = context.readDataFile('actions.xml')
if body is None:
continue
root = parseString(body).documentElement
for node in root.childNodes:
if node.nodeName != 'object':
continue
action_paths += _extractChildren(node)
action_paths.sort()
profiles.append({'id': info['id'],
'title': info['title'],
'action_paths': tuple(action_paths)})
template = PageTemplateResource('www/addAction.zpt',
globals()).__of__(self)
return template(profiles=tuple(profiles))
示例8: _filteredItems
def _filteredItems( self, ids, filt ):
"""
Apply filter, a mapping, to child objects indicated by 'ids',
returning a sequence of ( id, obj ) tuples.
"""
# Restrict allowed content types
if filt is None:
filt = {}
else:
# We'll modify it, work on a copy.
filt = filt.copy()
pt = filt.get('portal_type', [])
if type(pt) is type(''):
pt = [pt]
types_tool = getToolByName(self, 'portal_types')
allowed_types = types_tool.listContentTypes()
if not pt:
pt = allowed_types
else:
pt = [t for t in pt if t in allowed_types]
if not pt:
# After filtering, no types remain, so nothing should be
# returned.
return []
filt['portal_type'] = pt
query = ContentFilter(**filt)
result = []
append = result.append
get = self._getOb
for id in ids:
obj = get( id )
if query(obj):
append( (id, obj) )
return result
示例9: addMember
def addMember(self, id, password, roles=('Member',), domains='',
properties=None):
'''Creates a PortalMember and returns it. The properties argument
can be a mapping with additional member properties. Raises an
exception if the given id already exists, the password does not
comply with the policy in effect, or the authenticated user is not
allowed to grant one of the roles listed (where Member is a special
role that can always be granted); these conditions should be
detected before the fact so that a cleaner message can be printed.
'''
if not self.isMemberIdAllowed(id):
raise 'Bad Request', 'The login name you selected is already ' \
'in use or is not valid. Please choose another.'
failMessage = self.testPasswordValidity(password)
if failMessage is not None:
raise 'Bad Request', failMessage
failMessage = self.testPropertiesValidity(properties)
if failMessage is not None:
raise 'Bad Request', failMessage
# Limit the granted roles.
# Anyone is always allowed to grant the 'Member' role.
limitGrantedRoles(roles, self, ('Member',))
membership = getToolByName(self, 'portal_membership')
membership.addMember(id, password, roles, domains)
member = membership.getMemberById(id)
if properties is not None:
member.setMemberProperties(properties)
self.afterAdd(member, id, password, properties)
return member
示例10: createExprContext
def createExprContext(folder, portal, object):
'''
An expression context provides names for TALES expressions.
'''
pm = getToolByName(portal, 'portal_membership')
if object is None:
object_url = ''
else:
object_url = object.absolute_url()
if pm.isAnonymousUser():
member = None
else:
member = pm.getAuthenticatedMember()
data = {
'object_url': object_url,
'folder_url': folder.absolute_url(),
'portal_url': portal.absolute_url(),
'object': object,
'folder': folder,
'portal': portal,
'nothing': None,
'request': getattr( object, 'REQUEST', None ),
'modules': SecureModuleImporter,
'member': member,
}
return getEngine().getContext(data)
示例11: getTypeInfo
def getTypeInfo(self):
""" Get the TypeInformation object specified by the portal type.
"""
tool = getToolByName(self, 'portal_types', None)
if tool is None:
return None
return tool.getTypeInfo(self) # Can return None.
示例12: _uuid_unregister
def _uuid_unregister(self, reference_manager=None):
"""remove all references"""
if not reference_manager:
reference_manager = getToolByName(self, REFERENCE_MANAGER, None)
if reference_manager is not None:
reference_manager.unregisterObject(self)
示例13: searchMembers
def searchMembers( self, search_param, search_term ):
""" Search the membership """
# XXX: this method violates the rules for tools/utilities:
# it depends on a non-utility tool
md = getToolByName( self, 'portal_memberdata' )
return md.searchMemberData( search_param, search_term )
示例14: reindexObjectSecurity
def reindexObjectSecurity(self, skip_self=False):
"""Reindex security-related indexes on the object.
Recurses in the children to reindex them too.
If skip_self is True, only the children will be reindexed. This
is a useful optimization if the object itself has just been
fully reindexed, as there's no need to reindex its security twice.
"""
catalog = getToolByName(self, 'portal_catalog', None)
if catalog is None:
return
path = '/'.join(self.getPhysicalPath())
for brain in catalog.unrestrictedSearchResults(path=path):
brain_path = brain.getPath()
if brain_path == path and skip_self:
continue
# Get the object
if hasattr(aq_base(brain), '_unrestrictedGetObject'):
ob = brain._unrestrictedGetObject()
else:
# BBB: Zope 2.7
ob = self.unrestrictedTraverse(brain_path, None)
if ob is None:
# BBB: Ignore old references to deleted objects.
# Can happen only in Zope 2.7, or when using
# catalog-getObject-raises off in Zope 2.8
LOG('reindexObjectSecurity', PROBLEM,
"Cannot get %s from catalog" % brain_path)
continue
# Recatalog with the same catalog uid.
s = getattr(ob, '_p_changed', 0)
catalog.reindexObject(ob, idxs=self._cmf_security_indexes,
update_metadata=0, uid=brain_path)
if s is None: ob._p_deactivate()
示例15: reindexObjectSecurity
def reindexObjectSecurity(self, skip_self=False):
"""
Reindex security-related indexes on the object
(and its descendants).
"""
catalog = getToolByName(self, 'portal_catalog', None)
if catalog is not None:
path = '/'.join(self.getPhysicalPath())
for brain in catalog.unrestrictedSearchResults(path=path):
brain_path = brain.getPath()
# self is treated at the end of the method
# Optimization in case of an indexable container
if brain_path == path:
continue
# Get the object
ob = brain._unrestrictedGetObject()
if ob is None:
# Ignore old references to deleted objects.
LOG('reindexObjectSecurity', PROBLEM,
"Cannot get %s from catalog" % brain_path)
continue
s = getattr(ob, '_p_changed', 0)
catalog.reindexObject(ob, idxs=self._cmf_security_indexes,
update_metadata=0)
if s is None: ob._p_deactivate()
# Reindex the object itself in here if not explicitly
# asked to not to
if not skip_self:
catalog.reindexObject(self, idxs=self._cmf_security_indexes,
update_metadata=0)