本文整理汇总了Python中oslo_versionedobjects.fields.DateTimeField方法的典型用法代码示例。如果您正苦于以下问题:Python fields.DateTimeField方法的具体用法?Python fields.DateTimeField怎么用?Python fields.DateTimeField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_versionedobjects.fields
的用法示例。
在下文中一共展示了fields.DateTimeField方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_base_attributes
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import DateTimeField [as 别名]
def test_base_attributes(self):
dt = datetime.datetime(1955, 11, 5)
datatime = fields.DateTimeField()
obj = MyObj(self.context)
obj.created_at = dt
obj.updated_at = dt
expected = {'zun_object.name': 'MyObj',
'zun_object.namespace': 'zun',
'zun_object.version': '1.0',
'zun_object.changes':
['created_at', 'updated_at'],
'zun_object.data':
{'created_at': datatime.stringify(dt),
'updated_at': datatime.stringify(dt)}
}
actual = obj.obj_to_primitive()
# zun_object.changes is built from a set and order is undefined
self.assertEqual(sorted(expected['zun_object.changes']),
sorted(actual['zun_object.changes']))
del expected['zun_object.changes'],\
actual['zun_object.changes']
self.assertEqual(expected, actual)
示例2: test_base_attributes
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import DateTimeField [as 别名]
def test_base_attributes(self):
dt = datetime.datetime(1955, 11, 5)
datatime = fields.DateTimeField()
obj = MyObj(self.context)
obj.created_at = dt
obj.updated_at = dt
expected = {'magnum_object.name': 'MyObj',
'magnum_object.namespace': 'magnum',
'magnum_object.version': '1.0',
'magnum_object.changes':
['created_at', 'updated_at'],
'magnum_object.data':
{'created_at': datatime.stringify(dt),
'updated_at': datatime.stringify(dt)}
}
actual = obj.obj_to_primitive()
# magnum_object.changes is built from a set and order is undefined
self.assertEqual(sorted(expected['magnum_object.changes']),
sorted(actual['magnum_object.changes']))
del expected['magnum_object.changes'], actual['magnum_object.changes']
self.assertEqual(expected, actual)
示例3: setUp
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import DateTimeField [as 别名]
def setUp(self):
super(TestDateTime, self).setUp()
self.dt = datetime.datetime(1955, 11, 5, tzinfo=iso8601.iso8601.UTC)
self.field = fields.DateTimeField()
self.coerce_good_values = [(self.dt, self.dt),
(_utils.isotime(self.dt), self.dt)]
self.coerce_bad_values = [1, 'foo']
self.to_primitive_values = [(self.dt, _utils.isotime(self.dt))]
self.from_primitive_values = [(_utils.isotime(self.dt), self.dt)]
示例4: test_field_checking
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import DateTimeField [as 别名]
def test_field_checking(self):
def create_class(field):
@base.VersionedObjectRegistry.register
class TestField(base.VersionedObject):
VERSION = '1.5'
fields = {'foo': field()}
return TestField
create_class(fields.DateTimeField)
self.assertRaises(exception.ObjectFieldInvalid,
create_class, fields.DateTime)
self.assertRaises(exception.ObjectFieldInvalid,
create_class, int)
示例5: _from_db_object
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import DateTimeField [as 别名]
def _from_db_object(context, operation_log, db_operation_log):
for name, field in operation_log.fields.items():
value = db_operation_log.get(name)
if isinstance(field, fields.IntegerField):
value = value or 0
elif isinstance(field, fields.DateTimeField):
value = value or None
operation_log[name] = value
operation_log._context = context
operation_log.obj_reset_changes()
return operation_log
示例6: _from_db_object
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import DateTimeField [as 别名]
def _from_db_object(cls, context, verification, db_verification):
for name, field in verification.fields.items():
value = db_verification.get(name)
if isinstance(field, fields.IntegerField):
value = value or 0
elif isinstance(field, fields.DateTimeField):
value = value or None
if name in cls.json_fields:
value = jsonutils.loads(value) if value else {}
verification[name] = value
verification._context = context
verification.obj_reset_changes()
return verification
示例7: DateTimeField
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import DateTimeField [as 别名]
def DateTimeField(**kwargs):
return fields.DateTimeField(tzinfo_aware=False, **kwargs)
示例8: _from_db_object
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import DateTimeField [as 别名]
def _from_db_object(cls, context, restore, db_restore):
for name, field in restore.fields.items():
value = db_restore.get(name)
if isinstance(field, fields.IntegerField):
value = value or 0
elif isinstance(field, fields.DateTimeField):
value = value or None
if name in cls.json_fields:
value = jsonutils.loads(value) if value else {}
restore[name] = value
restore._context = context
restore.obj_reset_changes()
return restore
示例9: _from_db_object
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import DateTimeField [as 别名]
def _from_db_object(context, service, db_service):
for name, field in service.fields.items():
value = db_service.get(name)
if isinstance(field, fields.IntegerField):
value = value or 0
elif isinstance(field, fields.DateTimeField):
value = value or None
service[name] = value
service._context = context
service.obj_reset_changes()
return service
示例10: _render_object
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import DateTimeField [as 别名]
def _render_object(cls, object, *args, **kwargs):
# We need to findout the type of field sometimes - these are helper
# methods for that.
def _is_datetime_field(object, key):
field = object.FIELDS.get(key, {})
if isinstance(field, fields.Field):
# TODO(daidv): If we change to use DateTimeField or STL
# we should change this to exact object
return isinstance(field, fields.DateTimeField)
else:
return field.get('schema', {}).get('format', '') == 'date-time'
def _format_datetime_field(obj):
return datetime.datetime.strftime(
obj, utils.DATETIME_FORMAT)
# The dict we will return to be rendered to JSON / output format
r_obj = {}
# Loop over all fields that are supposed to be output
for key, value in cls.MODIFICATIONS['fields'].items():
# Get properties for this field
field_props = cls.MODIFICATIONS['fields'][key]
# Check if it has to be renamed
if field_props.get('rename', False):
obj = getattr(object, field_props.get('rename'))
# if rename is specified we need to change the key
obj_key = field_props.get('rename')
else:
# if not, move on
obj = getattr(object, key, None)
obj_key = key
# Check if this item is a relation (another DesignateObject that
# will need to be converted itself
field = object.FIELDS.get(obj_key, {})
if isinstance(field, dict) and field.get('relation'):
# Get a adapter for the nested object
# Get the class the object is and get its adapter, then set
# the item in the dict to the output
r_obj[key] = cls.get_object_adapter(
cls.ADAPTER_FORMAT,
object.FIELDS[obj_key].get('relation_cls')).render(
cls.ADAPTER_FORMAT, obj, *args, **kwargs)
elif hasattr(field, 'objname'):
# Add by daidv: Check if field is OVO field and have a relation
r_obj[key] = cls.get_object_adapter(
cls.ADAPTER_FORMAT,
field.objname).render(
cls.ADAPTER_FORMAT, obj, *args, **kwargs)
elif _is_datetime_field(object, obj_key) and obj is not None:
# So, we now have a datetime object to render correctly
# see bug #1579844
r_obj[key] = _format_datetime_field(obj)
else:
# Just attach the damn item if there is no weird edge cases
r_obj[key] = obj
# Send it back
return r_obj