app/soc/logic/models/base.py
changeset 512 aae25d2b4464
parent 499 d22e4fe8e64b
child 533 ba3309b2fd30
equal deleted inserted replaced
511:52557918ec8f 512:aae25d2b4464
   206       entity = None
   206       entity = None
   207 
   207 
   208     return entity
   208     return entity
   209 
   209 
   210   def getIfFields(self, fields):
   210   def getIfFields(self, fields):
   211     """Returns entity for supplied link name if one exists.
   211     """Returns entity for supplied link ID if one exists.
   212 
   212 
   213     Args:
   213     Args:
   214       fields: the fields of the entity that uniquely identifies it
   214       fields: the fields of the entity that uniquely identifies it
   215 
   215 
   216     Returns:
   216     Returns:
   217       * None if a field is false.
   217       * None if a field is false.
   218       * Entity for supplied fields
   218       * Entity for supplied fields
   219 
   219 
   220     Raises:
   220     Raises:
   221       out_of_band.ErrorResponse if link name is not false, but no entity
   221       out_of_band.ErrorResponse if link ID is not false, but no entity
   222       with the supplied link name exists in the Datastore.
   222       with the supplied link ID exists in the Datastore.
   223     """
   223     """
   224 
   224 
   225     if not all(fields.values()):
   225     if not all(fields.values()):
   226       # exit without error, to let view know that link_name was not supplied
   226       # exit without error, to let view know that link_id was not supplied
   227       return None
   227       return None
   228 
   228 
   229     entity = self.getFromFields(**fields)
   229     entity = self.getFromFields(**fields)
   230 
   230 
   231     if entity:
   231     if entity:
   232       # an entity exist for this link_name, so return that entity
   232       # an entity exist for this link_id, so return that entity
   233       return entity
   233       return entity
   234 
   234 
   235     format_text = ugettext_lazy('"%(key)s" is "%(value)s"')
   235     format_text = ugettext_lazy('"%(key)s" is "%(value)s"')
   236 
   236 
   237     msg_pairs = [format_text % {'key': key, 'value': value}
   237     msg_pairs = [format_text % {'key': key, 'value': value}