app/soc/logic/models/base.py
changeset 2980 cbfd8e12527a
parent 2968 7ba28890eb75
child 2989 4ab340430bfa
equal deleted inserted replaced
2978:2b3c39483f6f 2980:cbfd8e12527a
   584 
   584 
   585       result.extend(data)
   585       result.extend(data)
   586       offset = offset + chunk
   586       offset = offset + chunk
   587 
   587 
   588     return result
   588     return result
       
   589 
       
   590   def getBatchOfData(self, filter=None, order=None, next_key=None):
       
   591     """Returns one batch of entities
       
   592 
       
   593     Args:
       
   594       filter: a dict for the properties that the entities should have
       
   595       order: a list with the sort order
       
   596       next_key: a key for the first entity that should be returned
       
   597 
       
   598     Returns:
       
   599       A tuple: list of fetched entities and key value for the entity
       
   600       that should be fetched at first for the next batch
       
   601     """
       
   602 
       
   603     query = self.getQueryForFields(filter=filter, order=order)
       
   604 
       
   605     if next_key is not None:
       
   606       query.filter('__key__ >=', next_key)
       
   607 
       
   608     entities = query.fetch(self.BATCH_SIZE + 1)
       
   609 
       
   610     next_key = None
       
   611     if len(entities) == self.BATCH_SIZE + 1:
       
   612       next_entity = entities.pop()
       
   613       next_key = next_entity.key()
       
   614 
       
   615     return entities, next_key
       
   616 
   589   # pylint: disable-msg=C0103
   617   # pylint: disable-msg=C0103
   590   def entityIterator(self, queryGen, batch_size = 100):
   618   def entityIterator(self, queryGen, batch_size=100):
   591     """Iterator that yields an entity in batches.
   619     """Iterator that yields an entity in batches.
   592 
   620 
   593     Args:
   621     Args:
   594       queryGen: should return a Query object
   622       queryGen: should return a Query object
   595       batchSize: how many entities to retrieve in one datastore call
   623       batchSize: how many entities to retrieve in one datastore call