Author: jmorliaguet
Date: Fri May 12 20:50:44 2006
New Revision: 3110

Added:
   z3ecm/trunk/src/ecm/cpsskins/example7/
   z3ecm/trunk/src/ecm/cpsskins/example7/__init__.py   (contents, props changed)
   z3ecm/trunk/src/ecm/cpsskins/example7/configure.zcml   (contents, props 
changed)
   z3ecm/trunk/src/ecm/cpsskins/example7/ds.py   (contents, props changed)
   z3ecm/trunk/src/ecm/cpsskins/example7/news-icon.png   (contents, props 
changed)
   z3ecm/trunk/src/ecm/cpsskins/example7/newsbox.pt   (contents, props changed)
   z3ecm/trunk/src/ecm/cpsskins/example7/portlet.py   (contents, props changed)
   z3ecm/trunk/src/ecm/cpsskins/example7/widgets.py   (contents, props changed)
Modified:
   z3ecm/trunk/src/ecm/cpsskins/configure.zcml

Log:

- added an RSS portlet example and a newsbox widget.



Modified: z3ecm/trunk/src/ecm/cpsskins/configure.zcml
==============================================================================
--- z3ecm/trunk/src/ecm/cpsskins/configure.zcml (original)
+++ z3ecm/trunk/src/ecm/cpsskins/configure.zcml Fri May 12 20:50:44 2006
@@ -12,4 +12,6 @@
 
   <include package=".example6" />
 
+  <include package=".example7" />
+
 </configure>

Added: z3ecm/trunk/src/ecm/cpsskins/example7/__init__.py
==============================================================================
--- (empty file)
+++ z3ecm/trunk/src/ecm/cpsskins/example7/__init__.py   Fri May 12 20:50:44 2006
@@ -0,0 +1 @@
+# This is a package

Added: z3ecm/trunk/src/ecm/cpsskins/example7/configure.zcml
==============================================================================
--- (empty file)
+++ z3ecm/trunk/src/ecm/cpsskins/example7/configure.zcml        Fri May 12 
20:50:44 2006
@@ -0,0 +1,43 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope";
+    xmlns:i18n="http://namespaces.zope.org/i18n";
+    xmlns:cpsskins="http://namespaces.zope.org/cpsskins";
+    i18n_domain="ecm"
+    >
+
+  <cpsskins:portlet
+      name="ecm.cpsskins.example7"
+      title="Example7: News Portlet"
+      description="This portlet displays some news"
+      class=".portlet.NewsPortlet"
+      schema=".portlet.INewsPortlet"
+      icon="news-icon.png"
+  />
+
+  <cpsskins:widget
+      name="ecm.cpsskins.newsbox"
+      title="Example7: News Box Widget"
+      view=".widgets.NewsBox"
+      for=".ds.INewsData"
+      basic="True"
+  />
+
+  <cpsskins:presentation
+      for=".portlet.INewsPortlet">
+
+      <display
+         type="box"
+      />
+
+      <format
+         name="widget"
+         types="ecm.cpsskins.newsbox"
+      />
+
+      <format
+         name="style"
+      />
+
+  </cpsskins:presentation>
+
+</configure>

Added: z3ecm/trunk/src/ecm/cpsskins/example7/ds.py
==============================================================================
--- (empty file)
+++ z3ecm/trunk/src/ecm/cpsskins/example7/ds.py Fri May 12 20:50:44 2006
@@ -0,0 +1,39 @@
+##############################################################################
+#
+# Copyright (c) 2006 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+from zope.interface import Interface, implements
+
+class INewsData(Interface):
+    """Schema definition of news data.
+    """
+
+class NewsData(object):
+    """The actual news data.
+    """
+    implements(INewsData)
+
+    def __init__(self, header=u'', items=[]):
+        self.header = header
+        self.items = items
+
+    def __call__(self):
+        return {
+            'header': self.header,
+            'items': self.items,
+        }

Added: z3ecm/trunk/src/ecm/cpsskins/example7/news-icon.png
==============================================================================
Binary file. No diff available.

