Code

don't create instances that aren't used
authorrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Mon, 23 Sep 2002 01:01:06 +0000 (01:01 +0000)
committerrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Mon, 23 Sep 2002 01:01:06 +0000 (01:01 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1206 57a73879-2fb5-44c3-a270-3262357dd7e2

roundup/cgi/templating.py

index 1de56e1ce1d42b1503959af6015915b1961f6203..781afb0424f69210f6099890a51e675d09e3b08f 100644 (file)
@@ -1434,15 +1434,9 @@ function help_window(helpurl, width, height) {
             matches = None
         l = klass.filter(matches, filterspec, sort, group)
 
-        # map the item ids to instances
-        if self.classname == 'user':
-            klass = HTMLUser
-        else:
-            klass = HTMLItem
-        l = [klass(self.client, self.classname, item) for item in l]
-
-        # return the batch object
-        return Batch(self.client, l, self.pagesize, self.startwith)
+        # return the batch object, using IDs only
+        return Batch(self.client, l, self.pagesize, self.startwith,
+            classname=self.classname)
 
 # extend the standard ZTUtils Batch object to remove dependency on
 # Acquisition and add a couple of useful methods
@@ -1453,7 +1447,8 @@ class Batch(ZTUtils.Batch):
         ========= ========================================================
         Parameter  Usage
         ========= ========================================================
-        sequence  a list of HTMLItems
+        sequence  a list of HTMLItems or item ids
+        classname if sequence is a list of ids, this is the class of item
         size      how big to make the sequence.
         start     where to start (0-indexed) in the sequence.
         end       where to end (0-indexed) in the sequence.
@@ -1470,10 +1465,11 @@ class Batch(ZTUtils.Batch):
         "sequence_length" is the length of the original, unbatched, sequence.
     '''
     def __init__(self, client, sequence, size, start, end=0, orphan=0,
-            overlap=0):
+            overlap=0, classname=None):
         self.client = client
         self.last_index = self.last_item = None
         self.current_item = None
+        self.classname = classname
         self.sequence_length = len(sequence)
         ZTUtils.Batch.__init__(self, sequence, size, start, end, orphan,
             overlap)
@@ -1493,8 +1489,15 @@ class Batch(ZTUtils.Batch):
             self.last_item = self.current_item
             self.last_index = index
 
-        self.current_item = self._sequence[index + self.first]
-        return self.current_item
+        item = self._sequence[index + self.first]
+        if self.classname:
+            # map the item ids to instances
+            if self.classname == 'user':
+                item = HTMLUser(self.client, self.classname, item)
+            else:
+                item = HTMLItem(self.client, self.classname, item)
+        self.current_item = item
+        return item
 
     def propchanged(self, property):
         ''' Detect if the property marked as being the group property