本文整理汇总了Python中plone.app.contenttypes.interfaces.IFile.providedBy方法的典型用法代码示例。如果您正苦于以下问题:Python IFile.providedBy方法的具体用法?Python IFile.providedBy怎么用?Python IFile.providedBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.app.contenttypes.interfaces.IFile
的用法示例。
在下文中一共展示了IFile.providedBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fix_interface_for_file
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def test_fix_interface_for_file(self):
self.obj.portal_type = 'File'
self.catalog.reindexObject(self.obj)
self.portal.restrictedTraverse('fix_base_classes')()
self.assertTrue(IFile.providedBy(self.obj))
示例2: test_factory
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def test_factory(self):
fti = queryUtility(
IDexterityFTI,
name='File'
)
factory = fti.factory
new_object = createObject(factory)
self.failUnless(IFile.providedBy(new_object))
示例3: Format
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def Format(self):
ob = self.getObject()
# TODO: protect adainst acquisition here?
if IFile.providedBy(ob):
mime = ob.file.contentType
else:
mime = getattr(ob, 'format', 'application/octet-stream')
return mime
示例4: is_right_type
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def is_right_type(self, context=None):
if context is None:
context = self.context
if self.enabled()==False and IFile.providedBy(context):
return context.file.contentType in ('application/pdf', 'application/x-pdf', 'image/pdf', 'application/vnd.oasis.opendocument.text-master', 'application/vnd.oasis.opendocument.text', 'application/vnd.wordperfect', 'application/x-wordperfect', 'application/vnd.sun.xml.writer', 'application/wordperfect', 'application/vnd.sun.xml.impress', 'application/vnd.oasis.opendocument.presentation', 'application/vnd.ms-powerpoint', 'application/powerpoint, application/mspowerpoint', 'application/x-mspowerpoint', 'application/rtf', 'application/msword')
else:
return False
示例5: is_printable
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def is_printable(self):
if ILink.providedBy(self.context):
return False
if IFile.providedBy(self.context):
return IIconifiedPreview(self.context).is_convertible()
if IImage.providedBy(self.context):
return True
return True
示例6: test_factory
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def test_factory(self):
fti = queryUtility(
IDexterityFTI,
name='emc.bokeh.codefile'
)
factory = fti.factory
new_object = createObject(factory)
self.assertTrue(IFile.providedBy(new_object))
示例7: test_file_is_migrated
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def test_file_is_migrated(self):
from Products.ATContentTypes.content.file import ATFile
from plone.app.contenttypes.migration.migration import FileMigrator
from plone.app.contenttypes.interfaces import IFile
at_file = self.createATCTobject(ATFile, 'file')
migrator = self.get_migrator(at_file, FileMigrator)
migrator.migrate()
new_file = self.portal['file']
self.assertTrue(IFile.providedBy(new_file))
self.assertTrue(at_file is not new_file)
示例8: _download_url
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def _download_url(self):
"""Return the download url (None by default) for the current object"""
url = u'{url}/@@download'
portal_url = api.portal.get_tool('portal_url')
if IFile.providedBy(self.obj):
return url.format(
url=portal_url.getRelativeUrl(self.context))
if IImage.providedBy(self.obj):
return url.format(
url=portal_url.getRelativeUrl(self.context))
示例9: test_blob_file_is_migrated
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def test_blob_file_is_migrated(self):
from plone.app.contenttypes.migration.migration import BlobFileMigrator
from plone.app.contenttypes.interfaces import IFile
self.portal.invokeFactory('File', 'file')
at_file = self.portal['file']
applyProfile(self.portal, 'plone.app.contenttypes:default')
migrator = self.get_migrator(at_file, BlobFileMigrator)
migrator.migrate()
dx_file = self.portal['file']
self.assertTrue(IFile.providedBy(dx_file))
self.assertTrue(at_file is not dx_file)
示例10: setUp
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def setUp(self):
self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
login(self.portal, TEST_USER_NAME)
# Create files
for uri in self.layer['pdf_files']:
content_id = uri.split('/').pop()
blobfile = NamedBlobFile(filename=unicode(content_id),
data=open(uri, 'r').read())
dxfile = createContentInContainer(
self.portal, 'File', id=content_id, file=blobfile)
self.assertTrue(IFile.providedBy(dxfile))
self._validate_created_files()
logout()
示例11: setUp
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def setUp(self):
self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
login(self.portal, TEST_USER_NAME)
# Create files
for uri in self.layer['pdf_files']:
content_id = uri.split('/').pop()
new_id = self.portal.invokeFactory('File', content_id)
dxfile = self.portal[new_id]
dxfile.file = NamedBlobFile(filename=unicode(content_id),
data=open(uri, 'r').read())
self.assertTrue(IFile.providedBy(dxfile))
self._validate_created_files()
logout()
示例12: myViewSource
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def myViewSource(self, vtype):
"""
"""
doc = self.context
dto = doc.docTypeObj()
app = self.currentApplication()
dtid = doc.getPortalTypeName().lower()
if shasattr(doc, "typeName"):
dtid = doc.typeName()
if dto:
dtid = dto.customViewTemplate
if not dtid:
dtid = dto.getId()
else:
dto = doc # so that we can acquire stuff below
data = ""
if app:
names = [
"%s_%s_%s" % (app, dtid, vtype),
"%s_%s" % (app, vtype),
"%s_%s" % (dtid, vtype),
"doc_%s" % vtype
]
else:
names = [
"%s_%s" % (dtid, vtype),
"doc_%s" % vtype
]
#for n in names:
# print n
for n in names:
if shasattr(dto, n, acquire=True):
o = aq_base(getattr(dto, n))
if IFile.providedBy(o):
f = o.file.open()
data = f.read()
elif IPageTemplateSubclassing.providedBy(o):
data = o.read()
return data
return data
示例13: friendly_type_name
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def friendly_type_name(obj):
"""
Index for the friendly name of any content type
:param obj: The Plone content object to index
:type obj: IContentish
:return: Friendly content type name
:rtype: str
"""
default_name = obj.Type()
# If the object is a file get the friendly name of the mime type
if IFile.providedBy(obj):
mtr = api.portal.get_tool(name='mimetypes_registry')
primary_field_info = IPrimaryFieldInfo(obj)
if not primary_field_info.value:
return default_name
if hasattr(primary_field_info.value, "contentType"):
contenttype = primary_field_info.value.contentType
try:
mimetypeitem = mtr.lookup(contenttype)
except MimeTypeException as msg:
logger.warn(
'mimetype lookup failed for %s. Error: %s',
obj.absolute_url(),
str(msg)
)
return default_name
mimetype_name = mimetypeitem[0].name()
if mimetype_name != contenttype:
return mimetype_name
elif IUserProfile.providedBy(obj):
return 'Person'
return default_name
示例14: test_adding
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def test_adding(self):
self.portal.invokeFactory(
'File',
'doc1'
)
self.assertTrue(IFile.providedBy(self.portal['doc1']))
示例15: _getAllObjectsData
# 需要导入模块: from plone.app.contenttypes.interfaces import IFile [as 别名]
# 或者: from plone.app.contenttypes.interfaces.IFile import providedBy [as 别名]
def _getAllObjectsData(self, context, objects_listing, tfile, tmp=False):
""" Returns the data in all files with a content object to be placed
in a zipfile
"""
props = getToolByName(context, 'portal_properties')
nameByTitle = props.zipfile_properties.name_by_title
allow_zip64 = props.zipfile_properties.allow_zip64
# Use temporary IO object instead of writing to filesystem.
if tmp:
fd, path = tempfile.mkstemp('.zipfiletransport')
tfile = path
close(fd)
zipFile = ZipFile(tfile, 'w', ZIP_DEFLATED, allowZip64=allow_zip64)
context_path = str(context.virtual_url_path())
for obj in objects_listing:
object_extension = ''
object_path = str(obj.virtual_url_path())
file_data = None
if HAS_PAC:
if IImage.providedBy(obj):
file_data = str(obj.image.data)
object_path = object_path.replace(context_path + '/', '')
elif IFile.providedBy(obj):
file_data = str(obj.file.data)
object_path = object_path.replace(context_path + '/', '')
if file_data is not None and object_path is not None:
# early escape coming from plone.app.contenttypes
pass
elif self._objImplementsInterface(obj, interfaces.IATFile) or \
self._objImplementsInterface(obj, interfaces.IATImage):
file_data = str(obj.data)
object_path = object_path.replace(context_path + '/', '')
elif self._objImplementsInterface(obj, interfaces.IATDocument):
if "text/html" == obj.Format():
file_data = obj.getText()
object_extension = ".html"
elif "text/x-rst" == obj.Format():
file_data = obj.getRawText()
object_extension = ".rst"
elif "text/structured" == obj.Format():
file_data = obj.getRawText()
object_extension = ".stx"
elif "text/plain" == obj.Format():
file_data = obj.getRawText()
object_extension = ".txt"
else:
file_data = obj.getRawText()
object_path = object_path.replace(context_path + '/', '')
elif self._objImplementsInterface(obj, interfaces.IATFolder):
if hasattr(obj, 'getRawText'):
file_data = obj.getRawText()
if object_path == context_path:
object_path = object_path.split("/")[-1]
else:
object_path = object_path.replace(context_path + '/', '')
if object_path[-5:] != ".html" and object_path[-4:] != ".htm":
object_extension = ".html"
else:
continue
# start point for object path, adding 1 removes the initial '/'
object_path = self.generateSafeFileName(object_path)
if object_path:
# Reconstruct path with filename, use ID unless
# name_by_title has been set. Name by ID is the
# default behavior so that links to other documents
# in documents will be preserved when the same file
# is imported back into your Plone site. If you use
# name_by_title, you will be able to save non-ascii
# chars in the filename but you will not be able to
# round trip the ZIP archive and have links in your
# documents continue to work. ID is the preferred
# solution, as it is much work to go through lots of
# documents by hand, find the internal links and
# correct them manually.
filename_path = []
for i in range(0, len(object_path.split('/'))):
if nameByTitle:
# Use title for filename in ZIP export
filename_path.append(obj.Title())
else:
filename_path.append(obj.getId())
obj = obj.aq_inner.aq_parent
if len(filename_path) > 1:
filename_path.reverse()
filename_path = '/'.join(filename_path)
#.........这里部分代码省略.........