plone - 如何获取敏捷内容类型的图像并在批量 ListView 中显示?

标签 plone dexterity

我需要创建一个包含基于敏捷的内容类型(Plone 4.2)的文件夹的批处理 ListView ,该 View 还显示它们的图像。 我找到了两种获取对象图像的方法。

方法一:

在模板中(批处理内)

         ...
         <div tal:define="item_object item/getObject;">
              <img tal:condition="exists:item_object/@@images/image1"
                   tal:replace="structure item_object/@@images/image1/mini" />
         </div>

方法二:

在 View 类中

def get_item_image(self, item):
    itemobj = item.getObject()
    scales = getMultiAdapter((itemobj, self.request), name='images')
    scale = scales.scale('image1', scale='mini')
    imageTag = None
    if scale is not None:
       imageTag = scale.tag()
    return imageTag

在模板中

         ...
         <div tal:define="item_image python:view.get_item_image(item)">
              <img tal:condition="item_image"
                   tal:replace="structure item_image" />
         </div>

谁能告诉我哪种方式最好(如果有的话)不唤醒对象?

最佳答案

我认为当前的 plone.app.imaging 在任何情况下都需要唤醒对象以访问其图像比例(毕竟它们存储在对象内部)。因此生成对象的唤醒免费列表不是很容易。

好消息是 Dexterity 内容类型比 Archetypes 内容类型更轻量,并且通过在模板中迭代 folder.contentItems() 进行原始列表应该不会那么昂贵。事实上,它甚至可能比通过目录查询更快。所以不用担心唤醒对象,只需使用 plone.app.imaging 方法:

https://github.com/plone/plone.app.imaging

关于plone - 如何获取敏捷内容类型的图像并在批量 ListView 中显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14749216/

相关文章:

plone - getSectionFromURL.py 现在在 Plone 4 中折旧了

plone - 如何修复 : Members (This object from the CMFPlone product is broken! )?

plone - 是否可以在 Diazo 中删除 base 和 Content-Type + alter HTML 属性?

plone - 是否可以仅对某个类型的某些对象启用 plone.behavior?

image - 如何调整敏捷图像小部件的大小?

regex - Plone 体收集标准。它们可以是不区分大小写的或正则表达式吗?

forms - 如何修改updateWidgets中的z3c表单字段?

plone - 如何清理zc.relation目录上的旧接口(interface)?

python - 在以灵活的形式设置另一个字段后,动态更改一个字段的下拉选项。架构