[Zope3-checkins] CVS: Zope3/src/zope/app/content - configure.zcml:1.4 zpt.py:1.3

Steve Alexander steve@cat-box.net
Fri, 27 Dec 2002 15:34:20 -0500


Update of /cvs-repository/Zope3/src/zope/app/content
In directory cvs.zope.org:/tmp/cvs-serv24831/src/zope/app/content

Modified Files:
	configure.zcml zpt.py 
Log Message:
Split zpt interfaces out into the zope/app/interfaces hierarchy.
Added an ISized adapter for zpt pages.


=== Zope3/src/zope/app/content/configure.zcml 1.3 => 1.4 ===
--- Zope3/src/zope/app/content/configure.zcml:1.3	Fri Dec 27 14:19:09 2002
+++ Zope3/src/zope/app/content/configure.zcml	Fri Dec 27 15:33:49 2002
@@ -138,12 +138,12 @@
 
   <require
       permission="zope.ManageContent"
-      interface="zope.app.content.zpt.IZPTPage"
+      interface="zope.app.interfaces.content.zpt.IZPTPage"
       set_attributes="source" />
 
   <require
       permission="zope.View"
-      interface="zope.app.content.zpt.IRenderZPTPage" />
+      interface="zope.app.interfaces.content.zpt.IRenderZPTPage" />
 
   <implements
       interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
@@ -152,8 +152,11 @@
 
 <adapter factory="zope.app.content.zpt.SearchableText"
          provides="zope.app.interfaces.index.text.interfaces.ISearchableText"
-         for="zope.app.content.zpt.IZPTPage" />
+         for="zope.app.interfaces.content.zpt.IZPTPage" />
 
+<adapter factory="zope.app.content.zpt.Sized"
+         provides="zope.app.interfaces.size.ISized"
+         for="zope.app.interfaces.content.zpt.IZPTPage" />
 
 <content class="zope.app.content.dtmlpage.DTMLPage">
 


=== Zope3/src/zope/app/content/zpt.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/content/zpt.py:1.2	Wed Dec 25 09:12:48 2002
+++ Zope3/src/zope/app/content/zpt.py	Fri Dec 27 15:33:49 2002
@@ -19,9 +19,6 @@
 
 from persistence import Persistent
 
-import zope.schema
-
-from zope.interface import Interface, Attribute
 from zope.proxy.context import ContextMethod
 from zope.proxy.context import getWrapperContainer
 from zope.security.proxy import ProxyFactory
@@ -29,44 +26,10 @@
 from zope.pagetemplate.pagetemplate import PageTemplate
 from zope.app.pagetemplate.engine import AppPT
 from zope.app.interfaces.index.text.interfaces import ISearchableText
+from zope.app.interfaces.size import ISized
+from zope.app.interfaces.content.zpt import IZPTPage, IRenderZPTPage
 
-
-class IZPTPage(Interface):
-    """ZPT Pages are a persistent implementation of Page Templates.
-
-       Note: I introduced some new methods whose functionality is
-             actually already covered by some other methods but I
-             want to start enforcing a common coding standard.
-    """
-
-    def setSource(text, content_type='text/html'):
-        """Save the source of the page template.
-
-        'text' must be Unicode.
-        """
-
-    def getSource():
-        """Get the source of the page template."""
-
-    source = zope.schema.Text(
-        title=u"Source",
-        description=u"""The source of the page template.""",
-        required=True)
-
-
-class IRenderZPTPage(Interface):
-
-    content_type = Attribute('Content type of generated output')
-
-    def render(request, *args, **kw):
-        """Render the page template.
-
-        The first argument is bound to the top-level 'request'
-        variable. The positional arguments are bound to the 'args'
-        variable and the keyword arguments are bound to the 'options'
-        variable.
-        """
-
+__metaclass__ = type
 
 class ZPTPage(AppPT, PageTemplate, Persistent):
 
@@ -131,3 +94,21 @@
             text = tag.sub('', text)
 
         return [text]
+
+class Sized:
+
+    __implements__ = ISized
+
+    def __init__(self, page):
+        self.num_lines = len(page.getSource().splitlines())
+
+    def sizeForSorting(self):
+        'See ISized'
+        return ('line', self.num_lines)
+
+    def sizeForDisplay(self):
+        'See ISized'
+        if self.num_lines == 1:
+            return '1 line'
+        return '%s lines' % self.num_lines
+