本文整理汇总了Python中Products.Archetypes.interfaces.base.IBaseObject.providedBy方法的典型用法代码示例。如果您正苦于以下问题:Python IBaseObject.providedBy方法的具体用法?Python IBaseObject.providedBy怎么用?Python IBaseObject.providedBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products.Archetypes.interfaces.base.IBaseObject
的用法示例。
在下文中一共展示了IBaseObject.providedBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __bobo_traverse__
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def __bobo_traverse__(self, REQUEST, name):
try:
return self.boboTraverse(self.obj, REQUEST, name)
except AttributeError:
if not IBaseObject.providedBy(self.obj):
return self.boboTraverse(getSite(), REQUEST, name)
raise
示例2: findBaseTypes
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def findBaseTypes(klass):
bases = []
if hasattr(klass, '__bases__'):
for b in klass.__bases__:
if IBaseObject.providedBy(b):
bases.append(className(b))
return bases
示例3: update_translated_ids
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def update_translated_ids(obj, event):
if IBaseObject.providedBy(obj) and obj.isTemporary():
return
handler = IMultilanguageURLHandler(event.newParent, None)
old_handler = IMultilanguageURLHandler(event.oldParent, None)
if handler is not None and old_handler is not None:
for lang, id in old_handler.get_translated_ids(event.oldName):
handler.set_translated_id(event.newName, id, lang)
if not event.newParent is event.oldParent and old_handler is not None:
old_handler.remove_translated_ids(event.oldName, False)
示例4: _rawEnum
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def _rawEnum(self, callback, *args, **kwargs):
# Finds all object to check if they are 'referenceable'.
catalog = getToolByName(self, 'portal_catalog')
brains = catalog(dict(id=[]))
for b in brains:
o = b.getObject()
if o is not None:
if IBaseObject.providedBy(o):
callback(o, *args, **kwargs)
else:
log('no object for brain: %s:%s' % (b, b.getURL()))
示例5: getFields
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def getFields(self):
"""
The context should provide IBaseObject
The creation flag shoul be True
The context portal_type should be in the list of types with captcha validation
"""
first_cond = IBaseObject.providedBy(self.context)
second_cond = self.context.checkCreationFlag()
third_cond = self.context.portal_type in self.get_captcha_types()
if first_cond and second_cond and third_cond:
return self._fields
return []
示例6: create
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def create(container=None, type=None, id=None, title=None, strict=True, *args,
**kwargs):
"""Create a new object.
:param container: [required] Container object in which to create the new
object.
:type container: Folderish content object
:param type: [required] Type of the object.
:type type: string
:param id: Id of the object. If the id conflicts with another object in
the container, a suffix will be added to the new object's id. If no id
is provided, automatically generate one from the title. If there is no
id or title provided, raise a ValueError.
:type id: string
:param title: Title of the object. If no title is provided, use id as
the title.
:type title: string
:param strict: When True, the given id will be enforced. If the id is
conflicting with another object in the target container, raise a
KeyError. When False, ``create`` creates a new, non-conflicting id.
:type param: boolean
:returns: Content object
:Example: :ref:`create_content_example`
"""
if not container:
raise ValueError('The ``container`` attribute is required.')
if not type:
raise ValueError('The ``type`` attribute is required.')
if not id and not title:
raise ValueError('You have to provide either the ``id`` or the '
'``title`` attribute')
# Create a temporary id
id = str(random.randint(0, 99999999))
container.invokeFactory(type, id, title=title, **kwargs)
content = container[id]
# Archetypes specific code
if IBaseObject.providedBy(content):
# Will finish Archetypes content item creation process,
# rename-after-creation and such
content.processForm()
# Create a new id from title
chooser = INameChooser(container)
new_id = chooser.chooseName(title, content)
content.aq_parent.manage_renameObject(id, new_id)
return content
示例7: unrestricted_create
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def unrestricted_create(container=None, portal_type=None,
id=None, title=None, transition=None, **kwargs):
"""Create content, bypassing security checks.
XXX: this would be a bit cleaner if we used api.env.adopt_roles,
but it doesn't seem to work properly..
XXX 2: Verbose security needs to be turned on in buildout to make
this method work. WTF! We need to fix this.
:param container: container for the created object
:param portal_type: type of the object to create
:param id: id of the object to create
:param title: title of the object to create
:param transition: name of a workflow transition to perform after
creation
:param kwargs: additional parameters which are passed to the
createContent function (e.g. title, description etc.)
:returns: object that was created
"""
portal_types = api.portal.get_tool("portal_types")
type_info = portal_types.getTypeInfo(portal_type)
content_id = id or str(random.randint(0, 99999999))
obj = type_info._constructInstance(
container, content_id, title=title, **kwargs)
# Archetypes specific code
if IBaseObject.providedBy(obj):
# Will finish Archetypes content item creation process,
# rename-after-creation and such
obj.processForm()
if not id:
# Create a new id from title
chooser = INameChooser(container)
derived_id = id or title
new_id = chooser.chooseName(derived_id, obj)
transaction.savepoint(optimistic=True)
with api.env.adopt_roles(['Manager', 'Member']):
obj.aq_parent.manage_renameObject(content_id, new_id)
# perform a workflow transition
if transition:
with api.env.adopt_roles(['Manager', 'Member']):
api.content.transition(obj, transition=transition)
return obj
示例8: migrateUIDs
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def migrateUIDs(portal, out):
count = 0
uc = getToolByName(portal, UID_CATALOG)
print >>out, 'Migrating uids\n'
# temporary add a new index
if olduididx not in uc.indexes():
uc.addIndex(olduididx, 'FieldIndex', extra=None)
if not olduididx in uc.schema():
uc.addColumn(olduididx)
# clear UID Catalog
uc.manage_catalogClear()
# rebuild UIDS on objects and in catalog
allbrains = portal.portal_catalog()
for brain in allbrains:
# get a uid for each thingie
obj = brain.getObject()
if not IBaseObject.providedBy(obj):
continue # its no Archetype instance, so leave it
objUID = getattr(aq_base(obj), '_uid', None)
if objUID is not None: # continue # not an old style AT?
# this one can be part of the catalog
setattr(obj, olduididx, objUID)
delattr(obj, '_uid')
setattr(obj, UUID_ATTR, None)
obj._register() # creates a new UID
obj._updateCatalog(portal) # to be sure
count += 1
if not count % 10:
print >>out, '.',
# avoid eating up all RAM
if not count % 250:
print >>out, '*',
transaction.savepoint(optimistic=True)
print >>out, '\nDone\n'
if USE_FULL_TRANSACTIONS:
transaction.commit()
else:
transaction.savepoint(optimistic=True)
print >>out, count, "UID's migrated."
示例9: reindex_object
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def reindex_object(obj, recursive=0):
"""reindex the given object.
If 'recursive' is true then also take reindex of all sub-objects.
"""
if not IBaseObject.providedBy(obj):
return
try:
catalog_object(obj)
# Also reindex AT References
if hasattr(obj, 'at_references'):
refs = getattr(obj.at_references, 'objectValues', lambda: ())()
for ref in refs:
catalog_object(ref)
except Exception, err:
logger.warn("Couldn't reindex obj --> %s",
getattr(obj, 'absolute_url', lambda: 'None')())
logger.exception(err)
示例10: update
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def update(self):
self.available = False
if not HAS_ARCHETYPES:
return
self.context = aq_inner(self.context)
replaced_types = [
"ATFolder",
"ATDocument",
"ATFile",
"ATImage",
"ATNewsItem",
"ATLink",
"ATEvent",
"ATBlobImage",
"ATBlobFile",
"Collection",
]
if self.context.meta_type not in replaced_types:
return
if not IBaseObject.providedBy(self.context):
return
context_fti = self.context.getTypeInfo()
if IDexterityFTI.providedBy(context_fti):
self.available = True
示例11: __call__
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def __call__(self):
wrapped = IndexableObjectWrapper(self.context, self.catalog)
text = getattr(wrapped, 'SearchableText')
if safe_callable(text):
text = text()
# Archetypes object: remove id and title
if IBaseObject.providedBy(self.context):
for fieldname in ['id', 'title']:
field = self.context.Schema().getField(fieldname)
if field is None:
continue
method = field.getIndexAccessor(self.context)
value = method()
text = text.replace(value, '', 1)
# other content (e.g. dexterity): remove title
elif IContentish.providedBy(self.context):
text = text.replace(self.context.Title(), '', 1)
# Strip html tags
text = re.sub('<[^<]+?>', '', text)
return text
示例12: create
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def create(
container=None,
type=None,
id=None,
title=None,
safe_id=False,
**kwargs
):
"""Create a new content item.
:param container: [required] Container object in which to create the new
object.
:type container: Folderish content object
:param type: [required] Type of the object.
:type type: string
:param id: Id of the object. If the id conflicts with another object in
the container, a suffix will be added to the new object's id. If no id
is provided, automatically generate one from the title. If there is no
id or title provided, raise a ValueError.
:type id: string
:param title: Title of the object. If no title is provided, use id as
the title.
:type title: string
:param safe_id: When False, the given id will be enforced. If the id is
conflicting with another object in the target container, raise an
InvalidParameterError. When True, choose a new, non-conflicting id.
:type safe_id: boolean
:returns: Content object
:raises:
KeyError,
:class:`~plone.api.exc.MissingParameterError`,
:class:`~plone.api.exc.InvalidParameterError`
:Example: :ref:`content_create_example`
"""
# Create a temporary id if the id is not given
content_id = not safe_id and id or str(random.randint(0, 99999999))
if title:
kwargs['title'] = title
try:
container.invokeFactory(type, content_id, **kwargs)
except UnicodeDecodeError:
# UnicodeDecodeError is a subclass of ValueError,
# so will be swallowed below unless we re-raise it here
raise
except ValueError as e:
if ISiteRoot.providedBy(container):
allowed_types = container.allowedContentTypes()
types = [allowed_type.id for allowed_type in allowed_types]
else:
try:
types = container.getLocallyAllowedTypes()
except AttributeError:
raise InvalidParameterError(
"Cannot add a '%s' object to the container." % type
)
raise InvalidParameterError(
"Cannot add a '{0}' object to the container.\n"
"Allowed types are:\n"
"{1}\n"
"{2}".format(type, '\n'.join(sorted(types)), e.message)
)
content = container[content_id]
# Archetypes specific code
if IBaseObject.providedBy(content):
# Will finish Archetypes content item creation process,
# rename-after-creation and such
content.processForm()
if not id or (safe_id and id):
# Create a new id from title
chooser = INameChooser(container)
derived_id = id or title
new_id = chooser.chooseName(derived_id, content)
# kacee: we must do a partial commit, else the renaming fails because
# the object isn't in the zodb.
# Thus if it is not in zodb, there's nothing to move. We should
# choose a correct id when
# the object is created.
# maurits: tests run fine without this though.
transaction.savepoint(optimistic=True)
content.aq_parent.manage_renameObject(content_id, new_id)
return content
示例13: install_indexes
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def install_indexes(self, out, types):
portal_catalog = catalog = getToolByName(self, 'portal_catalog')
for cls in types:
if 'indexes' not in cls.installMode:
continue
for field in cls.schema.fields():
if not field.index:
continue
if isinstance(field.index, basestring):
index = (field.index,)
elif isinstance(field.index, (tuple, list)):
index = field.index
else:
raise SyntaxError("Invalid Index Specification %r"
% field.index)
for alternative in index:
installed = None
index_spec = alternative.split(':', 1)
use_column = 0
if len(index_spec) == 2 and index_spec[1] in ('schema', 'brains'):
use_column = 1
index_spec = index_spec[0]
accessor = field.getIndexAccessorName()
parts = index_spec.split('|')
# we want to be able to specify which catalog we want to use
# for each index. syntax is
# index=('member_catalog/:schema',)
# portal catalog is used by default if not specified
if parts[0].find('/') > 0:
str_idx = parts[0].find('/')
catalog_name = parts[0][:str_idx]
parts[0] = parts[0][str_idx + 1:]
catalog = getToolByName(self, catalog_name)
else:
catalog = portal_catalog
#####################
# add metadata column
# lets see if the catalog is itself an Archetype:
isArchetype = IBaseObject.providedBy(catalog)
# archetypes based zcatalogs need to provide a different method
# to list its schema-columns to not conflict with archetypes
# schema
hasNewWayMethod = hasattr(catalog, 'zcschema')
hasOldWayMethod = not isArchetype and hasattr(
catalog, 'schema')
notInNewWayResults = hasNewWayMethod and accessor not in catalog.zcschema()
notInOldWayResults = hasOldWayMethod and accessor not in catalog.schema()
if use_column and (notInNewWayResults or notInOldWayResults):
try:
catalog.addColumn(accessor)
except:
import traceback
traceback.print_exc(file=out)
###########
# add index
# if you want to add a schema field without an index
# if not parts[0]:
# continue
for itype in parts:
extras = itype.split(',')
if len(extras) > 1:
itype = extras[0]
props = Extra()
for extra in extras[1:]:
name, value = extra.split('=')
setattr(props, name.strip(), value.strip())
else:
props = None
try:
# Check for the index and add it if missing
catalog.addIndex(accessor, itype,
extra=props)
catalog.manage_reindexIndex(ids=(accessor,))
except:
# FIXME: should only catch "Index Exists"
# damned string exception !
pass
else:
installed = 1
break
if installed:
break
示例14: InvalidParameterError
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
except AttributeError:
raise InvalidParameterError(
"Cannot add a '%s' object to the container." % type
)
raise InvalidParameterError(
"Cannot add a '{0}' object to the container.\n"
"Allowed types are:\n"
"{1}\n"
"{2}".format(type, '\n'.join(sorted(types)), e.message)
)
content = container[content_id]
# Archetypes specific code
if IBaseObject.providedBy(content):
# Will finish Archetypes content item creation process,
# rename-after-creation and such
content.processForm()
if not id or (safe_id and id):
# Create a new id from title
chooser = INameChooser(container)
derived_id = id or title
new_id = chooser.chooseName(derived_id, content)
# kacee: we must do a partial commit, else the renaming fails because
# the object isn't in the zodb.
# Thus if it is not in zodb, there's nothing to move. We should
# choose a correct id when
# the object is created.
# maurits: tests run fine without this though.
示例15: create
# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import providedBy [as 别名]
def create(container=None,
type=None,
id=None,
title=None,
strict=True,
**kwargs):
"""Create a new content item.
:param container: [required] Container object in which to create the new
object.
:type container: Folderish content object
:param type: [required] Type of the object.
:type type: string
:param id: Id of the object. If the id conflicts with another object in
the container, a suffix will be added to the new object's id. If no id
is provided, automatically generate one from the title. If there is no
id or title provided, raise a ValueError.
:type id: string
:param title: Title of the object. If no title is provided, use id as
the title.
:type title: string
:param strict: When True, the given id will be enforced. If the id is
conflicting with another object in the target container, raise a
KeyError. When False, ``create`` creates a new, non-conflicting id.
:type strict: boolean
:returns: Content object
:Example: :ref:`content_create_example`
"""
if not container:
raise ValueError('The ``container`` attribute is required.')
if not type:
raise ValueError('The ``type`` attribute is required.')
if not id and not title:
raise ValueError('You have to provide either the ``id`` or the '
'``title`` attribute')
# Create a temporary id if the id is not given
content_id = strict and id or str(random.randint(0, 99999999))
if title:
kwargs['title'] = title
container.invokeFactory(type, content_id, **kwargs)
content = container[content_id]
# Archetypes specific code
if IBaseObject.providedBy(content):
# Will finish Archetypes content item creation process,
# rename-after-creation and such
content.processForm()
if not id or (not strict and id):
# Create a new id from title
chooser = INameChooser(container)
derived_id = id or title
new_id = chooser.chooseName(derived_id, content)
# kacee: we must do a partial commit, else the renaming fails because
# the object isn't in the zodb.
# Thus if it is not in zodb, there's nothing to move. We should
# choose a correct id when
# the object is created.
# maurits: tests run fine without this though.
transaction.savepoint(optimistic=True)
content.aq_parent.manage_renameObject(content_id, new_id)
return content