コード例 #1
0
 def deconvert(self, value):
     '''Changes a stored Reference to its Model'''
     if value is None: return None
     dict = yaml.load(value)
     assert "id" in dict and "keyspace" in dict and "kind" in dict, "Homer cannot load an invalid reference"
     clasz = MetaModel.discover(dict["kind"])
     return MetaModel(clasz).read(dict["id"])
コード例 #2
0
 def validate(self, value):
     '''Makes sure you can only set a Model or a Key that is complete on a Reference'''
     if self.empty(value):
         return None   
     if isinstance(self.clasz, str):
         found = MetaModel.discover(self.clasz)
         if found: self.clasz = found     
         
     if not isinstance(value, (self.clasz, Model)):
         raise BadValueError("Value: {0} must be an instance of {1}".format(value, self.clasz))
         
     value.validate() #Finally validate the model then return it.
     return value