本文整理匯總了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)
示例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)
示例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)