You are here: Home / Documentation / How To's / How to display only certain event types in a portlet

How to display only certain event types in a portlet

by nguyen — published Sep 13, 2008 02:15 PM, last modified Aug 16, 2016 10:50 AM
if you have different event types on your site

See UARC site - classic events portlet, combined with cloned Event portal types or Events that have a specific keyword (category) assigned

Distinguishing between event types: 

There are two ways to distinguish between event types.  Let's say for example you want to have "advisor" and "student" event types.

Use Keyword/Categories

When you create an Event, use the Category tab and set a category "studentevent" or "advisorevent".

Clone the Event portal type

Using the ZMI, go to portal_types, copy and paste the Event type, rename the new Event copy to "StudentEvent".  Do the same to create a "AdvisorEvent" portal type.

Create a portlet to display a specific event type:

Now you want to have a portlet that shows just one event type.  For this example, let's assume it's advisor events.

If you use the keyword/category method:

The events you want to display in the portlet will have the keyword/category "advisorevent".  You will

  • add a page template defining the advisor event portlet
  • add a script that returns published advisor events
  • add a classic portlet that calls the advisor event portlet

In ZMI, go to portal_skins/custom, add a Page Template, give it a name like "portlet_advisor_events".  The body should contain this:

<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/published_advisorevents;
                 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"
           i18n:translate="box_events">
            Advisor Events
        </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/event_icon.gif" />
            <span tal:replace="obj/pretty_title_or_id">
             Some Event 
            </span>
            <span class="portletItemDetails">
                <tal:condition condition="obj/location">
                    <tal:location content="obj/location">Location</tal:location>, <br />
                </tal:condition>
                <tal:date content="python:toLocalizedTime(obj.start)">
                May 5
                </tal:date>
            </span>
        </a>
    </dd>
    </tal:events>
    <dd class="portletFooter"
           tal:condition="prev_events_link">
       <a href=""
           tal:attributes="href prev_events_link"
           class="tile">
            <span i18n:translate="box_previous_events">
                Previous events&hellip;
            </span>
        </a>
    </dd>
    <dd class="portletFooter">
        <a href=""
           class="tile"
           tal:attributes="href events_link"
           i18n:translate="box_upcoming_events">
                Upcoming events&hellip;
        </a>
        <span class="portletBottomLeft"></span>
        <span class="portletBottomRight"></span>
    </dd>
</dl>
</div>
</body>
</html>

You will also need to add a Script (Python) called "published_advisorevents" containing this:

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

In a normal view (non-ZMI) of the root folder of your site, click on the "Manage portlets" link.  Add a classic portlet.  For Template, specify the value "portlet_advisor_events".  For Macro, specify the value "portlet".  Press Save.  Return to the normal view of your site's home page.  You should now see a new portlet that displays only advisor events.

If you used the portal type method:

If instead you have cloned the Event portal type to one called AdvisorEvent, you can use the same technique as above.  The only difference is in the Script (Python) called "published_advisorevents".  It should contain this

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

The difference in the script is that instead of specifying

portal_type='Event'

it specifies

portal_type='AdvisorEvent'

It also omits the condition

Subject='advisorevent' 

(the Subject being the internal name for the keyword/category mechanism).

 

Navigation