[Checkins] SVN: plone.z3cform/trunk/ merge r123889 to r125140

Tom Gross cvs-admin at zope.org
Mon Apr 16 05:55:50 UTC 2012


Log message for revision 125141:
  merge r123889 to r125140 
  

Changed:
  D   plone.z3cform/trunk/plone/z3cform/crud/batch.pt
  D   plone.z3cform/trunk/plone/z3cform/crud/batch.txt
  U   plone.z3cform/trunk/plone/z3cform/crud/crud-table.pt
  U   plone.z3cform/trunk/plone/z3cform/crud/crud.py
  U   plone.z3cform/trunk/plone/z3cform/tests.py
  U   plone.z3cform/trunk/setup.py

-=-
Deleted: plone.z3cform/trunk/plone/z3cform/crud/batch.pt
===================================================================
--- plone.z3cform/trunk/plone/z3cform/crud/batch.pt	2012-04-16 05:50:01 UTC (rev 125140)
+++ plone.z3cform/trunk/plone/z3cform/crud/batch.pt	2012-04-16 05:55:46 UTC (rev 125141)
@@ -1,18 +0,0 @@
-<html xmlns="http://www.w3.org/1999/xhtml"
-      xmlns:metal="http://xml.zope.org/namespaces/metal"
-      xmlns:tal="http://xml.zope.org/namespaces/tal"
-      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
-      i18n:domain="plone.z3cform"
-      tal:omit-tag="">
-
-  <ul class="batch-navigation">
-    <li tal:repeat="page options/pages">
-      <a tal:content="page/label"
-         tal:attributes="href page/link"
-         i18n:translate=""
-         tal:omit-tag="python:page['link'] is None">
-        Previous
-      </a>
-    </li>
-  </ul>
-</html>

Deleted: plone.z3cform/trunk/plone/z3cform/crud/batch.txt
===================================================================
--- plone.z3cform/trunk/plone/z3cform/crud/batch.txt	2012-04-16 05:50:01 UTC (rev 125140)
+++ plone.z3cform/trunk/plone/z3cform/crud/batch.txt	2012-04-16 05:55:46 UTC (rev 125141)
@@ -1,57 +0,0 @@
-Batching
---------
-
-The BatchNavigation adapter is used for rendering batch navigation in CRUD
-forms.
-
-  >>> from z3c.batching.batch import Batch
-  >>> from plone.z3cform.crud.crud import BatchNavigation
-
-Here's a little batch, set to three items per page and starting at the
-third item:
-
-  >>> l = [10, 11, 12, 20, 21, 22, 30, 31, 32, 40, 41, 42, 50, 51, 52]
-  >>> batch = Batch(l, start=3, size=3)
-  >>> list(batch)
-  [20, 21, 22]
-
-We can create the BatchNavigation now.  We set the make_link attribute
-to be a function that takes an argument (the page number) and returns
-a link to it:
-
-  >>> def make_link(page):
-  ...     return u"linkto?page=%s" % page
-
-  >>> from z3c.form.testing import TestRequest
-  >>> view = BatchNavigation(batch, TestRequest())
-  >>> view.make_link = make_link
-
-We monkey-patch the template to see what's being passed:
-
-  >>> from pprint import pprint
-  >>> def template(self, **kwargs):
-  ...     print "Batch", kwargs['batch']
-  ...     print "Links", [p['link'] for p in kwargs['pages']]
-  ...     print "Labels", [p['label'] for p in kwargs['pages']]
-  >>> BatchNavigation.template = template
-  >>> view()
-  Batch <Batch start=3, size=3>
-  Links [u'linkto?page=0', u'linkto?page=0', None, u'linkto?page=2', u'linkto?page=3', u'linkto?page=4', u'linkto?page=2']
-  Labels [u'Previous', u'1', u'2', u'3', u'4', u'5', u'Next']
-
-Rendering for the first and last page, we can see that "Previous" and
-"Next" links are ommitted accordingly:
-
-  >>> batch = Batch(l, start=0, size=3)
-  >>> view.context = batch
-  >>> view()
-  Batch <Batch start=0, size=3>
-  Links [None, u'linkto?page=1', u'linkto?page=2', u'linkto?page=3', u'linkto?page=4', u'linkto?page=1']
-  Labels [u'1', u'2', u'3', u'4', u'5', u'Next']
-
-  >>> batch = Batch(l, start=12, size=3)
-  >>> view.context = batch
-  >>> view()
-  Batch <Batch start=12, size=3>
-  Links [u'linkto?page=3', u'linkto?page=0', u'linkto?page=1', u'linkto?page=2', u'linkto?page=3', None]
-  Labels [u'Previous', u'1', u'2', u'3', u'4', u'5']

