[Checkins] SVN: z3c.pagelet/trunk/ * Removed hard dependency on ``zope.formlib``: the pagelet forms now

Michael Howitz mh at gocept.com
Thu May 28 15:01:26 EDT 2009


Log message for revision 100515:
  * Removed hard dependency on ``zope.formlib``: the pagelet forms now
    only get defined when ``zope.formlib`` is available. Tests still
    depend on ``zope.formlib``, so it got a test dependency.
  
  * Made sure long_description renders fine on pypi.
  
  

Changed:
  U   z3c.pagelet/trunk/CHANGES.txt
  U   z3c.pagelet/trunk/setup.py
  U   z3c.pagelet/trunk/src/z3c/pagelet/README.txt
  U   z3c.pagelet/trunk/src/z3c/pagelet/browser.py

-=-
Modified: z3c.pagelet/trunk/CHANGES.txt
===================================================================
--- z3c.pagelet/trunk/CHANGES.txt	2009-05-28 18:45:49 UTC (rev 100514)
+++ z3c.pagelet/trunk/CHANGES.txt	2009-05-28 19:01:25 UTC (rev 100515)
@@ -8,7 +8,13 @@
 * Got rid of dependency on ``zope.app.component`` by requiring
   ``zope.component >= 3.7``.
 
+* Removed hard dependency on ``zope.formlib``: the pagelet forms now
+  only get defined when ``zope.formlib`` is available. Tests still
+  depend on ``zope.formlib``, so it got a test dependency.
 
+* Made sure long_description renders fine on pypi.
+
+
 1.0.3 (2009-02-27)
 ------------------
 

Modified: z3c.pagelet/trunk/setup.py
===================================================================
--- z3c.pagelet/trunk/setup.py	2009-05-28 18:45:49 UTC (rev 100514)
+++ z3c.pagelet/trunk/setup.py	2009-05-28 19:01:25 UTC (rev 100515)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2007 Zope Foundation and Contributors.
+# Copyright (c) 2007-2009 Zope Foundation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -20,23 +20,21 @@
 from setuptools import setup, find_packages
 
 def read(*rnames):
-    text = open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-    return xml.sax.saxutils.escape(text)
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
 
-setup (
+version = '1.0.4dev',
+
+setup(
     name='z3c.pagelet',
-    version='1.0.4dev',
+    version=version,
     author = "Roger Ineichen and the Zope Community",
     author_email = "zope-dev at zope.org",
     description = "Pagelets are way to specify a template without the O-wrap.",
     long_description=(
         read('README.txt')
-        + '\n' +
-        'Detailed Documentation\n'
-        '**********************\n'
-        + '\n' +
+        + '\n\n' +
         read('src', 'z3c', 'pagelet', 'README.txt')
-        + '\n' +
+        + '\n\n' +
         read('CHANGES.txt')
         ),
     license = "ZPL 2.1",
@@ -64,6 +62,7 @@
                 'z3c.pt>=1.0b4',
                 'z3c.ptcompat',
                 'zope.app.security',
+                'zope.formlib',
                 ],
         docs = ['z3c.recipe.sphinxdoc'],
         ),
@@ -76,7 +75,6 @@
         'zope.component>=3.7.0',
         'zope.configuration',
         'zope.contentprovider',
-        'zope.formlib', # TODO: get rid of hard dependency on zope.formlib
         'zope.interface',
         'zope.publisher',
         'zope.schema',

Modified: z3c.pagelet/trunk/src/z3c/pagelet/README.txt
===================================================================
--- z3c.pagelet/trunk/src/z3c/pagelet/README.txt	2009-05-28 18:45:49 UTC (rev 100514)
+++ z3c.pagelet/trunk/src/z3c/pagelet/README.txt	2009-05-28 19:01:25 UTC (rev 100515)
@@ -154,8 +154,8 @@
   <div class="content">
     my template content
   </div>
-  
 
+
 PageletRenderer
 ---------------
 
@@ -264,7 +264,7 @@
   >>> zope.component.provideAdapter(
   ...     factory, (zope.interface.Interface, IDefaultBrowserLayer, IContent),
   ...     ILayoutTemplate)
