本文整理匯總了Python中google.appengine.ext.ndb.GeoPtProperty方法的典型用法代碼示例。如果您正苦於以下問題:Python ndb.GeoPtProperty方法的具體用法?Python ndb.GeoPtProperty怎麽用?Python ndb.GeoPtProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google.appengine.ext.ndb
的用法示例。
在下文中一共展示了ndb.GeoPtProperty方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: convert_GeoPtProperty
# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import GeoPtProperty [as 別名]
def convert_GeoPtProperty(self, model, prop, kwargs):
"""Returns a form field for a ``ndb.GeoPtProperty``."""
return GeoPtPropertyField(**kwargs)
示例2: _value_to_property
# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import GeoPtProperty [as 別名]
def _value_to_property(self, value, prop):
"""Converts raw data value into an appropriate NDB property"""
if isinstance(prop, ndb.KeyProperty):
if value is None:
return None
try:
return ndb.Key(urlsafe=value)
except ProtocolBufferDecodeError as e:
if prop._kind is not None:
model_class = ndb.Model._kind_map.get(prop._kind)
if getattr(model_class, 'RESTMeta', None) and getattr(model_class.RESTMeta, 'use_input_id', False):
return ndb.Key(model_class, value)
raise RESTException('invalid key: {}'.format(value) )
elif isinstance(prop, ndb.TimeProperty):
if dateutil is None:
try:
return datetime.strptime(value, "%H:%M:%S").time()
except ValueError as e:
raise RESTException("Invalid time. Must be in ISO 8601 format.")
else:
return dateutil.parser.parse(value).time()
elif isinstance(prop, ndb.DateProperty):
if dateutil is None:
try:
return datetime.strptime(value, "%Y-%m-%d").date()
except ValueError as e:
raise RESTException("Invalid date. Must be in ISO 8601 format.")
else:
return dateutil.parser.parse(value).date()
elif isinstance(prop, ndb.DateTimeProperty):
if dateutil is None:
try:
return datetime.strptime(value, "%Y-%m-%dT%H:%M:%S")
except ValueError as e:
raise RESTException("Invalid datetime. Must be in ISO 8601 format.")
else:
return dateutil.parser.parse(value)
elif isinstance(prop, ndb.GeoPtProperty):
# Convert from string (formatted as '52.37, 4.88') to GeoPt
return ndb.GeoPt(value)
elif isinstance(prop, ndb.StructuredProperty):
# It's a structured property - the input data is a dict - recursively parse it as well
return self._build_model_from_data(value, prop._modelclass)
else:
# Return as-is (no need for further manipulation)
return value