创建自定义portlet - 新闻和事件的混合

时间:2013-12-08 17:58:49

标签: plone

我正在尝试创建一个自定义portelt,它根据关键字显示新闻或事件项。我不想使用收集portlet工具。我已经创建了一个Python脚本,它可以获得如下所需的结果:

from Products.CMFCore.utils import getToolByName
portal_catalog = getToolByName(context, 'portal_catalog')
return portal_catalog.searchResults(
                                    Subject = 'Startseite',
                                    end={'query': DateTime(),
                                         'range': 'min'},
                                    sort_on='start',
                                    sort_limit=3,
                                    review_state='external')[:5]

所以这应该使用review_state'external'和关键字(或主题)'Startseite'来获取所有对象。现在我创建了一个页面模板,用于渲染经典的portelt:

<html xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      i18n:domain="plone">
<body>
<div metal:define-macro="portlet"
     tal:define="view context/@@events_view;
                 results context/startpage_informations;
                 events_link view/all_events_link;
                 prev_events_link view/prev_events_link"
     tal:condition="results">
<dl class="portlet" id="portlet-events">
    <dt class="portletHeader">
        <span class="portletTopLeft"></span>
        <a href=""
           tal:attributes="href events_link"
           class="tile">
            Wichtige Neuigkeiten:
        </a>
        <span class="portletTopRight"></span>
    </dt>
    <tal:events tal:repeat="obj results">
    <dd class="portletItem"
        tal:define="oddrow repeat/obj/odd"
        tal:attributes="class python:test(oddrow, 'portletItem even', 'portletItem odd')">
        <a href="#"
           class="tile"
           tal:attributes="href obj/getURL;
                           title obj/Description">
            <img src="#" alt="" tal:replace="structure here/news_icon.gif" />
            <span tal:replace="obj/pretty_title_or_id">
             Some Event 
            </span>
            <span class="portletItemDetails"
                tal:define="starts python:toLocalizedTime(obj.start, long_format=1);
                ends python:toLocalizedTime(obj.end, long_format=1);
                                startTime python:toLocalizedTime(obj.start,time_only=1);
                                endTime python:toLocalizedTime(obj.end,time_only=1);
                startDay python:toLocalizedTime(obj.start, long_format=0);
                endDay python:toLocalizedTime(obj.end, long_format=0);">
                    <span>
                    <tal:condition condition="obj/location">
                        <tal:location content="obj/location">Location</tal:location>,<br />
                    </tal:condition>
                        <tal:sameday tal:condition="python:startDay==endDay">
                            <span tal:condition="startDay" tal:replace="startDay">:[If this is an event, show its start time and date]</span><br />
                                Uhrzeit: <span tal:condition="startTime" tal:replace="startTime">[If this is an event, show its start time and date]</span> -
                                <span tal:condition="endTime" tal:replace="endTime">[If this is an event, show its start time and date]</span>
                        </tal:sameday>
                        <tal:multiday tal:condition="python:startDay!=endDay">
                            Vom <span tal:condition="starts" tal:replace="starts">[If this is a multi-day event, show its start date]</span><br />bis
                                <tal:hasendday tal:condition="ends"> 
                                    <span tal:replace="ends">[If this is a multi-day event, show its end date]</span>
                                </tal:hasendday>
                        </tal:multiday>
                     </span>
             </span>
        </a>
    </dd>
    </tal:events>
</dl>
</div>
</body>
</html>

0 个答案:

没有答案