如何在列表视图中显示基于 Dexterity 的 Plone 内容类型的图像?

发布于 2024-12-05 07:16:48 字数 378 浏览 0 评论 0原文

在列表视图中显示基于 Dexterity 的 Plone 内容类型的图像的最佳方式是什么?

假设我有一个包含基于敏捷性的内容对象的文件夹,该对象提供图像字段,并且我想将这些对象(作为目录大脑)与其图像一起列出。可以通过调用绝对 URL 来显示列表中的图像:

<img src="" tal:attributes="src string:${item/getURL}/@@images/image/thumb" />

不过,如果图像不存在,Plone 会引发错误,并且我没有找到检查图像是否存在于页面模板中的好方法。我们显然不想唤醒列表中的对象来查找图像。

我是否必须在目录中创建图像元数据列,或者是否有我没有看到的更好的解决方案?

What's the best way to show the image of a Dexterity-based Plone content type in a listing view?

Say I have a folder with Dexterity-based content objects that provide an image field and I want to list the objects (as catalog brains) together with their image. It is possible to show the images in the listing by calling their absolute URL:

<img src="" tal:attributes="src string:${item/getURL}/@@images/image/thumb" />

Though, Plone will raise an error if the image does not exist and I don't see a good way to check if the image exists in a page template. We obviously do not want to wake up the objects for a listing, to look up the image.

Do I have to create an image metadata column in the catalog or is there a better solution I don't see?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

红墙和绿瓦 2024-12-12 07:16:48

只要正确批处理,我就不会太担心唤醒列表中的对象。如果您使用 plone.app.textfield 和 plone.namedfile 中的字段,则大数据将保存在单独的持久对象中,因此主要内容项对象相对较轻。当然,如果您想确保它不会对您的情况造成损害,请自行进行基准测试。

I wouldn't worry too much about waking up objects in a listing as long as it's properly batched. If you're using the fields from plone.app.textfield and plone.namedfile then large data is kept in separate persistent objects, so the main content item object is relatively lightweight. Of course, do your own benchmarking if you want to be sure it doesn't hurt for your case.

对不⑦ 2024-12-12 07:16:48

有一个关于如何在专业Plone 4开发中执行此操作的秘诀(我相信第10章)。不幸的是,我真的不记得现在该怎么做。 :)

There is a recipe for how to do this in Professional Plone 4 Development (chapter 10, I believe). Unfortunately, I genuinely can't remember how to do it right now. :)

任谁 2024-12-12 07:16:48

在 Portal_catalog 中创建元数据,您将在其中存储有效图像的路径。
创建一个同名的 python 脚本,用于检查对象是否有图像,如果没有图像,则返回默认图像。

Create a metadata in portal_catalog where you will store a path to a valid image.
Create a python script of the same name that will check if the object has an image and in the case there is no image, return a default one.

爱已欠费 2024-12-12 07:16:48

检查图像字段的示例可用:

class product(grok.View):
    grok.context(IDexterityContent)
    grok.require('zope2.View')
    grok.name('view')

    def update(self):
        """
        """
        # Hide the editable-object border
        context = self.context
        request = self.request
        request.set('disable_border', True)


    #brain come from contained image field 's object
    def isImageAvalable(self,brain=None):
        """判断图片字段是否有效"""
        try:
            if brain is None:
                image = self.context.image.size
            else:
                 image = brain.getObject().image.size

            return (image != 0)

        except:
            return False

A example for checking image field is avalable:

class product(grok.View):
    grok.context(IDexterityContent)
    grok.require('zope2.View')
    grok.name('view')

    def update(self):
        """
        """
        # Hide the editable-object border
        context = self.context
        request = self.request
        request.set('disable_border', True)


    #brain come from contained image field 's object
    def isImageAvalable(self,brain=None):
        """判断图片字段是否有效"""
        try:
            if brain is None:
                image = self.context.image.size
            else:
                 image = brain.getObject().image.size

            return (image != 0)

        except:
            return False
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文