Modified: plone.z3cform/trunk/plone/z3cform/crud/crud-table.pt
===================================================================
--- plone.z3cform/trunk/plone/z3cform/crud/crud-table.pt	2012-04-16 05:50:01 UTC (rev 125140)
+++ plone.z3cform/trunk/plone/z3cform/crud/crud-table.pt	2012-04-16 05:55:46 UTC (rev 125141)
@@ -1,5 +1,4 @@
  <html xmlns="http://www.w3.org/1999/xhtml"
-      xmlns:metal="http://xml.zope.org/namespaces/metal"
       xmlns:tal="http://xml.zope.org/namespaces/tal"
       xmlns:i18n="http://xml.zope.org/namespaces/i18n"
       i18n:domain="plone.z3cform"
@@ -15,16 +14,8 @@
 
   <form action="." method="post" tal:attributes="action request/getURL">
 
-    <ul tal:replace="structure view/render_batch_navigation">
-    </ul>
+    <tal:batch tal:replace="structure view/render_batch_navigation" />
 
-    <input type="hidden"
-           tal:define="batch view/batch"
-           tal:condition="python:batch.total &gt; 1"
-           tal:attributes="name python:'%spage' % view.prefix;
-                           value python:batch.number-1"
-           />
-
     <table class="listing" tal:define="rows view/subforms">
         <thead tal:define="row1 python:len(rows) and rows[0] or None"
                tal:condition="python:row1 is not None">
@@ -50,7 +41,8 @@
         <tbody>
           <tal:block repeat="row view/subforms">
             <tr tal:content="structure row/render"
-                tal:attributes="class python:repeat['row'].odd() and 'even' or 'odd'" />
+                tal:attributes="class python:repeat['row'].odd() and 'even' or 'odd'">
+            </tr>
           </tal:block>
         </tbody>
     </table>

Modified: plone.z3cform/trunk/plone/z3cform/crud/crud.py
===================================================================
--- plone.z3cform/trunk/plone/z3cform/crud/crud.py	2012-04-16 05:50:01 UTC (rev 125140)
+++ plone.z3cform/trunk/plone/z3cform/crud/crud.py	2012-04-16 05:55:46 UTC (rev 125141)
@@ -11,8 +11,9 @@
 import z3c.form.widget
 from z3c.form.interfaces import DISPLAY_MODE, INPUT_MODE, NOVALUE
 from zope.app.pagetemplate import viewpagetemplatefile
-import z3c.batching.batch
 
+from plone.batching import Batch
+from plone.batching.browser import BatchView
 
 from plone.z3cform.widget import singlecheckboxwidget_factory
 from plone.z3cform import MessageFactory as _
@@ -72,6 +73,7 @@
         """Return a URL for this item's field or None.
         """
 
