[CMF-checkins]
SVN: CMF/branches/tseaver-viewification/CMFDefault/browser/
- added utils for batch navigation
Yvo Schubbe
y.2006_ at wcm-solutions.de
Tue Jan 31 13:09:45 EST 2006
Log message for revision 41518:
- added utils for batch navigation
Changed:
U CMF/branches/tseaver-viewification/CMFDefault/browser/configure.zcml
A CMF/branches/tseaver-viewification/CMFDefault/browser/templates/batch_widgets.pt
U CMF/branches/tseaver-viewification/CMFDefault/browser/utils.py
-=-
Modified: CMF/branches/tseaver-viewification/CMFDefault/browser/configure.zcml
===================================================================
--- CMF/branches/tseaver-viewification/CMFDefault/browser/configure.zcml 2006-01-31 18:00:39 UTC (rev 41517)
+++ CMF/branches/tseaver-viewification/CMFDefault/browser/configure.zcml 2006-01-31 18:09:45 UTC (rev 41518)
@@ -74,4 +74,12 @@
layer="cmf"
/>
+ <browser:page
+ for="*"
+ name="batch_widget"
+ template="templates/batch_widgets.pt"
+ permission="zope2.View"
+ layer="cmf"
+ />
+
</configure>
Added: CMF/branches/tseaver-viewification/CMFDefault/browser/templates/batch_widgets.pt
===================================================================
--- CMF/branches/tseaver-viewification/CMFDefault/browser/templates/batch_widgets.pt 2006-01-31 18:00:39 UTC (rev 41517)
+++ CMF/branches/tseaver-viewification/CMFDefault/browser/templates/batch_widgets.pt 2006-01-31 18:09:45 UTC (rev 41518)
@@ -0,0 +1,22 @@
+<html>
+<body>
+
+ <metal:macro metal:define-macro="navigation"
+ tal:define="prev_info view/navigation_previous;
+ next_info view/navigation_next"
+ ><p class="BatchNavigation" tal:condition="python: prev_info or next_info"
+ ><tal:case tal:condition="prev_info">
+ <a href="" tal:attributes="href prev_info/url"
+ tal:content="prev_info/title"
+ i18n:translate="">PREVIOUS N ITEMS</a></tal:case
+ ><tal:case tal:condition="python: prev_info and next_info">
+ </tal:case
+ ><tal:case tal:condition="next_info">
+ <a href="" tal:attributes="href next_info/url"
+ tal:content="next_info/title"
+ i18n:translate="">NEXT N ITEMS</a></tal:case
+ ></p
+></metal:macro>
+
+</body>
+</html>
Modified: CMF/branches/tseaver-viewification/CMFDefault/browser/utils.py
===================================================================
--- CMF/branches/tseaver-viewification/CMFDefault/browser/utils.py 2006-01-31 18:00:39 UTC (rev 41517)
+++ CMF/branches/tseaver-viewification/CMFDefault/browser/utils.py 2006-01-31 18:09:45 UTC (rev 41518)
@@ -15,6 +15,7 @@
$Id$
"""
+from ZTUtils import Batch
from ZTUtils import make_query
from Products.CMFCore.utils import getToolByName
@@ -159,3 +160,63 @@
vars = [ {'name': name, 'value': value}
for name, value in html_marshal(**kw) ]
return tuple(vars)
+
+
+class BatchViewBase(ViewBase):
+
+ # helpers
+
+ _BATCH_SIZE = 25
+
+ @memoize
+ def _getBatchStart(self):
+ return self.request.form.get('b_start', 0)
+
+ @memoize
+ def _getBatchObj(self):
+ b_start = self._getBatchStart()
+ items = self._getItems()
+ return Batch(items, self._BATCH_SIZE, b_start, orphan=0)
+
+ @memoize
+ def _getNavigationURL(self, b_start):
+ target = self._getViewURL()
+ kw = self._getHiddenVars()
+
+ kw['b_start'] = b_start
+ for k, v in kw.items():
+ if not v or k == 'portal_status_message':
+ del kw[k]
+
+ query = kw and ('?%s' % make_query(kw)) or ''
+ return u'%s%s' % (target, query)
+
+ # interface
+
+ @memoize
+ def navigation_previous(self):
+ batch_obj = self._getBatchObj().previous
+ if batch_obj is None:
+ return None
+
+ length = len(batch_obj)
+ url = self._getNavigationURL(batch_obj.first)
+ if length == 1:
+ title = _(u'Previous item')
+ else:
+ title = _(u'Previous ${count} items', mapping={'count': length})
+ return {'title': title, 'url': url}
+
+ @memoize
+ def navigation_next(self):
+ batch_obj = self._getBatchObj().next
+ if batch_obj is None:
+ return None
+
+ length = len(batch_obj)
+ url = self._getNavigationURL(batch_obj.first)
+ if length == 1:
+ title = _(u'Next item')
+ else:
+ title = _(u'Next ${count} items', mapping={'count': length})
+ return {'title': title, 'url': url}
More information about the CMF-checkins
mailing list