app/soc/logic/models/base.py
changeset 363 d35ffa6ca643
parent 354 b931c74abbee
child 368 f90f9b22751a
equal deleted inserted replaced
362:d904f4a76f6f 363:d35ffa6ca643
   116     if not all(kwargs.values()):
   116     if not all(kwargs.values()):
   117       return None
   117       return None
   118 
   118 
   119     return self._keyName(**kwargs)
   119     return self._keyName(**kwargs)
   120 
   120 
       
   121   def extractKeyFields(self, fields):
       
   122     """Extracts all the fields from that are in the mode's key_fields property
       
   123 
       
   124     Args:
       
   125       fields: A dict from which the fields should be extracted
       
   126     """
       
   127 
       
   128     key_fields = {}
       
   129     keys = fields.keys()
       
   130 
       
   131     for key in keys[:]:
       
   132       if key in self._model.key_fields:
       
   133         key_fields[key] = fields[key]
       
   134 
       
   135     return key_fields
       
   136 
   121   def getForLimitAndOffset(self, limit, offset=0):
   137   def getForLimitAndOffset(self, limit, offset=0):
   122     """Returns entities for given offset and limit or None if not found.
   138     """Returns entities for given offset and limit or None if not found.
   123 
   139 
   124     Args:
   140     Args:
   125       limit: max amount of entities to return
   141       limit: max amount of entities to return
   197 
   213 
   198     # attempt to retrieve the existing entity
   214     # attempt to retrieve the existing entity
   199     key_name  = self.getKeyNameForFields(**kwargs)
   215     key_name  = self.getKeyNameForFields(**kwargs)
   200 
   216 
   201     return self.updateOrCreateFromKeyName(properties, key_name)
   217     return self.updateOrCreateFromKeyName(properties, key_name)
   202   
   218 
       
   219   def isDeletable(self, entity):
       
   220     """Returns whether the specified entity can be deleted
       
   221     """
       
   222 
       
   223     # TODO(pawel.solyga): Create specific delete method for Sponsor model
       
   224     # Check if Sponsor can be deleted (has no Hosts and Programs)
       
   225     return True
       
   226 
   203   def delete(self, entity):
   227   def delete(self, entity):
   204     """Delete existing entity from datastore.
   228     """Delete existing entity from datastore.
   205     
   229     
   206     Args:
   230     Args:
   207       entity: an existing entity in datastore
   231       entity: an existing entity in datastore