Python google.appengine.ext.db 模块,ReferenceProperty() 实例源码

我们从Python开源项目中,提取了以下29个代码示例,用于说明如何使用google.appengine.ext.db.ReferenceProperty()

项目:Tinychat-Bot--Discontinued    作者:Tinychat    | 项目源码 | 文件源码
def getCustomProperties(self):
        self.reference_properties = {}
        self.properties = {}
        reverse_props = []

        for name, prop in self.klass.properties().iteritems():
            self.properties[name] = prop

            if isinstance(prop, db.ReferenceProperty):
                self.reference_properties[name] = prop

        if issubclass(self.klass, polymodel.PolyModel):
            del self.properties['_class']

        # check if the property is a defined as a collection_name. These types
        # of properties are read-only and the datastore freaks out if you
        # attempt to meddle with it. We delete the attribute entirely ..
        for name, value in self.klass.__dict__.iteritems():
            if isinstance(value, db._ReverseReferenceProperty):
                reverse_props.append(name)

        self.encodable_properties.update(self.properties.keys())
        self.decodable_properties.update(self.properties.keys())
        self.readonly_attrs.update(reverse_props)

        if not self.reference_properties:
            self.reference_properties = None

        if not self.properties:
            self.properties = None
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:FileStoreGAE    作者:liantian-cn    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:beg-django-e-commerce    作者:Apress    | 项目源码 | 文件源码
def __set__(self, instance, value):
        if value and not isinstance(value, db.Model):
            raise ValueError('You must supply a Model instance.')
        if not value:
            key = None
        elif self.use_key_name:
            key = value.key().name()
        else:
            key = str(value.key())
        setattr(instance, '_ref_cache_for_' + self.target_name, value)
        setattr(instance, self.target_name, key)

        for destination, source in self.integrate.items():
            integrate_value = None
            if value:
                try:
                    property = getattr(value.__class__, source)
                except:
                    property = None
                if property and isinstance(property, db.ReferenceProperty):
                    integrate_value = property.get_value_for_datastore(value)
                else:
                    integrate_value = getattr_by_path(value, source)
            setattr(instance, destination, integrate_value)

# Don't use this, yet. It's not part of the official API!
项目:beg-django-e-commerce    作者:Apress    | 项目源码 | 文件源码
def __init__(self, reference_class, integrate={}, **kwargs):
        self.integrate = integrate
        super(ReferenceProperty, self).__init__(reference_class, **kwargs)
项目:beg-django-e-commerce    作者:Apress    | 项目源码 | 文件源码
def is_resolved(cls, property, instance):
        try:
            if not hasattr(instance, property.__id_attr_name()) or \
                    not getattr(instance, property.__id_attr_name()):
                return True
            return bool(getattr(instance, property.__resolved_attr_name()))
        except:
            import logging
            logging.exception('ReferenceProperty implementation changed! '
                              'Update ragendja.dbutils.ReferenceProperty.'
                              'is_resolved! Exception was:')
        return False
项目:beg-django-e-commerce    作者:Apress    | 项目源码 | 文件源码
def __set__(self, instance, value):
        super(ReferenceProperty, self).__set__(instance, value)

        for destination, source in self.integrate.items():
            integrate_value = None
            if value:
                try:
                    property = getattr(value.__class__, source)
                except:
                    property = None
                if property and isinstance(property, db.ReferenceProperty):
                    integrate_value = property.get_value_for_datastore(value)
                else:
                    integrate_value = getattr_by_path(value, source)
            setattr(instance, destination, integrate_value)
项目:python-group-proj    作者:Sharcee    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:start    作者:argeweb    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:Sudoku-Solver    作者:ayush1997    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:gardenbot    作者:GoestaO    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:flask-zhenai-mongo-echarts    作者:Fretice    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def get_form_field(self, **kwargs):
    """Return a Django form field appropriate for a reference property.

    This defaults to a ModelChoiceField instance.
    """
    defaults = {'form_class': ModelChoiceField,
                'reference_class': self.reference_class}
    defaults.update(kwargs)
    return super(ReferenceProperty, self).get_form_field(**defaults)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def get_value_for_form(self, instance):
    """Extract the property value from the instance for use in a form.

    This return the key object for the referenced object, or None.
    """
    value = super(ReferenceProperty, self).get_value_for_form(instance)
    if value is not None:
      value = value.key()
    return value
项目:micro-blog    作者:nickChenyx    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:python-flask-security    作者:weinbergdavid    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:Lixiang_zhaoxin    作者:hejaxian    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:flask    作者:bobohope    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:Hawkeye    作者:tozhengxq    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:ngx_status    作者:YoYoAdorkable    | 项目源码 | 文件源码
def convert_ReferenceProperty(model, prop, kwargs):
    """Returns a form field for a ``db.ReferenceProperty``."""
    kwargs['reference_class'] = prop.reference_class
    kwargs.setdefault('allow_blank', not prop.required)
    return ReferencePropertyField(**kwargs)
项目:beg-django-e-commerce    作者:Apress    | 项目源码 | 文件源码
def __init__(self, property, model, use_key_name=True, integrate={}):
        if isinstance(property, basestring):
            self.target_name = property
        else:
            # Monkey-patch the target property, so we can monkey-patch the
            # model class, so we can detect when the user wants to set our
            # KeyReferenceProperty via the model constructor.
            # What an ugly hack; but this is the simplest implementation. :(
            # One alternative would be to implement a proxy model that
            # provides direct access to the key, but this won't work with
            # isinstance(). Maybe that's an option for Python 3000.
            # Yet another alternative would be to force the user to choose
            # either .key_name or .reference manually. That's rather ugly, too.
            self.target_name = None
            myself = self
            old_config = property.__property_config__
            def __property_config__(model_class, property_name):
                myself.target_name = property_name
                my_name = None
                for key, value in model_class.__dict__.items():
                    if value is myself:
                        my_name = key
                        break
                old_init = model_class.__init__
                def __init__(self, *args, **kwargs):
                    if my_name in kwargs:
                        setattr(self, my_name, kwargs[my_name])
                        kwargs[property_name] = getattr(self, property_name)
                        for destination, source in myself.integrate.items():
                            integrate_value = None
                            if kwargs[my_name]:
                                try:
                                    property = getattr(self.__class__, source)
                                except:
                                    property = None
                                if property and isinstance(property, db.ReferenceProperty):
                                    integrate_value = property.get_value_for_datastore(self)
                                else:
                                    integrate_value = getattr_by_path(
                                        kwargs[my_name], source)
                            kwargs[destination] = integrate_value
                    old_init(self, *args, **kwargs)
                model_class.__init__ = __init__
                old_config(model_class, property_name)
            property.__property_config__ = __property_config__
        self.target_model = model
        self.use_key_name = use_key_name
        self.integrate = integrate