Skip to content

Commit 2fad0f9

Browse files
author
Richard Jones
committed
don't create instances that aren't used
1 parent 92fd8ce commit 2fad0f9

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

roundup/cgi/templating.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,15 +1434,9 @@ def batch(self):
14341434
matches = None
14351435
l = klass.filter(matches, filterspec, sort, group)
14361436

1437-
# map the item ids to instances
1438-
if self.classname == 'user':
1439-
klass = HTMLUser
1440-
else:
1441-
klass = HTMLItem
1442-
l = [klass(self.client, self.classname, item) for item in l]
1443-
1444-
# return the batch object
1445-
return Batch(self.client, l, self.pagesize, self.startwith)
1437+
# return the batch object, using IDs only
1438+
return Batch(self.client, l, self.pagesize, self.startwith,
1439+
classname=self.classname)
14461440

14471441
# extend the standard ZTUtils Batch object to remove dependency on
14481442
# Acquisition and add a couple of useful methods
@@ -1453,7 +1447,8 @@ class Batch(ZTUtils.Batch):
14531447
========= ========================================================
14541448
Parameter Usage
14551449
========= ========================================================
1456-
sequence a list of HTMLItems
1450+
sequence a list of HTMLItems or item ids
1451+
classname if sequence is a list of ids, this is the class of item
14571452
size how big to make the sequence.
14581453
start where to start (0-indexed) in the sequence.
14591454
end where to end (0-indexed) in the sequence.
@@ -1470,10 +1465,11 @@ class Batch(ZTUtils.Batch):
14701465
"sequence_length" is the length of the original, unbatched, sequence.
14711466
'''
14721467
def __init__(self, client, sequence, size, start, end=0, orphan=0,
1473-
overlap=0):
1468+
overlap=0, classname=None):
14741469
self.client = client
14751470
self.last_index = self.last_item = None
14761471
self.current_item = None
1472+
self.classname = classname
14771473
self.sequence_length = len(sequence)
14781474
ZTUtils.Batch.__init__(self, sequence, size, start, end, orphan,
14791475
overlap)
@@ -1493,8 +1489,15 @@ def __getitem__(self, index):
14931489
self.last_item = self.current_item
14941490
self.last_index = index
14951491

1496-
self.current_item = self._sequence[index + self.first]
1497-
return self.current_item
1492+
item = self._sequence[index + self.first]
1493+
if self.classname:
1494+
# map the item ids to instances
1495+
if self.classname == 'user':
1496+
item = HTMLUser(self.client, self.classname, item)
1497+
else:
1498+
item = HTMLItem(self.client, self.classname, item)
1499+
self.current_item = item
1500+
return item
14981501

14991502
def propchanged(self, property):
15001503
''' Detect if the property marked as being the group property

0 commit comments

Comments
 (0)