[Zope-CVS] CVS: Products/BTreeFolder2 - BTreeFolder2.py:1.3 contents.dtml:1.2
Shane Hathaway
shane@cvs.zope.org
Wed, 8 May 2002 14:55:12 -0400
Update of /cvs-repository/Products/BTreeFolder2
In directory cvs.zope.org:/tmp/cvs-serv7591
Modified Files:
BTreeFolder2.py contents.dtml
Log Message:
Added batching, removed unused code, and added tests.
=== Products/BTreeFolder2/BTreeFolder2.py 1.2 => 1.3 ===
ob = dispatcher._getOb(id)
if REQUEST is not None:
- return dispatcher.manage_main(self, REQUEST, update_menu=1)
+ return dispatcher.manage_main(dispatcher, REQUEST, update_menu=1)
listtext0 = '''<select name="ids:list" multiple size="%s">
@@ -80,8 +80,6 @@
_tree = None # OOBTree: { id -> object }
_count = None # A BTrees.Length
- #_mt_index = None # OOBTree: { meta_type -> OIBTree: { id -> 1 } }
-
_v_nextid = 0 # The next computed ID
@@ -93,14 +91,12 @@
def _init(self):
self._tree = OOBTree()
self._count = Length()
- #self._mt_index = OOBTree()
def _populateFromFolder(self, source):
ids = source.objectIds()
tree = self._tree
count = self._count
- #mti = self._mt_index
for name in ids:
value = source._getOb(name, None)
if value is not None:
@@ -110,15 +106,6 @@
% name)
tree[name] = aq_base(value)
count.change(1)
-## # Update the meta type index.
-## meta_type = getattr(value, 'meta_type', None)
-## if meta_type is None:
-## continue
-## ids = mti.get(meta_type, None)
-## if ids is None:
-## ids = OIBTree()
-## mti[meta_type] = ids
-## ids[key] = 1
def _getOb(self, id, default=_marker):
@@ -139,50 +126,47 @@
"""
tree = self._tree
tree[id] = object
-
-## mti = self._mt_index
-## meta_type = getattr(object, 'meta_type', None)
-## if meta_type is not None:
-## ids = mti.get(meta_type, None)
-## if ids is None:
-## ids = OIBTree()
-## mti[meta_type] = ids
-## ids[id] = 1
-
self._count.change(1)
def _delOb(self, id):
tree = self._tree
- #meta_type = getattr(tree[id], 'meta_type', None)
del tree[id]
self._count.change(-1)
-## if meta_type is not None:
-## mti = self._mt_index
-## ids = mti.get(meta_type, None)
-## if ids is not None and ids.has_key(id):
-## del ids[id]
- security.declareProtected(view_management_screens,
- 'manage_main_listing')
- def manage_main_listing(self, REQUEST):
- '''Generates a select box.'''
- if REQUEST.has_key('dtpref_rows'):
- pref_rows = REQUEST['dtpref_rows']
+ security.declareProtected(view_management_screens, 'getBatchObjectListing')
+ def getBatchObjectListing(self, REQUEST=None):
+ if REQUEST is None:
+ REQUEST = {}
+ pref_rows = int(REQUEST.get('dtpref_rows', 20))
+ b_start = int(REQUEST.get('b_start', 1))
+ b_count = int(REQUEST.get('b_count', 1000))
+ b_end = b_start + b_count - 1
+ url = self.absolute_url() + '/manage_main'
+ idlist = self.objectIds() # Pre-sorted.
+ count = self.objectCount()
+
+ if b_end < count:
+ next_url = url + '?b_start=%d' % (b_start + b_count)
else:
- pref_rows = 20
- rval = []
- rval.append(listtext0 % pref_rows)
- counter = 0
- idlist = list(self.objectIds())
- idlist.sort()
- for id in idlist:
- html_fmt = escape(id)
- rval.append(listtext1 % html_fmt)
- counter = counter + 1
- rval.append(listtext2)
- return ''.join(rval)
+ b_end = count
+ next_url = ''
+
+ if b_start > 1:
+ prev_url = url + '?b_start=%d' % max(b_start - b_count, 1)
+ else:
+ prev_url = ''
+
+ formatted = []
+ formatted.append(listtext0 % pref_rows)
+ for i in range(b_start - 1, b_end):
+ formatted.append(listtext1 % escape(idlist[i]))
+ formatted.append(listtext2)
+ return {'b_start': b_start, 'b_end': b_end,
+ 'prev_batch_url': prev_url,
+ 'next_batch_url': next_url,
+ 'formatted_list': ''.join(formatted)}
security.declareProtected(view_management_screens,
@@ -230,17 +214,6 @@
if spec is not None:
raise RuntimeError, (
'BTreeFolder2 does not support lookups by meta_type.')
-## if isinstance(spec, StringType):
-## spec = [spec]
-## mti = self._mt_index
-## set = None
-## for meta_type in spec:
-## ids = mti.get(meta_type, None)
-## if ids is not None:
-## set = union(set, ids.keys())
-## if set is None:
-## set = ()
-## return set
else:
return self._tree.keys()
@@ -271,9 +244,6 @@
return LazyMap(lambda (k, v):
{'id': k, 'meta_type': getattr(v, 'meta_type', None)},
self._tree.items(), self._count())
-
- # _objects is needed to make superValues() work.
- #_objects = ComputedAttribute(objectMap)
# superValues() looks for the _objects attribute, but the implementation
# would be inefficient, so superValues() support is disabled.
=== Products/BTreeFolder2/contents.dtml 1.1.1.1 => 1.2 ===
<form action="&dtml-URL1;/" name="objectItems" method="post">
-<dtml-if objectIds>
-<p><em>Item count: <dtml-var "_.len(objectIds)"></em></p>
-<dtml-var expr="manage_main_listing(REQUEST)">
+<dtml-if objectCount>
+<dtml-with expr="getBatchObjectListing(REQUEST)" mapping>
+
+<p>
+<dtml-if prev_batch_url><a href="&dtml-prev_batch_url;"><<</a></dtml-if>
+<em>Items <dtml-var b_start> through <dtml-var b_end> of <dtml-var objectCount></em>
+<dtml-if next_batch_url><a href="&dtml-next_batch_url;">>></a></dtml-if>
+</p>
+
+<dtml-var formatted_list>
<table cellspacing="0" cellpadding="2" border="0">
<tr>
@@ -115,6 +122,7 @@
</tr>
</table>
+</dtml-with>
<dtml-else>
<table cellspacing="0" cellpadding="2" border="0">
<tr>