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


Python fields.DateTimeField方法代碼示例

本文整理匯總了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) 
開發者ID:openstack,項目名稱:zun,代碼行數:24,代碼來源:test_objects.py

示例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) 
開發者ID:openstack,項目名稱:magnum,代碼行數:23,代碼來源:test_objects.py

示例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)] 
開發者ID:openstack,項目名稱:oslo.versionedobjects,代碼行數:11,代碼來源:test_fields.py

示例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) 
開發者ID:openstack,項目名稱:oslo.versionedobjects,代碼行數:15,代碼來源:test_objects.py

示例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 
開發者ID:openstack,項目名稱:karbor,代碼行數:14,代碼來源:operation_log.py

示例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 
開發者ID:openstack,項目名稱:karbor,代碼行數:16,代碼來源:verification.py

示例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) 
開發者ID:openstack,項目名稱:karbor,代碼行數:4,代碼來源:base.py

示例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 
開發者ID:openstack,項目名稱:karbor,代碼行數:16,代碼來源:restore.py

示例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 
開發者ID:openstack,項目名稱:karbor,代碼行數:14,代碼來源:service.py

示例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 
開發者ID:openstack,項目名稱:designate,代碼行數:61,代碼來源:base.py


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