本文整理汇总了Python中plone.dexterity.interfaces.IDexterityFTI类的典型用法代码示例。如果您正苦于以下问题:Python IDexterityFTI类的具体用法?Python IDexterityFTI怎么用?Python IDexterityFTI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDexterityFTI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_versioning_behavior
def remove_versioning_behavior(self, fti):
if not IDexterityFTI.providedBy(fti):
return
behaviors = list(fti.behaviors)
if self.behavior_name in behaviors:
behaviors.remove(self.behavior_name)
fti.behaviors = behaviors
示例2: installTypeIfNeeded
def installTypeIfNeeded(type_name):
"""Make sure the dexterity-fti is already installed.
If not we create a empty dexterity fti and load the
information from the fti in the profile.
"""
if type_name not in DEFAULT_TYPES:
raise KeyError('{0} is not one of the default types'.format(type_name))
portal = getSite()
tt = getToolByName(portal, 'portal_types')
fti = tt.getTypeInfo(type_name)
if IDexterityFTI.providedBy(fti):
# The dx-type is already installed, so keep it. But this
# might be an old dexterity type of Collection, in which case
# it is better to replace it.
if type_name != 'Collection':
return
if fti.klass == 'plone.app.contenttypes.content.Collection':
# If the klass is fine, we are happy.
return
if fti:
tt.manage_delObjects(type_name)
tt.manage_addTypeInformation('Dexterity FTI', id=type_name)
dx_fti = tt.getTypeInfo(type_name)
ps = getToolByName(portal, 'portal_setup')
profile_info = ps.getProfileInfo('profile-plone.app.contenttypes:default')
profile_path = os.path.join(profile_info['path'])
environ = DirectoryImportContext(ps, profile_path)
parent_path = 'types/'
importObjects(dx_fti, parent_path, environ)
示例3: invalidate
def invalidate(self, fti):
if fti is not None and not IDexterityFTI.providedBy(fti):
# fti is a name, lookup
fti = queryUtility(IDexterityFTI, name=fti)
if fti is not None:
invalidate_cache(fti)
self.invalidations += 1
示例4: add_versioning_behavior
def add_versioning_behavior(self, fti):
if not IDexterityFTI.providedBy(fti):
return
behaviors = list(fti.behaviors)
if self.behavior_name not in behaviors:
behaviors.append(self.behavior_name)
fti.behaviors = behaviors
示例5: __call__
def __call__(self):
req = self.request
if req.REQUEST_METHOD != 'POST':
return
filedata = self.request.form.get("file", None)
if filedata is None:
return
filename = filedata.filename
content_type = mimetypes.guess_type(filename)[0] or ""
if not filedata:
return
# Determine if the default file/image types are DX or AT based
ctr = getToolByName(self.context, 'content_type_registry')
type_ = ctr.findTypeName(filename.lower(), '', '') or 'File'
DX_BASED = False
if HAS_DEXTERITY:
pt = getToolByName(self.context, 'portal_types')
if IDexterityFTI.providedBy(getattr(pt, type_)):
factory = IDXFileFactory(self.context)
DX_BASED = True
else:
factory = IATCTFileFactory(self.context)
else:
factory = IATCTFileFactory(self.context)
obj = factory(filename, content_type, filedata)
if DX_BASED:
if 'File' in obj.portal_type:
size = obj.file.getSize()
content_type = obj.file.contentType
elif 'Image' in obj.portal_type:
size = obj.image.getSize()
content_type = obj.image.contentType
result = {
"type": content_type,
"size": size
}
else:
try:
size = obj.getSize()
except AttributeError:
size = obj.getObjSize()
result = {
"type": obj.getContentType(),
"size": size
}
result.update({
'url': obj.absolute_url(),
'name': obj.getId(),
'uid': IUUID(obj),
'filename': filename
})
return json.dumps(result)
示例6: __call__
def __call__(self, context):
context = getattr(context, 'context', context)
portal = getToolByName(context, 'portal_url').getPortalObject()
items = [SimpleTerm('auto', 'auto', context.translate(_('label_default_portaltype_configuration',
default=u'Default configuration (Content Type Registry).')))]
archetype_tool = getToolByName(context, 'archetype_tool', None)
if archetype_tool:
flt = [_infoDictForType(portal, tipe) for tipe in _listTypesForInterface(portal, IFileContent)]
ilt = [_infoDictForType(portal, tipe) for tipe in _listTypesForInterface(portal, IImageContent)]
items.extend([SimpleTerm(t['portal_type'], t['portal_type'], t['type_ui_info'])
for t in flt])
file_types = [t['portal_type'] for t in flt]
items.extend([SimpleTerm(t['portal_type'], t['portal_type'], t['type_ui_info'])
for t in ilt if t['portal_type'] not in file_types])
for fti in portal.portal_types.objectValues():
if HAS_DEXTERITY and IDexterityFTI.providedBy(fti):
try:
schema = fti.lookupSchema()
except ImportError:
# this dexterity type was changed/removed in an improper way
# no need to punish, just fail gracefully
continue
fields = getFieldsInOrder(schema)
for fieldname, field in fields:
if INamedFileField.providedBy(field) or INamedImageField.providedBy(field):
items.append(SimpleTerm(fti.getId(), fti.getId(), fti.Title()))
break
return SimpleVocabulary(items)
示例7: test_install_dx_type_if_needed
def test_install_dx_type_if_needed(self):
from plone.app.contenttypes.migration.utils import installTypeIfNeeded
tt = self.portal.portal_types
tt.manage_delObjects('Document')
tt.manage_addTypeInformation(
'Factory-based Type Information with dynamic views',
id='Document')
applyProfile(
self.portal,
'plone.app.contenttypes:default',
blacklisted_steps=['typeinfo'])
fti = tt.getTypeInfo('Document')
self.assertFalse(IDexterityFTI.providedBy(fti))
installTypeIfNeeded('Document')
fti = tt.getTypeInfo('Document')
self.assertTrue(IDexterityFTI.providedBy(fti))
示例8: fix_core_behaviors_in_ftis
def fix_core_behaviors_in_ftis(context):
# The behaviors for IRichText and ILeadImage have been renamed.
# All FTIs that use them must be updated accordingly
# See plone/plone.app.contenttypes#480
types_tool = getToolByName(context, 'portal_types')
to_replace = {
'plone.app.contenttypes.behaviors.richtext.IRichText':
'plone.app.contenttypes.behaviors.richtext.IRichTextBehavior',
'plone.app.contenttypes.behaviors.leadimage.ILeadImage':
'plone.app.contenttypes.behaviors.leadimage.ILeadImageBehavior',
}
ftis = types_tool.listTypeInfo()
for fti in ftis:
# Since we're handling dexterity behaviors, we only care about
# dexterity FTIs
if not IDexterityFTI.providedBy(fti):
continue
behaviors = []
change_needed = False
for behavior in fti.behaviors:
if behavior in to_replace:
behavior = to_replace[behavior]
change_needed = True
behaviors.append(behavior)
if change_needed:
fti.behaviors = tuple(behaviors)
示例9: removeBehaviors
def removeBehaviors(context):
"""Remove p.a.multilingual behaviors from p.a.contenttypes types."""
if context.readDataFile('plone.app.multilingual_uninstall.txt') is None:
return
portal = context.getSite()
portal_types = getToolByName(portal, 'portal_types')
behavior = 'plone.app.multilingual.dx.interfaces.IDexterityTranslatable'
# plone.app.contenttype types
typeNames = [
'Document',
'File',
'Folder',
'Image',
'Link',
'News Item',
]
for name in typeNames:
type_ = portal_types.get(name)
# safety first
if not type_ or not IDexterityFTI.providedBy(type_):
continue
behaviors = list(type_.behaviors)
behaviors.remove(behavior)
type_.behaviors = tuple(behaviors)
示例10: __call__
def __call__(self, context):
context = getattr(context, 'context', context)
portal = getToolByName(context, 'portal_url').getPortalObject()
flt = [_infoDictForType(portal, tipe) for tipe in _listTypesForInterface(portal, IFileContent)]
ilt = [_infoDictForType(portal, tipe) for tipe in _listTypesForInterface(portal, IImageContent)]
items = [SimpleTerm('auto', 'auto', context.translate('label_default_portaltype_configuration',
default=u'Default configuration (Content Type Registry).',
domain='collective.quickupload')),]
all_portal_types = []
for t in flt+ilt:
portal_type = t['portal_type']
if portal_type not in all_portal_types:
items.append(SimpleTerm(portal_type, portal_type, t['type_ui_info']))
all_portal_types.append(portal_type)
for fti in portal.portal_types.objectValues():
if HAS_DEXTERITY and IDexterityFTI.providedBy(fti):
fields = getFieldsInOrder(fti.lookupSchema())
for fieldname, field in fields:
if INamedFileField.providedBy(field) or INamedImageField.providedBy(field):
items.append(SimpleTerm(fti.getId(), fti.getId(), fti.Title()))
break
return SimpleVocabulary(items)
示例11: remove_versioning_behavior
def remove_versioning_behavior(self, fti):
if not IDexterityFTI.providedBy(fti):
return
behaviors = list(fti.behaviors)
if self.behavior_name in behaviors:
behaviors.remove(self.behavior_name)
# TODO: remove locking if it wasn't set in first place
fti.behaviors = behaviors
示例12: ftiAdded
def ftiAdded(object, event):
"""When the FTI is created, install local components
"""
if not IDexterityFTI.providedBy(event.object):
return
register(event.object)
示例13: ftiRemoved
def ftiRemoved(object, event):
"""When the FTI is removed, uninstall local coponents
"""
if not IDexterityFTI.providedBy(event.object):
return
unregister(event.object)
示例14: ftiModified
def ftiModified(object, event):
"""When an FTI is modified, re-sync and invalidate the schema, if
necessary.
"""
if not IDexterityFTI.providedBy(event.object):
return
fti = event.object
portal_type = fti.getId()
mod = {}
for desc in event.descriptions:
if IDexterityFTIModificationDescription.providedBy(desc):
mod[desc.attribute] = desc.oldValue
# If the factory utility name was modified, we may get an orphan if one
# was registered as a local utility to begin with. If so, remove the
# orphan.
if 'factory' in mod:
old_factory = mod['factory']
site = getUtility(ISiteRoot)
site_manager = getSiteManager(site)
# Remove previously registered factory, if no other type uses it.
unregister_factory(old_factory, site_manager)
# Register a new local factory if one doesn't exist already
new_factory_utility = queryUtility(IFactory, name=fti.factory)
if new_factory_utility is None:
site_manager.registerUtility(
DexterityFactory(portal_type),
IFactory,
fti.factory,
info='plone.dexterity.dynamic'
)
# Determine if we need to invalidate the schema at all
if 'behaviors' in mod \
or 'schema' in mod \
or 'model_source' in mod \
or 'model_file' in mod \
or 'schema_policy' in mod:
# Determine if we need to re-sync a dynamic schema
if (fti.model_source or fti.model_file) \
and ('model_source' in mod or 'model_file' in mod or 'schema_policy' in mod):
schemaName = portalTypeToSchemaName(portal_type)
schema = getattr(plone.dexterity.schema.generated, schemaName)
model = fti.lookupModel()
sync_bases = 'schema_policy' in mod
syncSchema(model.schema, schema, overwrite=True, sync_bases=sync_bases)
notify(SchemaInvalidatedEvent(portal_type))
示例15: getDexterityTypes
def getDexterityTypes(self):
"""
Returns a list of Dexterity FTIs.
"""
portal_types = getToolByName(self.context, 'portal_types')
for fti in portal_types.listTypeInfo():
if IDexterityFTI.providedBy(fti):
yield fti