开发者

How to detect a change of "state" and display something?

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 event开发者_JAVA百科s 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...


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.


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