+
 class AbstractCrudForm(object):
     """The AbstractCrudForm is not a form but implements methods
     necessary to comply with the ``ICrudForm`` interface:
@@ -105,6 +107,15 @@
     def link(self, item, field):
         return None
 
+
+class CrudBatchView(BatchView):
+
+    prefix = ''
+
+    def make_link(self, pagenumber):
+        return "%s?%spage=%s" % (self.request.getURL(), self.prefix, pagenumber)
+
+
 class EditSubForm(form.EditForm):
     template = viewpagetemplatefile.ViewPageTemplateFile('crud-row.pt')
 
@@ -183,38 +194,7 @@
             freakList.append(item.field.title)
         return freakList
 
-class BatchItem(object):
-    def __init__(self, label, link=None):
-        self.label = label
-        self.link = link
 
-class BatchNavigation(zope.publisher.browser.BrowserView):
-    template = viewpagetemplatefile.ViewPageTemplateFile('batch.pt')
-
-    def make_link(self, page):
-        raise NotImplementedError()
-
-    def __call__(self):
-        pages = []
-        batch = self.context
-        if batch.total == 1:
-            return u""
-        else:
-            if batch.number > 1:
-                pages.append(dict(label=_("Previous"),
-                                  link=self.make_link(page=batch.number-2)))
-
-            for index in range(batch.total):
-                link = (index != batch.number-1 and
-                        self.make_link(page=index) or None)
-                pages.append(dict(label=unicode(index+1), link=link))
-
-            if batch.number < batch.total:
-                pages.append(dict(label=_("Next"),
-                                  link=self.make_link(page=batch.number)))
-
-            return self.template(batch=batch, pages=pages)
-
 class EditForm(form.Form):
     label = _(u"Edit")
     template = viewpagetemplatefile.ViewPageTemplateFile('crud-table.pt')
@@ -244,22 +224,14 @@
     def batch(self):
         items = self.context.get_items()
         batch_size = self.context.batch_size or sys.maxint
-        page = self._page()
-        return z3c.batching.batch.Batch(
-            items, start=page*batch_size, size=batch_size)
-    #batch = zope.cachedescriptors.property.CachedProperty(batch)
+        page = int(self.request.get('%spage' % self.prefix, 0))
+        return Batch.fromPagenumber(items, batch_size, page+1)
 
     def render_batch_navigation(self):
-        navigation = BatchNavigation(self.batch, self.request)
-        def make_link(page):
-            return "%s?%spage=%s" % (self.request.getURL(), self.prefix, page)
-        navigation.make_link = make_link
-        return navigation()
+        bv = CrudBatchView(self.context, self.request)
+        bv.prefix = self.prefix
+        return bv(self.batch)
 
-    def _page(self):
-        name = '%spage' % self.prefix
-        return int(self.request.get(name, '0'))
-
     @button.buttonAndHandler(_('Apply changes'),
                              name='edit',
                              condition=lambda form: form.context.update_schema)

Modified: plone.z3cform/trunk/plone/z3cform/tests.py
===================================================================
--- plone.z3cform/trunk/plone/z3cform/tests.py	2012-04-16 05:50:01 UTC (rev 125140)
+++ plone.z3cform/trunk/plone/z3cform/tests.py	2012-04-16 05:55:46 UTC (rev 125141)
@@ -92,11 +92,6 @@
            setUp=testing.setUp, tearDown=testing.tearDown,
            ),
 
-        doctest.DocFileSuite(
-           'crud/batch.txt',
-           setUp=testing.setUp, tearDown=testing.tearDown,
-           ),
-
         doctest.DocTestSuite(
            'plone.z3cform.crud.crud',
            setUp=testing.setUp, tearDown=testing.tearDown,

Modified: plone.z3cform/trunk/setup.py
===================================================================
--- plone.z3cform/trunk/setup.py	2012-04-16 05:50:01 UTC (rev 125140)
+++ plone.z3cform/trunk/setup.py	2012-04-16 05:55:46 UTC (rev 125141)
@@ -9,7 +9,6 @@
     return (open('README.txt').read() + '\n' +
             open(join('fieldsets', 'README.txt')).read() + '\n' +
             open(join('crud', 'README.txt')).read() + '\n' +
-            open(join('crud', 'batch.txt')).read() + '\n' +
             open(os.path.join('docs', 'HISTORY.txt')).read() + '\n')
 
 setup(name='plone.z3cform',
@@ -38,8 +37,8 @@
       # feature of plone.recipe.zope2install.
       install_requires=[
           'setuptools',
+          'plone.batching',
           'z3c.form',
-          'z3c.batching',
           'zope.i18n>=3.4',
           'zope.component',
           'collective.monkeypatcher',



More information about the checkins mailing list