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


Python ndb.DateTimeProperty方法代码示例

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


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

示例1: from_serializable_dict

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import DateTimeProperty [as 别名]
def from_serializable_dict(cls, serializable_dict, **props):
    """Makes an entity with properties from |serializable_dict| and |props|.

    Properties from |serializable_dict| are converted from simple types to
    rich types first (e.g. int -> DateTimeProperty). See doc string for
    'convert_serializable_dict' method for more details.

    Properties from |props| are passed to entity constructor as is. Values in
    |props| override values from |serializable_dict|.

    Raises ValueError if types or structure of |serializable_dict| doesn't match
    entity schema.
    """
    try:
      all_props = cls.convert_serializable_dict(serializable_dict)
      all_props.update(props)
      return cls(**all_props)
    except datastore_errors.BadValueError as e:
      raise ValueError(e) 
开发者ID:luci,项目名称:luci-py,代码行数:21,代码来源:serializable.py

示例2: convert_DateTimeProperty

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

        return f.DateTimeField(format='%Y-%m-%d %H:%M:%S', **kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:8,代码来源:ndb.py

示例3: _get_for_dict

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import DateTimeProperty [as 别名]
def _get_for_dict(self, entity):
        value = super(DateTimeProperty, self)._get_for_dict(entity)
        if not value:
            return None
        return value.isoformat() 
开发者ID:duo-labs,项目名称:isthislegit,代码行数:7,代码来源:util.py

示例4: testDateTimeProperty_shouldConvertToString

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import DateTimeProperty [as 别名]
def testDateTimeProperty_shouldConvertToString(self):
        self.__assert_conversion(ndb.DateTimeProperty, DateTime) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:4,代码来源:test_converter.py

示例5: mock_now

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import DateTimeProperty [as 别名]
def mock_now(test, now, seconds):
  """Mocks utcnow() and ndb properties.

  In particular handles when auto_now and auto_now_add are used.
  """
  now = now + datetime.timedelta(seconds=seconds)
  test.mock(utils, 'utcnow', lambda: now)
  test.mock(ndb.DateTimeProperty, '_now', lambda _: now)
  test.mock(ndb.DateProperty, '_now', lambda _: now.date())
  return now 
开发者ID:luci,项目名称:luci-py,代码行数:12,代码来源:test_case.py

示例6: test_datetime_properties

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import DateTimeProperty [as 别名]
def test_datetime_properties(self):
    """Test handling of DateTimeProperty."""
    class Entity(ndb.Model, serializable.SerializableModelMixin):
      dt = ndb.DateTimeProperty()

    # Same point in time as datetime and as timestamp.
    dt = datetime.datetime(2012, 1, 2, 3, 4, 5)
    ts = 1325473445000000

    # Datetime is serialized to a number of milliseconds since epoch.
    self.assertEqual({'dt': ts}, Entity(dt=dt).to_serializable_dict())
    # Reverse operation also works.
    self.assertEqual({'dt': dt}, Entity.convert_serializable_dict({'dt': ts})) 
开发者ID:luci,项目名称:luci-py,代码行数:15,代码来源:serializable_test.py

示例7: test_repeated_properties

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import DateTimeProperty [as 别名]
def test_repeated_properties(self):
    """Test that properties with repeated=True are handled."""
    class IntsEntity(ndb.Model, serializable.SerializableModelMixin):
      ints = ndb.IntegerProperty(repeated=True)
    class DatesEntity(ndb.Model, serializable.SerializableModelMixin):
      dates = ndb.DateTimeProperty(repeated=True)

    # Same point in time as datetime and as timestamp.
    dt = datetime.datetime(2012, 1, 2, 3, 4, 5)
    ts = 1325473445000000

    # Repeated properties that are not set are converted to empty lists.
    self.assertEqual({'ints': []}, IntsEntity().to_serializable_dict())
    self.assertEqual({'dates': []}, DatesEntity().to_serializable_dict())

    # List of ints works (as an example of simple repeated property).
    self.assertEqual(
        {'ints': [1, 2]},
        IntsEntity(ints=[1, 2]).to_serializable_dict())
    self.assertEqual(
        {'ints': [1, 2]},
        IntsEntity.convert_serializable_dict({'ints': [1, 2]}))

    # List of datetimes works (as an example of not-so-simple property).
    self.assertEqual(
        {'dates': [ts, ts]},
        DatesEntity(dates=[dt, dt]).to_serializable_dict())
    self.assertEqual(
        {'dates': [dt, dt]},
        DatesEntity.convert_serializable_dict({'dates': [ts, ts]})) 
开发者ID:luci,项目名称:luci-py,代码行数:32,代码来源:serializable_test.py

示例8: test_bad_type_for_datetime_property

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import DateTimeProperty [as 别名]
def test_bad_type_for_datetime_property(self):
    """Trying to deserialize non-number into DateTimeProperty -> ValueError."""
    class Entity(ndb.Model, serializable.SerializableModelMixin):
      prop = ndb.DateTimeProperty()

    # Works.
    Entity.from_serializable_dict({'prop': 123})
    # Doesn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': 'abc'}) 
开发者ID:luci,项目名称:luci-py,代码行数:12,代码来源:serializable_test.py

示例9: __init__

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import DateTimeProperty [as 别名]
def __init__(self, property_converters, field_mode_predicate):
    """Args:
      property_converters: sequence of tuples that define how to handle various
        NDB property classes.
      field_mode_predicate: callable that will be used to decide what properties
        to use during conversion. It is called with single integer argument
        |mode| which is a value from entity.serializable_properties dictionary
        that correspond to property being considered. If |field_mode_predicate|
        returns True, then property will be used, otherwise it will be silently
        ignored during conversion (i.e. resulting dict will not have it even
        if it was present in incoming dict).

    Each property converter tuple has 3 components:
      * ndb.Property subclass this converter applies to.
      * Boolean: True to apply converter to all subclasses or False only to
        this specific class.
      * Actual converter: function(property instance, from type) -> to type.

    For instance when converting rich-typed dict to serializable dict, converter
    for DateTimeProperty will be defined as:
      (
        ndb.DateTimeProperty,
        False,
        lambda(ndb.DateTimeProperty instance, datetime) -> integer
      )
    """
    self.property_converters = property_converters
    self.field_mode_predicate = field_mode_predicate 
开发者ID:luci,项目名称:luci-py,代码行数:30,代码来源:serializable.py


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