Author: jmorliaguet
Date: Fri Oct 28 11:02:45 2005
New Revision: 28770

Added:
   z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/
   z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/README.txt   (contents, props 
changed)
   z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/__init__.py   (contents, props 
changed)
   z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/configure.zcml   (contents, 
props changed)
   z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/counter-icon.png   (contents, 
props changed)
   z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/counter.py   (contents, props 
changed)
   z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/example6.png   (contents, props 
changed)
Log:

- added a Counter portlet to demonstrate the 2-step update / render



Added: z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/README.txt
==============================================================================
--- (empty file)
+++ z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/README.txt      Fri Oct 28 
11:02:45 2005
@@ -0,0 +1,54 @@
+
+.. header:: cpsskins developer tutorial
+
+Example 6: Counter portlet
+==========================
+
+:Author: Jean-Marc Orliaguet
+:Version: $Revision: 1 $
+:Copyright: 2005 Nuxeo and Contributors.
+
+.. contents::
+
+
+Prerequisites
+-------------
+
+You have read the 'example1' section of this tutorial.
+
+Description
+-----------
+
+The Counter portlet updates a counter stored in the request. It increments the
+counter by 1 every time it gets displayed. 
+
+
+Steps in developing the Counter portlet
+---------------------------------------
+
+You may take a look the `<counter.py>`_ file while going through the steps.
+
+Step 1: defining the portlet's interface
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+Step 2: defining the portlet's factory
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+Step 3: creating the portlet's markup
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Step 4: registrering the portlet
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+Step 5: testing the portlet
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+.. figure:: example6.png
+
+   fig.1: The Counter portlet displayed on the page canvas.
+
+.. footer:: copyright 2005 - Nuxeo and Contributors

Added: z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/__init__.py
==============================================================================
--- (empty file)
+++ z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/__init__.py     Fri Oct 28 
11:02:45 2005
@@ -0,0 +1 @@
+# This is a package

Added: z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/configure.zcml
==============================================================================
--- (empty file)
+++ z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/configure.zcml  Fri Oct 28 
11:02:45 2005
@@ -0,0 +1,23 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope";
+    xmlns:i18n="http://namespaces.zope.org/i18n";
+    xmlns:cpsskins="http://namespaces.zope.org/cpsskins";
+    i18n_domain="ecm"
+    >
+
+  <!-- The 'Counter portlet' increments a counter each time it is displayed -->
+
+  <cpsskins:portlet
+      name="ecm.cpsskins.example6"
+      title="Example6: Counter portlet"
+      description="This portlet increments a counter."
+      factory=".counter.CounterPortlet"
+      schema=".counter.ICounterPortlet"
+      icon="counter-icon.png"
+  />
+
+  <adapter
+      factory=".counter.CounterUpdater"
+  />
+
+</configure>

Added: z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/counter-icon.png
==============================================================================
Binary file. No diff available.

Added: z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/counter.py
==============================================================================
--- (empty file)
+++ z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/counter.py      Fri Oct 28 
11:02:45 2005
@@ -0,0 +1,65 @@
+##############################################################################
+#
+# Copyright (c) 2005 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 persistent import Persistent
+from zope.component import adapts
+from zope.interface import implements
+
+from cpsskins.interfaces import IPortlet
+from cpsskins.browser.rendering.interfaces import IUpdateData
+
+COUNTER_NAME = 'ecm.cpsskins.counter'
+
+class ICounterPortlet(IPortlet):
+    """Interface for the Counter portlet"""
+
+class CounterPortlet(Persistent):
+    """The Counter portlet increments a counter before being displayed.
+    """
+    implements(ICounterPortlet)
+
+    def __init__(self, title=''):
+        self.title = title
+
+    def __call__(self, info):
+        request = info.request
+        count = request.annotations.get(COUNTER_NAME, 0)
+        return u"There are <b>%s</b> portlet(s) on this page." % str(count)
+
+class CounterUpdater(object):
+    """This adapter is called when the portlet is updated.
+
+    It increments the counter by 1.
+    """
+    adapts(ICounterPortlet)
+    implements(IUpdateData)
+
+    def __init__(self, context):
+        self.context = context
+
+    def __call__(self, info):
+        request = info.request
+
+        if COUNTER_NAME not in request.annotations:
+            request.annotations[COUNTER_NAME] = 0
+        # get the count
+        count = request.annotations[COUNTER_NAME]
+        # increment the counter
+        request.annotations[COUNTER_NAME] = count +1
+

Added: z3lab/z3ecm/trunk/src/ecm/cpsskins/example6/example6.png
==============================================================================
Binary file. No diff available.
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to