- 
+
   >>> contextContentTemplate = os.path.join(temp_dir, 'contextContentTemplate.pt')
   >>> open(contextContentTemplate, 'w').write('''
   ...   <div class="context-content">
@@ -294,8 +294,11 @@
 -------------------------------------
 
 What would the pagelet be without any formlib based implementations?
-We offer base implementations for add, edit and display forms
-based on the formlib.
+We offer base implementations for add, edit and display forms based on
+the formlib. **Note:** To make sure these classes get defined, you
+should have ``zope.formlib`` already installed, as ``z3c.pagelet``
+does not directly depend on ``zope.formlib`` because there are other
+form libraries.
 
 For the next tests we provide a generic form template
 like those used in formlib. This template is registered within this package

Modified: z3c.pagelet/trunk/src/z3c/pagelet/browser.py
===================================================================
--- z3c.pagelet/trunk/src/z3c/pagelet/browser.py	2009-05-28 18:45:49 UTC (rev 100514)
+++ z3c.pagelet/trunk/src/z3c/pagelet/browser.py	2009-05-28 19:01:25 UTC (rev 100515)
@@ -19,7 +19,6 @@
 
 import zope.interface
 import zope.component
-from zope.formlib import form # TODO: get rid of hard dependency on zope.formlib
 from zope.publisher import browser
 
 from z3c.template.interfaces import ILayoutTemplate, IContentTemplate
@@ -53,11 +52,11 @@
     def __call__(self):
         """Calls update and returns the layout template which calls render."""
         self.update()
-        
+
         if self.request.response.getStatus() in REDIRECT_STATUS_CODES:
             # don't bother rendering when redirecting
             return ''
-        
+
         if self.layout is None:
             layout = zope.component.queryMultiAdapter(
                 (self, self.request, self.context), ILayoutTemplate)
@@ -67,68 +66,72 @@
             return layout(self)
         return self.layout()
 
+try:
+    from zope.formlib import form
+except ImportError:
+    pass
+else:
+    # formlib based pagelet mixin classes
+    class PageletForm(form.FormBase, BrowserPagelet):
+        """Fomr mixin for pagelet implementations."""
 
-# formlib based pagelet mixin classes
-class PageletForm(form.FormBase, BrowserPagelet):
-    """Fomr mixin for pagelet implementations."""
+        zope.interface.implements(interfaces.IPageletForm)
 
-    zope.interface.implements(interfaces.IPageletForm)
+        template = None
+        layout = None
 
-    template = None
-    layout = None
+        __init__ = BrowserPagelet.__init__
 
-    __init__ = BrowserPagelet.__init__
+        __call__ = BrowserPagelet.__call__
 
-    __call__ = BrowserPagelet.__call__
+        def render(self):
+            # if the form has been updated, it will already have a result
+            if self.form_result is None:
+                if self.form_reset:
+                    # we reset, in case data has changed in a way that
+                    # causes the widgets to have different data
+                    self.resetForm()
+                    self.form_reset = False
+                if self.template is None:
+                    template = zope.component.queryMultiAdapter(
+                        (self, self.request, self.context), IContentTemplate)
+                    if template is None:
+                        template = zope.component.getMultiAdapter(
+                            (self, self.request), IContentTemplate)
+                    self.form_result = template(self)
+                else:
+                    self.form_result = self.template()
 
-    def render(self):
-        # if the form has been updated, it will already have a result
-        if self.form_result is None:
-            if self.form_reset:
-                # we reset, in case data has changed in a way that
-                # causes the widgets to have different data
-                self.resetForm()
-                self.form_reset = False
+            return self.form_result
+
+
+    class PageletAddForm(PageletForm, form.AddFormBase):
+        """Add form mixin for pagelet implementations."""
+
+        zope.interface.implements(interfaces.IPageletAddForm)
+
+        def render(self):
+            if self._finished_add:
+                self.request.response.redirect(self.nextURL())
+                return ""
+            # render content template
             if self.template is None:
                 template = zope.component.queryMultiAdapter(
                     (self, self.request, self.context), IContentTemplate)
                 if template is None:
                     template = zope.component.getMultiAdapter(
                         (self, self.request), IContentTemplate)
-                self.form_result = template(self)
-            else:
-                self.form_result = self.template()
+                return template(self)
+            return self.template()
 
-        return self.form_result
 
+    class PageletEditForm(PageletForm, form.EditFormBase):
+        """Edit form mixin for pagelet implementations."""
 
-class PageletAddForm(PageletForm, form.AddFormBase):
-    """Add form mixin for pagelet implementations."""
+        zope.interface.implements(interfaces.IPageletEditForm)
 
-    zope.interface.implements(interfaces.IPageletAddForm)
 
-    def render(self):
-        if self._finished_add:
-            self.request.response.redirect(self.nextURL())
-            return ""
-        # render content template
-        if self.template is None:
-            template = zope.component.queryMultiAdapter(
-                (self, self.request, self.context), IContentTemplate)
-            if template is None:
-                template = zope.component.getMultiAdapter(
-                    (self, self.request), IContentTemplate)
-            return template(self)
-        return self.template()
+    class PageletDisplayForm(PageletForm, form.DisplayFormBase):
+        """Display fomr mixin for pagelet implementations."""
 
-
-class PageletEditForm(PageletForm, form.EditFormBase):
-    """Edit form mixin for pagelet implementations."""
-
-    zope.interface.implements(interfaces.IPageletEditForm)
-
-
-class PageletDisplayForm(PageletForm, form.DisplayFormBase):
-    """Display fomr mixin for pagelet implementations."""
-
-    zope.interface.implements(interfaces.IPageletDisplayForm)
+        zope.interface.implements(interfaces.IPageletDisplayForm)



More information about the Checkins mailing list