本文整理汇总了Python中schematics.types.DateTimeType方法的典型用法代码示例。如果您正苦于以下问题:Python types.DateTimeType方法的具体用法?Python types.DateTimeType怎么用?Python types.DateTimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类schematics.types
的用法示例。
在下文中一共展示了types.DateTimeType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _value_to_dynamodb
# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import DateTimeType [as 别名]
def _value_to_dynamodb(cls, key, value):
"""
Convert python/schematics values to DynamoDB values.
:param key: field name (string)
:param value: field value
:return: dynamodb-friendly value
"""
if isinstance(getattr(cls, key), (fields.DateTimeType,
fields.DateType)):
if not value:
return 0
value = getattr(cls, key).to_native(value)
return decimal.Decimal(int(calendar.timegm(value.timetuple())))
if isinstance(getattr(cls, key), fields.UUIDType) and value:
return getattr(cls, key).to_primitive(value)
if isinstance(getattr(cls, key), fields.BooleanType):
return decimal.Decimal('1') if value else decimal.Decimal('0')
if value == '': # Empty AttributeValue is an error in DynamoDB
return None
return value
示例2: _dynamodb_to_model
# 需要导入模块: from schematics import types [as 别名]
# 或者: from schematics.types import DateTimeType [as 别名]
def _dynamodb_to_model(self, row):
dict_row = dict(row)
for field_name, dynamodb_value in row.items():
if field_name in self._fields:
if isinstance(self._fields[field_name],
(fields.DateTimeType,
fields.DateType)):
if dynamodb_value:
dict_row[field_name] = datetime.datetime.utcfromtimestamp(
float(dynamodb_value)
) # TODO: test for this
else:
dict_row[field_name] = None
if isinstance(self._fields[field_name],
fields.BooleanType):
# tests/test_gis_report_provider.py covers this
dict_row[field_name] = bool(
dynamodb_value
) # DynamoDB loads boolean as e.g. Decimal('1')
return dict_row