app/soc/logic/models/base.py
changeset 433 001b981be45e
parent 432 1851d67a1004
child 435 829fe8302a8b
equal deleted inserted replaced
432:1851d67a1004 433:001b981be45e
   208     """
   208     """
   209 
   209 
   210     query = self._model.all()
   210     query = self._model.all()
   211     return query.fetch(limit, offset)
   211     return query.fetch(limit, offset)
   212 
   212 
       
   213   def getForFields(self, properties, unique=False, limit=1000, offset=0):
       
   214     """Returns all entities that have the specified properties
       
   215 
       
   216     Args:
       
   217       properties: the properties that the entity should have
       
   218       unique: if set, only the first item from the resultset will be returned
       
   219       limit: max amount of entities to return
       
   220       offset: optional number of results to skip first; default zero.
       
   221     """
       
   222 
       
   223     if not properties:
       
   224       raise Error("Properties did not contain any values")
       
   225 
       
   226     format_text = '%(key)s = :%(key)s'
       
   227     msg_pairs = [format_text % {'key': key} for key in properties.iterkeys()]
       
   228     joined_pairs = ' AND '.join(msg_pairs)
       
   229     condition = 'WHERE %s' % joined_pairs
       
   230 
       
   231     query = self._model.gql(condition, **properties)
       
   232 
       
   233     if unique:
       
   234       return query.get()
       
   235 
       
   236     result = query.fetch(limit, offset)
       
   237     return result
       
   238 
   213   def updateModelProperties(self, model, **model_properties):
   239   def updateModelProperties(self, model, **model_properties):
   214     """Update existing model entity using supplied model properties.
   240     """Update existing model entity using supplied model properties.
   215 
   241 
   216     Args:
   242     Args:
   217       model: a model entity
   243       model: a model entity