From f5d3ed4b8be018ca6d01088b3e28117ba254493b Mon Sep 17 00:00:00 2001 From: pycook Date: Thu, 24 Oct 2019 14:48:58 +0800 Subject: [PATCH] fix date picker --- api/lib/cmdb/const.py | 4 ++-- api/lib/database.py | 5 +++-- ui/src/views/cmdb/ci/modules/CreateInstanceForm.vue | 5 +++++ ui/src/views/cmdb/ci_type/attributesTable.vue | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/api/lib/cmdb/const.py b/api/lib/cmdb/const.py index e5bfb55..f8bcbc3 100644 --- a/api/lib/cmdb/const.py +++ b/api/lib/cmdb/const.py @@ -47,8 +47,8 @@ type_map = { Attribute.FLOAT: float, Attribute.TEXT: str, Attribute.TIME: str, - Attribute.DATE: lambda x: x.strftime("%Y%m%d"), - Attribute.DATETIME: lambda x: x.strftime("%Y%m%d %H:%M:%S"), + Attribute.DATE: lambda x: x.strftime("%Y-%m-%d"), + Attribute.DATETIME: lambda x: x.strftime("%Y-%m-%d %H:%M:%S"), }, 'serialize2': { Attribute.INT: int, diff --git a/api/lib/database.py b/api/lib/database.py index 2ac9867..82c6c62 100644 --- a/api/lib/database.py +++ b/api/lib/database.py @@ -10,7 +10,9 @@ from api.lib.exception import CommitException class FormatMixin(object): def to_dict(self): - return dict([(k.name, getattr(self, k.name)) for k in getattr(self, "__table__").columns]) + return dict([(k.name, + getattr(self, k.name) if not isinstance(getattr(self, k.name), datetime.datetime) else getattr( + self, k.name).strftime('%Y-%m-%d %H:%M:%S')) for k in getattr(self, "__table__").columns]) @classmethod def get_columns(cls): @@ -18,7 +20,6 @@ class FormatMixin(object): class CRUDMixin(FormatMixin): - @classmethod def create(cls, flush=False, **kwargs): return cls(**kwargs).save(flush=flush) diff --git a/ui/src/views/cmdb/ci/modules/CreateInstanceForm.vue b/ui/src/views/cmdb/ci/modules/CreateInstanceForm.vue index 0cb120e..9976526 100644 --- a/ui/src/views/cmdb/ci/modules/CreateInstanceForm.vue +++ b/ui/src/views/cmdb/ci/modules/CreateInstanceForm.vue @@ -128,6 +128,11 @@ export default { createInstance (e) { e.preventDefault() this.form.validateFields((err, values) => { + Object.keys(values).forEach(k => { + if (typeof values[k] === 'object') { + values[k] = values[k].format("YYYY-MM-DD HH:mm:ss") + } + }) if (!err) { if (this.action === 'update') { this.$emit('submit', values) diff --git a/ui/src/views/cmdb/ci_type/attributesTable.vue b/ui/src/views/cmdb/ci_type/attributesTable.vue index eb58508..f0c4e5c 100644 --- a/ui/src/views/cmdb/ci_type/attributesTable.vue +++ b/ui/src/views/cmdb/ci_type/attributesTable.vue @@ -393,7 +393,7 @@ export default { }, getAttributes () { - searchAttributes().then(res => { + searchAttributes({ page_size: 10000 }).then(res => { this.allAttributes = res.attributes }) },