app/soc/logic/models/base.py
changeset 2709 7a595f688ab5
parent 2364 a1cbd3143277
child 2736 8f3935f0f4ba
equal deleted inserted replaced
2708:db544114b158 2709:7a595f688ab5
   196     values = self.getKeyValuesFromFields(dictionary)
   196     values = self.getKeyValuesFromFields(dictionary)
   197     key_fields = dicts.zip(keys, values)
   197     key_fields = dicts.zip(keys, values)
   198 
   198 
   199     return key_fields
   199     return key_fields
   200 
   200 
   201   def getFromKeyName(self, key_name):
   201   def getFromKeyName(self, key_name, parent=None):
   202     """"Returns entity for key_name or None if not found.
   202     """Returns entity for key_name or None if not found.
   203 
   203 
   204     Args:
   204     Args:
   205       key_name: key name of entity
   205       key_name: key name of entity
       
   206       parent: parent of the entity
   206     """
   207     """
   207 
   208 
   208     if self._id_based:
   209     if self._id_based:
   209       raise Error("getFromKeyName called on an id based logic")
   210       raise Error("getFromKeyName called on an id based logic")
   210 
   211 
   211     if not key_name:
   212     if not key_name:
   212       raise InvalidArgumentError
   213       raise InvalidArgumentError
   213 
   214 
   214     return self._model.get_by_key_name(key_name)
   215     return self._model.get_by_key_name(key_name, parent=parent)
   215 
   216 
   216   def getFromID(self, id):
   217   def getFromID(self, id, parent=None):
   217     """Returns entity for id or None if not found.
   218     """Returns entity for id or None if not found.
   218 
   219 
   219     Args:
   220     Args:
   220       id: id of entity
   221       id: id of entity
       
   222       parent: parent of the entity
   221     """
   223     """
   222 
   224 
   223     if not self._id_based:
   225     if not self._id_based:
   224       raise Error("getFromID called on a not id based logic")
   226       raise Error("getFromID called on a not id based logic")
   225 
   227 
   226     if not id:
   228     if not id:
   227       raise InvalidArgumentError
   229       raise InvalidArgumentError
   228 
   230 
   229     return self._model.get_by_id(id)
   231     return self._model.get_by_id(id, parent=parent)
   230 
   232 
   231   def getFromKeyNameOr404(self, key_name):
   233   def getFromKeyNameOr404(self, key_name):
   232     """Like getFromKeyName but expects to find an entity.
   234     """Like getFromKeyName but expects to find an entity.
   233 
   235 
   234     Raises:
   236     Raises: