本文整理汇总了Python中plone.namedfile.interfaces.INamedImage.providedBy方法的典型用法代码示例。如果您正苦于以下问题:Python INamedImage.providedBy方法的具体用法?Python INamedImage.providedBy怎么用?Python INamedImage.providedBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.namedfile.interfaces.INamedImage
的用法示例。
在下文中一共展示了INamedImage.providedBy方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_newsitem_content_is_migrated
# 需要导入模块: from plone.namedfile.interfaces import INamedImage [as 别名]
# 或者: from plone.namedfile.interfaces.INamedImage import providedBy [as 别名]
def test_newsitem_content_is_migrated(self):
from Products.ATContentTypes.content.newsitem import ATNewsItem
from plone.app.contenttypes.migration import NewsItemMigrator
from plone.app.textfield.interfaces import IRichTextValue
from plone.namedfile.interfaces import INamedImage
# create an ATNewsItem
at_newsitem = self.createATCTobject(ATNewsItem, 'newsitem')
at_newsitem.setText('Tütensuppe')
at_newsitem.setContentType('chemical/x-gaussian-checkpoint')
at_newsitem.setImageCaption('Daniel Düsentrieb')
test_image_data = self.get_test_image_data()
image_field = at_newsitem.getField('image')
image_field.set(at_newsitem, test_image_data)
image_field.setFilename(at_newsitem, 'testimage.png')
# migrate
migrator = self.get_migrator(at_newsitem, NewsItemMigrator)
migrator.migrate()
# assertions
new_newsitem = self.portal['newsitem']
self.assertTrue(INamedImage.providedBy(new_newsitem.image))
self.assertEqual(new_newsitem.image.filename, 'testimage.png')
self.assertEqual(new_newsitem.image.contentType, 'image/png')
self.assertEqual(new_newsitem.image.data, test_image_data)
self.assertEqual(new_newsitem.image_caption, u'Daniel Düsentrieb')
self.assertTrue(IRichTextValue(new_newsitem.text))
self.assertEqual(new_newsitem.text.raw, u'Tütensuppe')
self.assertEqual(new_newsitem.text.mimeType,
'chemical/x-gaussian-checkpoint')
self.assertEqual(new_newsitem.text.outputMimeType, 'text/x-html-safe')
示例2: modified
# 需要导入模块: from plone.namedfile.interfaces import INamedImage [as 别名]
# 或者: from plone.namedfile.interfaces.INamedImage import providedBy [as 别名]
def modified(self):
""" provide a callable to return the modification time of content
items, so stored image scales can be invalidated """
mtime = 0
for k, v in self.context.data.items():
if INamedImage.providedBy(v):
mtime += v._p_mtime
return mtime
示例3: set
# 需要导入模块: from plone.namedfile.interfaces import INamedImage [as 别名]
# 或者: from plone.namedfile.interfaces.INamedImage import providedBy [as 别名]
def set(self, data):
for k, v in data.items():
if INamedImage.providedBy(v):
if (self.key not in self.annotations or
k not in self.annotations[self.key] or
(self.key not in self.annotations and
data[k] != self.annotations[self.key][k])):
# set modification time of the image
data['%s_mtime' % k] = time.mktime(datetime.now().timetuple())
self.annotations[self.key] = PersistentDict(data)
示例4: set
# 需要导入模块: from plone.namedfile.interfaces import INamedImage [as 别名]
# 或者: from plone.namedfile.interfaces.INamedImage import providedBy [as 别名]
def set(self, data):
for k, v in data.items():
if INamedImage.providedBy(v):
if (self.key not in self.annotations or
k not in self.annotations[self.key] or
(self.key in self.annotations and
data[k] != self.annotations[self.key][k])):
# set modification time of the image
notify(Purge(self.tile))
data['{0}_mtime'.format(k)] = '%f' % time.time()
self.annotations[self.key] = PersistentDict(data)
示例5: test_namedimage_setting
# 需要导入模块: from plone.namedfile.interfaces import INamedImage [as 别名]
# 或者: from plone.namedfile.interfaces.INamedImage import providedBy [as 别名]
def test_namedimage_setting(self):
data = 'datattatatata'
filename = FILENAME_TESTSTRING + u".jpeg"
content_type = 'image/jpeg'
fileSetter = self.getFileSetter(ISchemaWithNamedImage)
fileSetter.set(data, filename.encode('utf-8'), content_type)
field = fileSetter.context.field
self.assertTrue(INamedImage.providedBy(field))
self.assertEqual(field.filename, filename)
self.assertEqual(field.contentType, content_type)
self.assertEqual(field.data, data)
示例6: getRelativePaths
# 需要导入模块: from plone.namedfile.interfaces import INamedImage [as 别名]
# 或者: from plone.namedfile.interfaces.INamedImage import providedBy [as 别名]
def getRelativePaths(self):
context = aq_inner(self.context)
parent = aq_parent(context)
portal_url = api.portal.get().portal_url()
prefix = context.url.replace(portal_url, '', 1)
yield prefix
for k, v in context.data.items():
if INamedImage.providedBy(v):
yield '{0}/@@images/image'.format(prefix)
scales = parent.unrestrictedTraverse(
'{0}/{1}'.format(prefix.strip('/'), '@@images'))
for size in scales.getAvailableSizes().keys():
yield '{0}/@@images/{1}'.format(prefix, size)
示例7: getRelativePaths
# 需要导入模块: from plone.namedfile.interfaces import INamedImage [as 别名]
# 或者: from plone.namedfile.interfaces.INamedImage import providedBy [as 别名]
def getRelativePaths(self):
context = self.context.aq_inner
portal_state = getMultiAdapter(
(context, context.request), name=u'plone_portal_state')
prefix = context.url.replace(portal_state.portal_url(), '', 1)
yield prefix
for _, v in context.data.items():
if INamedImage.providedBy(v):
yield "%s/@@images/image" % prefix
scales = aq_parent(context).unrestrictedTraverse(prefix.strip('/') + '/@@images')
for size in scales.getAvailableSizes().keys():
yield "%s/@@images/%s" % (prefix, size,)
示例8: modified
# 需要导入模块: from plone.namedfile.interfaces import INamedImage [as 别名]
# 或者: from plone.namedfile.interfaces.INamedImage import providedBy [as 别名]
def modified(self):
""" provide a callable to return the modification time of content
items, so stored image scales can be invalidated """
if not IPersistentCoverTile.providedBy(self.context):
base_scales = getMultiAdapter(
(self.context, self.request), name='images')
return base_scales.modified()
mtime = ''
for k, v in self.context.data.items():
if INamedImage.providedBy(v):
mtime += self.context.data.get('%s_mtime' % k, 0)
return mtime
示例9: modified
# 需要导入模块: from plone.namedfile.interfaces import INamedImage [as 别名]
# 或者: from plone.namedfile.interfaces.INamedImage import providedBy [as 别名]
def modified(self):
""" provide a callable to return the modification time of content
items, so stored image scales can be invalidated """
if not IPersistentCoverTile.providedBy(self.context):
base_scales = queryMultiAdapter((self.context, self.request),
name='images',
default=None)
return base_scales and base_scales.modified()
mtime = None
for k, v in self.context.data.items():
if INamedImage.providedBy(v):
mtime = self.context.data.get('{0}_mtime'.format(k), None)
return mtime
示例10: getRelativePaths
# 需要导入模块: from plone.namedfile.interfaces import INamedImage [as 别名]
# 或者: from plone.namedfile.interfaces.INamedImage import providedBy [as 别名]
def getRelativePaths(self):
context = aq_inner(self.context)
parent = aq_parent(context)
portal_state = getMultiAdapter(
(context, context.request), name=u'plone_portal_state')
prefix = context.url.replace(portal_state.portal_url(), '', 1)
yield prefix
for _, v in context.data.items():
if INamedImage.providedBy(v):
yield '{0}/@@images/image'.format(prefix)
scales = parent.unrestrictedTraverse(
'{0}/{1}'.format(prefix.strip('/'), '@@images'))
for size in scales.getAvailableSizes().keys():
yield '{0}/@@images/{1}'.format(prefix, size)
示例11: test_image_content_is_migrated
# 需要导入模块: from plone.namedfile.interfaces import INamedImage [as 别名]
# 或者: from plone.namedfile.interfaces.INamedImage import providedBy [as 别名]
def test_image_content_is_migrated(self):
from plone.app.contenttypes.migration import ImageMigrator
from plone.namedfile.interfaces import INamedImage
from Products.ATContentTypes.content.image import ATImage
# create the ATImage
at_image = self.createATCTobject(ATImage, 'image')
test_image_data = self.get_test_image_data()
field = at_image.getField('image')
field.set(at_image, test_image_data)
field.setFilename(at_image, 'testimage.png')
migrator = self.get_migrator(at_image, ImageMigrator)
migrator.migrate()
new_image = self.portal['image']
self.assertTrue(INamedImage.providedBy(new_image.image))
self.assertEqual(new_image.image.filename, 'testimage.png')
self.assertEqual(new_image.image.contentType, 'image/png')
self.assertEqual(new_image.image.data, test_image_data)
示例12: set
# 需要导入模块: from plone.namedfile.interfaces import INamedImage [as 别名]
# 或者: from plone.namedfile.interfaces.INamedImage import providedBy [as 别名]
def set(self, data):
# when setting data, we need to purge scales/image data...
# XXX hack?
try:
scale_key = self.key.replace('.data.', '.scale.')
del self.annotations[scale_key]
except KeyError:
pass
for k, v in data.items():
if INamedImage.providedBy(v):
if (self.key not in self.annotations or
k not in self.annotations[self.key] or
(self.key in self.annotations and
data[k] != self.annotations[self.key][k])):
# set modification time of the image
notify(Purge(self.tile))
data['{0}_mtime'.format(k)] = '%f' % time.time()
self.annotations[self.key] = PersistentDict(data)
notify(ObjectModifiedEvent(self.context))
示例13: fix_image_field_modification_time
# 需要导入模块: from plone.namedfile.interfaces import INamedImage [as 别名]
# 或者: from plone.namedfile.interfaces.INamedImage import providedBy [as 别名]
def fix_image_field_modification_time(context):
"""Fix image modification time to be float timestamp instead of string."""
covers = context.portal_catalog(object_provides=ICover.__identifier__)
logger.info('About to update {0} objects'.format(len(covers)))
for cover in covers:
obj = cover.getObject()
for tile_id in obj.list_tiles():
tile = obj.get_tile(tile_id)
dmgr = ITileDataManager(tile)
data = dmgr.get()
for k, v in data.items():
if not INamedImage.providedBy(v):
continue
mtime_key = '{0}_mtime'.format(k)
data[mtime_key] = float(data[mtime_key])
# need to set changes directly into annotation
dmgr.annotations[dmgr.key] = PersistentDict(data)
msg = 'Tile {0} at {1} updated'
logger.info(msg.format(tile_id, cover.getPath()))
logger.info('Done')