Add get detail of a resource to API; remove the dependency of the domain in the view...
[pti/o2.git] / o2common / domain / base.py
1 # Copyright (C) 2021 Wind River Systems, Inc.\r
2 #\r
3 #  Licensed under the Apache License, Version 2.0 (the "License");\r
4 #  you may not use this file except in compliance with the License.\r
5 #  You may obtain a copy of the License at\r
6 #\r
7 #      http://www.apache.org/licenses/LICENSE-2.0\r
8 #\r
9 #  Unless required by applicable law or agreed to in writing, software\r
10 #  distributed under the License is distributed on an "AS IS" BASIS,\r
11 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 #  See the License for the specific language governing permissions and\r
13 #  limitations under the License.\r
14 \r
15 from datetime import datetime\r
16 from typing import List\r
17 from sqlalchemy.inspection import inspect\r
18 from .events import Event\r
19 \r
20 \r
21 class AgRoot:\r
22 \r
23     def __init__(self) -> None:\r
24         self.hash = ""\r
25         self.updatetime = datetime.now()\r
26         self.createtime = datetime.now()\r
27         self.events = []  # type: List[Event]\r
28         # self.id = ""\r
29 \r
30 \r
31 class Serializer(object):\r
32 \r
33     def serialize(self):\r
34         # d = {c: getattr(self, c) for c in inspect(self).attrs.keys()}\r
35         # if 'createtime' in d:\r
36         #     d['createtime'] = d['createtime'].isoformat()\r
37         # if 'updatetime' in d:\r
38         #     d['updatetime'] = d['updatetime'].isoformat()\r
39         # return d\r
40         return {c: getattr(self, c) for c in inspect(self).attrs.keys()}\r
41 \r
42     @staticmethod\r
43     def serialize_list(li):\r
44         return [m.serialize() for m in li]\r