当前位置: 首页>>代码示例>>Python>>正文


Python ndb.BlobKeyProperty方法代码示例

本文整理汇总了Python中google.appengine.ext.ndb.BlobKeyProperty方法的典型用法代码示例。如果您正苦于以下问题:Python ndb.BlobKeyProperty方法的具体用法?Python ndb.BlobKeyProperty怎么用?Python ndb.BlobKeyProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.appengine.ext.ndb的用法示例。


在下文中一共展示了ndb.BlobKeyProperty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: convert_BlobKeyProperty

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import BlobKeyProperty [as 别名]
def convert_BlobKeyProperty(self, model, prop, kwargs):
        """Returns a form field for a ``ndb.BlobKeyProperty``."""
        return f.FileField(**kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:5,代码来源:ndb.py

示例2: default

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import BlobKeyProperty [as 别名]
def default(self, obj):
        if isinstance(obj, ndb.Model):
            obj_dict = obj.to_dict()

            # Each BlobKeyProperty is represented as a dict of upload_url/download_url
            for (name, prop) in obj._properties.iteritems():
                if isinstance(prop, ndb.BlobKeyProperty):
                    server_host = app_identity.get_default_version_hostname()
                    blob_property_url = 'http://%s%s/%s/%s' % (server_host, obj.RESTMeta.base_url, self._decode_key(obj.key), name) # e.g. /api/my_model/<SOME_KEY>/blob_prop
                    obj_dict[name] = {
                            'upload_url': blob_property_url,
                            'download_url': blob_property_url if getattr(obj, name) else None # Display as null if the blob property is not set
                            }



            # Filter the properties that will be returned to user
            included_properties = get_included_properties(obj, 'output')
            obj_dict = dict((k,v) for k,v in obj_dict.iteritems() if k in included_properties)
            # Translate the property names
            obj_dict = translate_property_names(obj_dict, obj, 'output')
            obj_dict['id'] = self._decode_key(obj.key)

            return obj_dict

        elif isinstance(obj, datetime) or isinstance(obj, date) or isinstance(obj, time):
            return obj.isoformat()

        elif isinstance(obj, ndb.Key):
            return self._decode_key(obj)

        elif isinstance(obj, ndb.GeoPt):
            return str(obj)

        else:
            return json.JSONEncoder.default(self, obj) 
开发者ID:budowski,项目名称:rest_gae,代码行数:38,代码来源:rest_gae.py

示例3: __init__

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import BlobKeyProperty [as 别名]
def __init__(self, url, model, **kwd):

        url = url.rstrip(' /')
        model = import_class(model)

        if not url.startswith('/'):
            raise ValueError('RESHandler url should start with "/": %s' % url)

        routes = [
                # Make sure we catch both URLs: to '/mymodel' and to '/mymodel/123'
                webapp2.Route(url + '<model_id:(/.+)?|/>', get_rest_class(model, url, **kwd), 'main')
            ]


        included_properties = get_included_properties(model, 'input')
        translation_table = get_translation_table(model, 'input')

        # Build extra routes for each BlobKeyProperty
        for (name, prop) in model._properties.iteritems():
            if isinstance(prop, ndb.BlobKeyProperty) and name in included_properties:
                # Register a route for the current BlobKeyProperty

                property_name = translation_table.get(name, name)
                blob_property_url = '%s/<model_id:.+?>/<property_name:%s>' % (url, property_name) # e.g. /api/my_model/<SOME_KEY>/blob_prop

                # Upload/Download blob route and handler
                routes.insert(0, webapp2.Route(blob_property_url, get_rest_class(model, url, **kwd), 'upload-download-blob'))



        super(RESTHandler, self).__init__('rest-handler-', routes) 
开发者ID:budowski,项目名称:rest_gae,代码行数:33,代码来源:rest_gae.py


注:本文中的google.appengine.ext.ndb.BlobKeyProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。