我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用google.appengine.ext.ndb.ComputedProperty()。
def getCustomProperties(self): props = {} # list of property names that are considered read only read_only_props = [] repeated_props = {} non_repeated_props = {} # list of property names that are computed computed_props = {} for name, prop in self.klass._properties.iteritems(): props[name] = prop if prop._repeated: repeated_props[name] = prop else: non_repeated_props[name] = prop if isinstance(prop, ndb.ComputedProperty): computed_props[name] = prop if issubclass(self.klass, polymodel.PolyModel): del props['class'] # check if the property is a defined as a computed property. These # types of properties are read-only for name, value in self.klass.__dict__.iteritems(): if isinstance(value, ndb.ComputedProperty): read_only_props.append(name) self.encodable_properties.update(props.keys()) self.decodable_properties.update(props.keys()) self.readonly_attrs.update(read_only_props) if computed_props: self.decodable_properties.difference_update(computed_props.keys()) self.model_properties = props or None self.repeated_properties = repeated_props or None self.non_repeated_properties = non_repeated_props or None self.computed_properties = computed_props or None
def convert_ComputedProperty(self, model, prop, kwargs): """Returns a form field for a ``ndb.ComputedProperty``.""" return None
def convert__ClassKeyProperty(self, model, prop, kwargs): """Returns a form field for a ``ndb.ComputedProperty``.""" return None
def clone_entity(e, **extra_args): from google.appengine.ext import ndb klass = e.__class__ props = dict((v._code_name, v.__get__(e, klass)) for v in klass._properties.itervalues() if type(v) is not ndb.ComputedProperty) props.update(extra_args) return klass(**props)
def update_model(old_model, new_model): """Updates a model. For all fields that are set in new_model, copy them into old_model. Args: old_model: The ndb model object retrieved from the datastore. new_model_dict: A json object containing the new values. """ for k, v in new_model.to_dict().iteritems(): if type(getattr(type(new_model), k)) != ndb.ComputedProperty and v is not None: setattr(old_model, k, v)