[Checkins] SVN: zc.table/trunk/s release a batching table formatter that has seen a fair bit of use

Fred L. Drake, Jr. fdrake at gmail.com
Tue Jun 27 18:19:15 EDT 2006


Log message for revision 68873:
  release a batching table formatter that has seen a fair bit of use

Changed:
  U   zc.table/trunk/setup.py
  A   zc.table/trunk/src/zc/table/batching.pt
  A   zc.table/trunk/src/zc/table/batching.py

-=-
Modified: zc.table/trunk/setup.py
===================================================================
--- zc.table/trunk/setup.py	2006-06-27 22:00:52 UTC (rev 68872)
+++ zc.table/trunk/setup.py	2006-06-27 22:19:14 UTC (rev 68873)
@@ -12,7 +12,7 @@
     namespace_packages=['zc'],
     package_data = {
     '': ['*.txt', '*.zcml', '*.gif', '*.js'],
-    'zc.table':['resources/*'],
+    'zc.table':['resources/*', '*.pt'],
     },
 
     zip_safe=False,

Added: zc.table/trunk/src/zc/table/batching.pt
===================================================================
--- zc.table/trunk/src/zc/table/batching.pt	2006-06-27 22:00:52 UTC (rev 68872)
+++ zc.table/trunk/src/zc/table/batching.pt	2006-06-27 22:19:14 UTC (rev 68873)
@@ -0,0 +1,54 @@
+<script type="text/javascript" lang="Javascript1.1">
+
+  function zc_intranet_table_batching_do_it(el, direction) {
+    var element_name = el.attributes.batch_change_name.value;
+    var element = document.getElementById(element_name);
+    element.value = direction;
+    element.form.submit();
+  }
+
+</script>
+
+<input type="hidden" value="" tal:attributes="
+    name view/batch_change_name;
+    id view/batch_change_name;" />
+<input
+    type="hidden"
+    tal:attributes="
+      name view/batch_start_name;
+      id view/batch_start_name;
+      value view/batch_start;
+    " />
+
+<div
+    style="text-align: center; font-weight: bold"
+    tal:condition="python:
+        (view.items and (
+            (view.previous_batch_start is not None) or
+            (view.next_batch_start is not None)))"
+    i18n:domain="zc.intranet"
+    class="zc-intranet-table-batching-pager">
+  <a
+      style="margin-right: 1ex"
+      tal:attributes="batch_change_name view/batch_change_name"
+      tal:condition="python: view.previous_batch_start is not None"
+      onclick="javascript:zc_intranet_table_batching_do_it(this, 'back');"
+      class="zc-intranet-table-batching-pager-prev"
+      >&lt; <span i18n:translate="">Prev</span></a>
+  <span
+      style="margin-right: 1ex"
+      tal:condition="python: view.previous_batch_start is None"
+      class="zc-intranet-table-batching-pager-prev"
+      >&lt; <span i18n:translate="">Prev</span></span>
+  <a
+      tal:attributes="batch_change_name view/batch_change_name"
+      tal:condition="python: view.next_batch_start is not None"
+      onclick="javascript:zc_intranet_table_batching_do_it(this, 'next')"
+      class="zc-intranet-table-batching-pager-next"
+      ><span i18n:translate="">Next</span> &gt;</a>
+  <span
+      style="margin-right: 1ex"
+      tal:condition="python: view.next_batch_start is None"
+      class="zc-intranet-table-batching-pager-next"
+      ><span i18n:translate="">Next</span> &gt;</span>
+</div>


Property changes on: zc.table/trunk/src/zc/table/batching.pt
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: zc.table/trunk/src/zc/table/batching.py
===================================================================
--- zc.table/trunk/src/zc/table/batching.py	2006-06-27 22:00:52 UTC (rev 68872)
+++ zc.table/trunk/src/zc/table/batching.py	2006-06-27 22:19:14 UTC (rev 68873)
@@ -0,0 +1,127 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Visible Source
+# License, Version 1.0 (ZVSL).  A copy of the ZVSL 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.
+#
+##############################################################################
+"""Table formatting and configuration
+"""
+from zope import interface
+from zope.app import pagetemplate
+
+import zc.table.table
+import zc.table.interfaces
+
+unspecified = object()
+
+class Formatter(zc.table.table.FormSortFormatterMixin,
+                zc.table.table.AlternatingRowFormatterMixin,
+                zc.table.table.Formatter):
+    interface.classProvides(zc.table.interfaces.IFormatterFactory)
+
+    def __init__(self, context, request, items, visible_column_names=None,
+                 batch_start=None, batch_size=unspecified, prefix=None,
+                 columns=None, sort_on=None):
+        if batch_size is unspecified:
+            batch_size = 20
+
+        if prefix is None:
+            prefix = 'zc.intranet.table'
+
+        super(Formatter, self).__init__(
+            context, request, items, visible_column_names,
+            batch_start, batch_size, prefix, columns,
+            sort_on=sort_on,
+            )
+
+    @property
+    def batch_change_name(self):
+        return self.prefix + '.batch_change'
+
+    @property
+    def batch_start_name(self):
+        return self.prefix + '.batch_start'
+
+    _batch_start = None
+    _batch_start_computed = False
+
+    def setPrefix(self, prefix):
+        super(Formatter, self).setPrefix(prefix)
+        self._batch_start_computed = False
+
+    @apply
+    def batch_start():
+        def fget(self):
+            if not self._batch_start_computed:
+                self.updateBatching()
+            return self._batch_start
+        def fset(self, value):
+            self._batch_start = value
+            self._batch_start_computed = False
+        def fdel(self):
+            self._batch_start = None
+        return property(fget, fset, fdel)
+
+    def updateBatching(self):
+        request = self.request
+        if self._batch_start is None:
+            try:
+                self.batch_start = int(request.get(self.batch_start_name, '0'))
+            except ValueError:
+                self._batch_start = 0
+        # Handle requests to change batches:
+        change = request.get(self.batch_change_name)
+        if change == "next":
+            self._batch_start += self.batch_size
+            try:
+                length = len(self.items)
+            except TypeError:
+                for length, ob in enumerate(self.items):
+                    if length > self._batch_start:
+                        break
+                else:
+                    self._batch_start = length
+            else:
+                if self._batch_start > length:
+                    self._batch_start = length
+        elif change == "back":
+            self._batch_start -= self.batch_size
+            if self._batch_start < 0:
+                self._batch_start = 0
+
+        self.next_batch_start = self._batch_start + self.batch_size
+        try:
+            self.items[self.next_batch_start]
+        except IndexError:
+            self.next_batch_start = None
+
+        self.previous_batch_start = self._batch_start - self.batch_size
+        if self.previous_batch_start < 0:
+            self.previous_batch_start = None
+        self._batch_start_computed = True
+
+    batching_template = pagetemplate.ViewPageTemplateFile('batching.pt')
+    def renderExtra(self):
+        if not self._batch_start_computed:
+            self.updateBatching()
+        return self.batching_template() + super(Formatter, self).renderExtra()
+
+    def __call__(self):
+        return ('\n'
+                '<div style="width: 100%"> '
+                '<!-- this div is a workaround for an IE bug -->\n'
+                '<table class="listingdescription" style="width:100%" '
+                + ('name="%s">\n' % self.prefix)
+                + self.renderContents() +
+                '</table>\n'
+                + self.renderExtra() +
+                '</div> <!-- end IE bug workaround -->\n'
+               )


Property changes on: zc.table/trunk/src/zc/table/batching.py
___________________________________________________________________
Name: svn:mime-type
   + text/x-python
Name: svn:eol-style
   + native



More information about the Checkins mailing list