|
@@ -14,6 +14,8 @@ class LeType(object):
|
14
|
14
|
_superiors = list()
|
15
|
15
|
## @brief Stores the class of LeClass
|
16
|
16
|
_leclass = None
|
|
17
|
+ ## @brief Stores the EM uid
|
|
18
|
+ _type_id = None
|
17
|
19
|
|
18
|
20
|
## @brief Instanciate a new LeType
|
19
|
21
|
# @param lodel_id : The lodel id
|
|
@@ -23,11 +25,37 @@ class LeType(object):
|
23
|
25
|
raise NotImplementedError("Abstract class")
|
24
|
26
|
|
25
|
27
|
self.lodel_id = lodel_id
|
|
28
|
+
|
|
29
|
+ if 'type_id' in kwargs:
|
|
30
|
+ if self.__class__._type_id != int(kwargs['type_id']):
|
|
31
|
+ raise RuntimeError("Trying to instanciate a %s with an EM uid that is not correct"%self.__class__.__name__)
|
|
32
|
+
|
26
|
33
|
## Populate the object from the datas received in kwargs
|
27
|
34
|
for name, value in kwargs.items():
|
28
|
35
|
if name not in self._fields:
|
29
|
36
|
raise AttributeError("No such field '%s' for %s"%(name, self.__class__.__name__))
|
30
|
37
|
setattr(self, name, value)
|
|
38
|
+
|
|
39
|
+ ## @brief Populate the LeType wih datas from DB
|
|
40
|
+ # @param field_list None|list : List of fieldname to fetch. If None fetch all the missing datas
|
|
41
|
+ def populate(self, field_list=None):
|
|
42
|
+ if field_list == None:
|
|
43
|
+ field_list = [ fname for fname in self._fields if not hasattr(self, fname) ]
|
|
44
|
+
|
|
45
|
+ fdatas = self._datasource.get(self._leclass, self.__class__, 'lodel_id = %d'%self.lodel_id)
|
|
46
|
+ for fname, fdats in fdatas[0].items():
|
|
47
|
+ setattr(self, name, value)
|
|
48
|
+
|
|
49
|
+ ## @brief Get a fieldname:value dict
|
|
50
|
+ # @warning Giving True as full argument can represent a performances issue
|
|
51
|
+ # @param full bool : If true populate the object before returning the datas
|
|
52
|
+ # @return A dict with field name as key and the field value as value
|
|
53
|
+ @property
|
|
54
|
+ def datas(self, full=False):
|
|
55
|
+ if full:
|
|
56
|
+ self.populate()
|
|
57
|
+ return { fname: getattr(self, fname) for fname in self._fields if hasattr(self,fname) }
|
|
58
|
+
|
31
|
59
|
|
32
|
60
|
## @brief Delete the LeType from Db
|
33
|
61
|
# @note equivalent to LeType::delete(this.lodel_id)
|
|
@@ -63,6 +91,7 @@ class LeType(object):
|
63
|
91
|
# @throw InvalidArgumentError if invalid argument
|
64
|
92
|
@classmethod
|
65
|
93
|
def insert(self, **datas):
|
|
94
|
+ self.check_datas_or_raise(datas, complete=True)
|
66
|
95
|
super(LeType, self).insert(typename=self.__class__.__name__, classname=self._leclass.__name__, **datas)
|
67
|
96
|
pass
|
68
|
97
|
|