當前位置: 首頁>>代碼示例>>Python>>正文


Python ndb.TimeProperty方法代碼示例

本文整理匯總了Python中google.appengine.ext.ndb.TimeProperty方法的典型用法代碼示例。如果您正苦於以下問題:Python ndb.TimeProperty方法的具體用法?Python ndb.TimeProperty怎麽用?Python ndb.TimeProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.appengine.ext.ndb的用法示例。


在下文中一共展示了ndb.TimeProperty方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: convert_TimeProperty

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import TimeProperty [as 別名]
def convert_TimeProperty(self, model, prop, kwargs):
        """Returns a form field for a ``ndb.TimeProperty``."""
        if prop._auto_now or prop._auto_now_add:
            return None

        return f.DateTimeField(format='%H:%M:%S', **kwargs) 
開發者ID:jpush,項目名稱:jbox,代碼行數:8,代碼來源:ndb.py

示例2: testTimeProperty_shouldConvertToString

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import TimeProperty [as 別名]
def testTimeProperty_shouldConvertToString(self):
        self.__assert_conversion(ndb.TimeProperty, Time) 
開發者ID:graphql-python,項目名稱:graphene-gae,代碼行數:4,代碼來源:test_converter.py

示例3: _value_to_property

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import TimeProperty [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 
開發者ID:budowski,項目名稱:rest_gae,代碼行數:48,代碼來源:rest_gae.py


注:本文中的google.appengine.ext.ndb.TimeProperty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。