|
@@ -3,7 +3,8 @@
|
3
|
3
|
from leobject.leclass import LeClass
|
4
|
4
|
|
5
|
5
|
## @brief Represent an EmType data instance
|
6
|
|
-class LeType(LeClass):
|
|
6
|
+# @note Is not a derivated class of LeClass because the concrete class will be a derivated class from LeClass
|
|
7
|
+class LeType(object):
|
7
|
8
|
|
8
|
9
|
## @brief Stores selected fields with key = name
|
9
|
10
|
_fields = list()
|
|
@@ -11,20 +12,34 @@ class LeType(LeClass):
|
11
|
12
|
_leclass = None
|
12
|
13
|
|
13
|
14
|
## @brief Instanciate a new LeType
|
14
|
|
- # @param model Model : The editorial model
|
15
|
|
- # @param datasource ? : The datasource
|
16
|
|
- def __init__(self, **kwargs):
|
17
|
|
- if self._typename is None or self._leclass is None:
|
|
15
|
+ # @param lodel_id : The lodel id
|
|
16
|
+ # @param **kwargs : Datas used to populate a LeType
|
|
17
|
+ def __init__(self, lodel_id, **kwargs):
|
|
18
|
+ if self._leclass is None:
|
18
|
19
|
raise NotImplementedError("Abstract class")
|
19
|
|
- super(LeType, self).__init__(**kwargs)
|
|
20
|
+
|
|
21
|
+ self.lodel_id = lodel_id
|
|
22
|
+ ## Populate the object from the datas received in kwargs
|
|
23
|
+ for name, value in kwargs.items():
|
|
24
|
+ if name not in self._fields:
|
|
25
|
+ raise AttributeError("No such field '%s' for %s"%(name, self.__class__.__name__)
|
|
26
|
+ setattr(self, name, value)
|
20
|
27
|
|
21
|
28
|
## @brief Insert a new LeType in the datasource
|
22
|
|
- # @param datas dict : A dict containing the datas
|
|
29
|
+ # @param **datas : A dict containing the datas
|
23
|
30
|
# @return The lodel id of the new LeType or False
|
24
|
31
|
# @thorw A leo exception if invalid stuff
|
25
|
32
|
# @throw InvalidArgumentError if invalid argument
|
26
|
33
|
@classmethod
|
27
|
|
- def insert(cls, datas):
|
|
34
|
+ def insert(cls, **datas):
|
|
35
|
+ #check datas
|
|
36
|
+ autom_fields = ['lodel_id', 'typename', 'classname' ]
|
|
37
|
+ for forbiden in autom_fields:
|
|
38
|
+ if forbiden in datas:
|
|
39
|
+ raise AttributeError("Not allowed to give explicitly '%s' to insert method"%(forbiden))
|
|
40
|
+ self.check_datas(datas)
|
|
41
|
+
|
|
42
|
+ super(LeType, self).insert(typename=self.__class__.__name__, classname=self._leclass.__name__, **datas)
|
28
|
43
|
pass
|
29
|
44
|
|
30
|
45
|
## @brief Delete a LeType from the datasource
|
|
@@ -52,8 +67,8 @@ class LeType(LeClass):
|
52
|
67
|
@classmethod
|
53
|
68
|
def check_datas(cls, datas):
|
54
|
69
|
for dname, dval in datas.items():
|
55
|
|
- if dname not in cls._fields.keys():
|
56
|
|
- raise Exception()
|
|
70
|
+ if dname not in cls._fields:
|
|
71
|
+ raise AttributeError("No such field '%s' for %s"%(dname, self.__class__.__name__)
|
57
|
72
|
cls._fields[dname].check_or_raise(dval)
|
58
|
73
|
|
59
|
74
|
|