如何检测“状态”的变化?并显示一些东西?

发布于 2024-10-24 19:03:31 字数 402 浏览 5 评论 0 原文

在 Plone 3.3.5 中,我有一个经典的文件夹内容,它是按日期排序的事件列表(反向)。我正在一一展示每个元素。当事件不再是未来而是过去的事件时,我想显示一条特殊消息。

现在,我有这个:

  <span tal:define="endDate item/end; 
           " tal:condition="python: endDate.isPast()">Past event<br />
  </span>

但我只想显示一次此消息,而不是显示所有过去的事件...

我尝试创建一个Python变量但未能这样做(与未声明的变量混淆)。

感谢您的帮助

PS:我对 Plone 的模板语言一点也不熟悉...

With Plone 3.3.5, I have a classical foldercontents which is a list of events sorted by date (reverse). I am displaying each element one by one. I would like to display a special message when events are no longer in the future but are past events.

For now, I have this:

  <span tal:define="endDate item/end; 
           " tal:condition="python: endDate.isPast()">Past event<br />
  </span>

But I would like to display only once this message and not for all past events...

I tried creating a Python variable but failed to do so (mess with the undeclared variable).

Thanks for the help

PS: I am not familiar at all with the template language of Plone...

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

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

发布评论

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

评论(4

梦在深巷 2024-10-31 19:03:31

最简单的方法可能是让它们成为两个可迭代的列表:一个用于未来事件,一个用于过去事件。然后您可以将“过去的事件”作为标题放在列表之间。

Easiest would probably be to just make them two lists that you iterate over: one for future events and one for past events. Then you can just put 'Past events' as header between the to lists.

花伊自在美 2024-10-31 19:03:31

您可以对未来的事件进行计数,并在该事件变为 0 时显示相应的消息

。有关示例,请参阅门户根目录中的“事件”集合。

You can count the events in the future and display the appropriate message if this becomes 0.

See the "events" collection at the root of the portal for an example of this.

沧桑㈠ 2024-10-31 19:03:31

出色地,
这可能看起来有点棘手,因为在管理数据库结果集时这种方法很自然。

您可以参考这里:
http:// /docs.zope.org/zope2/zope2book/AppendixC.html#the-following-information-is-available-from-the-repeat-variable

tal:repeat 语句非常强大,在您的情况下,您可以依靠“第一”变量信息。

尝试迭代处理 isPast 信息的字典列表,而不是简单的事件列表。

运行以下(简单而残酷的)tal 代码...它是不言自明的。

<div tal:define="past string:Past events;
                 future string:Events to Come;
                 richList python:[{'event':'event1', 'passed': past},
                                  {'event':'event2', 'passed': future},
                                  {'event':'event3', 'passed': past},
                                  {'event':'event4', 'passed': future}];
                 dummy python:richList.sort(lambda x,y:cmp(x['passed'], y['passed']))">    


    <tal:block repeat="item richList">
        <h2 tal:condition="repeat/item/first/passed"
            tal:content="item/passed">
            Past Events or Future
        </h2>
      <a tal:content="item/event">event's url</a>
        </tal:block>

    </div>

您可以创建对目录调用结果进行迭代的 richList。您可以根据 event/end/isPast 函数创建字典项设置“传递”值。

希望这有帮助。

Well,
it may be appears a little bit tricky, cause this approach comes natural when managing db results set.

You can refer here:
http://docs.zope.org/zope2/zope2book/AppendixC.html#the-following-information-is-available-from-the-repeat-variable

The tal:repeat statement is very powerful and, in your case you can count on "first" variable information.

Instead of a simple List of Events, try to iterate over a list of dictionaries in which you take care of isPast information.

Run the following (simple and brutal) tal code... it is self explaning.

<div tal:define="past string:Past events;
                 future string:Events to Come;
                 richList python:[{'event':'event1', 'passed': past},
                                  {'event':'event2', 'passed': future},
                                  {'event':'event3', 'passed': past},
                                  {'event':'event4', 'passed': future}];
                 dummy python:richList.sort(lambda x,y:cmp(x['passed'], y['passed']))">    


    <tal:block repeat="item richList">
        <h2 tal:condition="repeat/item/first/passed"
            tal:content="item/passed">
            Past Events or Future
        </h2>
      <a tal:content="item/event">event's url</a>
        </tal:block>

    </div>

You can create your richList iterating on the result of a catalog call. And you can create the dictionary item seting 'passed' value according with event/end/isPast function.

hope this helps.

贪恋 2024-10-31 19:03:31

您可以在 listFolderContents 中“过滤”,就像进行目录搜索时进行过滤一样。
请参阅http://collective-docs.plone.org/内容/listing.html#getting-folder-objects-filtered
这是如何完成的。已经有一个“结束”索引,您可以将其包含在过滤器中,请参阅 http://plone.org/documentation/manual/plone-community-developer-documentation/searching-and-indexing/query#querying-by-date

You can "filter" in listFolderContents exactly as you can filter when doing a catalog search.
See http://collective-docs.plone.org/content/listing.html#getting-folder-objects-filtered
for how this is done. There is already an "end" index which you can include in your filter, see http://plone.org/documentation/manual/plone-community-developer-documentation/searching-and-indexing/query#querying-by-date

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