Added: z3ecm/trunk/src/ecm/cpsskins/example7/newsbox.pt
==============================================================================
--- (empty file)
+++ z3ecm/trunk/src/ecm/cpsskins/example7/newsbox.pt    Fri May 12 20:50:44 2006
@@ -0,0 +1,17 @@
+<tal:block define="data options/info/data">
+
+<table>
+  <tr>
+    <th class="header" tal:content="data/header" />
+  </tr>
+
+  <tr class="item" tal:repeat="item data/items">
+    <td>
+      <a tal:attributes="href item/url; alt item/description"
+         tal:content="item/title" />
+      <div class="date" tal:content="item/date" />
+    </td>
+  </tr>
+</table>
+
+</tal:block>

Added: z3ecm/trunk/src/ecm/cpsskins/example7/portlet.py
==============================================================================
--- (empty file)
+++ z3ecm/trunk/src/ecm/cpsskins/example7/portlet.py    Fri May 12 20:50:44 2006
@@ -0,0 +1,82 @@
+##############################################################################
+#
+# Copyright (c) 2006 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+import os
+import urllib
+from xml.dom.minidom import parse
+
+from zope.app.cache.ram import RAMCache
+from zope.interface import implements
+from zope.schema import TextLine
+
+from cpsskins import Portlet
+from cpsskins.interfaces import IPortlet
+from ecm.cpsskins.example7.ds import NewsData
+
+cache = RAMCache()
+CACHE_ID = 'ecm.cpsskins.example7'
+
+class INewsPortlet(IPortlet):
+    """Interface for the News portlet"""
+
+    rss_url = TextLine(title=u'RSS feed url')
+
+class NewsPortlet(Portlet):
+    """News portlet
+    """
+    implements(INewsPortlet)
+
+    def __init__(self, title=u'', rss_url=u''):
+        self.title = title
+        self.rss_url = rss_url
+
+    def __call__(self, info):
+        """Set the portlet data.
+        """
+        rss_url = self.rss_url
+
+        data = cache.query(CACHE_ID, {'key': rss_url}, None)
+        if data is None:
+            data = getRSSData(rss_url)
+            cache.set(data, CACHE_ID, {'key': rss_url})
+
+        info.data = NewsData(header=data['header'], items=data['items'])
+
+def getRSSData(url):
+
+    def textOf(node, tag):
+        children = node.getElementsByTagName(tag)
+        if len(children):
+             text = u''.join([c.data for c in children[0].childNodes]) 
+        return text
+
+    xml = parse(urllib.urlopen(url))
+
+    channel_def = xml.getElementsByTagName('channel')[0]
+    channel_title = textOf(channel_def, 'title')
+
+    items = []
+    for item_def in channel_def.getElementsByTagName('item'):
+        items.append({
+            'url': textOf(item_def, 'link'),
+            'title': textOf(item_def, 'title'),
+            'description': textOf(item_def, 'description'),
+            'date': textOf(item_def, 'pubDate'),
+        })
+
+    return {'header': channel_title, 'items': items}

Added: z3ecm/trunk/src/ecm/cpsskins/example7/widgets.py
==============================================================================
--- (empty file)
+++ z3ecm/trunk/src/ecm/cpsskins/example7/widgets.py    Fri May 12 20:50:44 2006
@@ -0,0 +1,61 @@
+##############################################################################
+#
+# Copyright (c) 2006 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+from zope.app import pagetemplate
+from zope.interface import Interface, implements
+
+from cpsskins import WidgetView
+
+class INewsBox(Interface):
+    """Typing interface for news boxes"""
+
+class NewsBox(WidgetView):
+    """News box widget view
+    """
+    template = pagetemplate.ViewPageTemplateFile('newsbox.pt')
+
+    preview = """
+    <table>
+      <tr>
+        <th class="header">header</th>
+      </tr>
+      <tr class="item" label="Item">
+        <td>
+          <a href="http://some.url.1"; label="Link">item 1</a>
+          <div class="date" label="Publication date">publication date</div>
+        </td>
+      </tr>
+      <tr class="item" label="item">
+        <td>
+          <a href="http://some.url.2"; label="Link">item 2</a>
+          <div class="date" label="Publication date">publication date</div>
+        </td>
+      </tr>
+    </table>
+    """
+
+    implements(INewsBox)
+
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
+
+    def __call__(self, markup, info, **kw):
+        return self.template(markup=markup, info=info, **kw)
+
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to