comparison roundup/cgi/templating.py @ 1182:cb35cf3db0e0

don't create instances that aren't used
author Richard Jones <richard@users.sourceforge.net>
date Mon, 23 Sep 2002 01:01:06 +0000
parents af104fa52746
children 08a13a84ed43
comparison
equal deleted inserted replaced
1181:49aebf5a8691 1182:cb35cf3db0e0
1432 re.findall(r'\b\w{2,25}\b', self.search_text), klass) 1432 re.findall(r'\b\w{2,25}\b', self.search_text), klass)
1433 else: 1433 else:
1434 matches = None 1434 matches = None
1435 l = klass.filter(matches, filterspec, sort, group) 1435 l = klass.filter(matches, filterspec, sort, group)
1436 1436
1437 # map the item ids to instances 1437 # return the batch object, using IDs only
1438 if self.classname == 'user': 1438 return Batch(self.client, l, self.pagesize, self.startwith,
1439 klass = HTMLUser 1439 classname=self.classname)
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)
1446 1440
1447 # extend the standard ZTUtils Batch object to remove dependency on 1441 # extend the standard ZTUtils Batch object to remove dependency on
1448 # Acquisition and add a couple of useful methods 1442 # Acquisition and add a couple of useful methods
1449 class Batch(ZTUtils.Batch): 1443 class Batch(ZTUtils.Batch):
1450 ''' Use me to turn a list of items, or item ids of a given class, into a 1444 ''' Use me to turn a list of items, or item ids of a given class, into a
1451 series of batches. 1445 series of batches.
1452 1446
1453 ========= ======================================================== 1447 ========= ========================================================
1454 Parameter Usage 1448 Parameter Usage
1455 ========= ======================================================== 1449 ========= ========================================================
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
1457 size how big to make the sequence. 1452 size how big to make the sequence.
1458 start where to start (0-indexed) in the sequence. 1453 start where to start (0-indexed) in the sequence.
1459 end where to end (0-indexed) in the sequence. 1454 end where to end (0-indexed) in the sequence.
1460 orphan if the next batch would contain less items than this 1455 orphan if the next batch would contain less items than this
1461 value, then it is combined with this batch 1456 value, then it is combined with this batch
1468 the batch. 1463 the batch.
1469 1464
1470 "sequence_length" is the length of the original, unbatched, sequence. 1465 "sequence_length" is the length of the original, unbatched, sequence.
1471 ''' 1466 '''
1472 def __init__(self, client, sequence, size, start, end=0, orphan=0, 1467 def __init__(self, client, sequence, size, start, end=0, orphan=0,
1473 overlap=0): 1468 overlap=0, classname=None):
1474 self.client = client 1469 self.client = client
1475 self.last_index = self.last_item = None 1470 self.last_index = self.last_item = None
1476 self.current_item = None 1471 self.current_item = None
1472 self.classname = classname
1477 self.sequence_length = len(sequence) 1473 self.sequence_length = len(sequence)
1478 ZTUtils.Batch.__init__(self, sequence, size, start, end, orphan, 1474 ZTUtils.Batch.__init__(self, sequence, size, start, end, orphan,
1479 overlap) 1475 overlap)
1480 1476
1481 # overwrite so we can late-instantiate the HTMLItem instance 1477 # overwrite so we can late-instantiate the HTMLItem instance
1491 # (for some reason, index 0 is fetched twice) 1487 # (for some reason, index 0 is fetched twice)
1492 if index != self.last_index: 1488 if index != self.last_index:
1493 self.last_item = self.current_item 1489 self.last_item = self.current_item
1494 self.last_index = index 1490 self.last_index = index
1495 1491
1496 self.current_item = self._sequence[index + self.first] 1492 item = self._sequence[index + self.first]
1497 return self.current_item 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
1498 1501
1499 def propchanged(self, property): 1502 def propchanged(self, property):
1500 ''' Detect if the property marked as being the group property 1503 ''' Detect if the property marked as being the group property
1501 changed in the last iteration fetch 1504 changed in the last iteration fetch
1502 ''' 1505 '''

Roundup Issue Tracker: http://roundup-tracker.org/