|
@@ -13,11 +13,10 @@
|
13
|
13
|
import leobject
|
14
|
14
|
from leobject.leclass import LeClass
|
15
|
15
|
from leobject.leobject import LeObjectError
|
16
|
|
-from Lodel.utils.classinstancemethod import classinstancemethod
|
17
|
16
|
|
18
|
17
|
## @brief Represent an EmType data instance
|
19
|
18
|
# @note Is not a derivated class of LeClass because the concrete class will be a derivated class from LeClass
|
20
|
|
-class LeType(leobject.leobject._LeObject):
|
|
19
|
+class LeType(object):
|
21
|
20
|
|
22
|
21
|
## @brief Stores selected fields with key = name
|
23
|
22
|
_fields = list()
|
|
@@ -64,24 +63,20 @@ class LeType(leobject.leobject._LeObject):
|
64
|
63
|
## @brief Get a fieldname:value dict
|
65
|
64
|
# @return A dict with field name as key and the field value as value
|
66
|
65
|
@property
|
67
|
|
- def datas(self, full=False):
|
|
66
|
+ def datas(self):
|
68
|
67
|
return { fname: getattr(self, fname) for fname in self._fields if hasattr(self,fname) }
|
69
|
68
|
|
70
|
69
|
## @brief Get all the datas for this LeType
|
71
|
70
|
# @return a dict with fieldname as key and field value as value
|
72
|
71
|
# @warning Can represent a performance issue
|
73
|
|
- @property
|
74
|
72
|
def all_datas(self):
|
75
|
73
|
self.populate()
|
76
|
74
|
return self.datas
|
77
|
|
-
|
78
|
|
-
|
79
|
|
-
|
|
75
|
+
|
80
|
76
|
## @brief Delete the LeType from Db
|
81
|
77
|
# @note equivalent to LeType::delete(filters=['lodel_id = %s'%self.lodel_id)
|
82
|
|
- @classinstancemethod
|
83
|
|
- def delete(self):
|
84
|
|
- return self.__class__.delete([('lodel_id','=',self.lodel_id)])
|
|
78
|
+ def db_delete(self):
|
|
79
|
+ return self.delete([('lodel_id','=',repr(self.lodel_id))])
|
85
|
80
|
|
86
|
81
|
## @brief Delete a LeType from the datasource
|
87
|
82
|
# @param filters list : list of filters (see @ref leobject_filters)
|
|
@@ -89,27 +84,23 @@ class LeType(leobject.leobject._LeObject):
|
89
|
84
|
# @return True if deleted False if not existing
|
90
|
85
|
# @throw InvalidArgumentError if invalid parameters
|
91
|
86
|
# @throw Leo exception if the lodel_id identify an object from another type
|
92
|
|
- @delete.classmethod
|
|
87
|
+ @classmethod
|
93
|
88
|
def delete(cls, filters):
|
94
|
|
- return super(LeType, cls).delete(letype, leclass, filters)
|
|
89
|
+ return leobject.lefactory.LeFactory.leobject().delete(cls, filters)
|
95
|
90
|
|
96
|
|
-
|
97
|
|
- @classinstancemethod
|
98
|
91
|
## @brief Update a LeType in db
|
99
|
|
- def update(self):
|
100
|
|
- return self.__class__.update(filters=[('lodel_id', '=', self.lodel_id)], datas = self.datas)
|
|
92
|
+ def db_update(self):
|
|
93
|
+ return self.update(filters=[('lodel_id', '=', repr(self.lodel_id))], datas = self.datas)
|
101
|
94
|
|
102
|
|
-
|
103
|
|
- @update.classmethod
|
|
95
|
+ @classmethod
|
104
|
96
|
## @brief Update some LeType in db
|
105
|
97
|
# @param datas : keys are lodel_id and value are dict of fieldname => value
|
106
|
98
|
# @param filters list : list of filters (see @ref leobject_filters)
|
107
|
99
|
# @param cls
|
108
|
100
|
# return bool
|
109
|
101
|
def update(cls, filters, datas):
|
110
|
|
- return super(LeType, cls).update(letype = cls, leclass = cls._leclass, filters = filters, datas = datas)
|
|
102
|
+ return leobject.lefactory.LeFactory.leobject().update(letype = cls, filters = filters, datas = datas)
|
111
|
103
|
|
112
|
|
-
|
113
|
104
|
## @brief Insert a new LeType in the datasource
|
114
|
105
|
# @param **datas list : A list of dict containing the datas
|
115
|
106
|
# @return The lodel id of the new LeType or False
|
|
@@ -122,14 +113,15 @@ class LeType(leobject.leobject._LeObject):
|
122
|
113
|
## @brief Check that datas are valid for this type
|
123
|
114
|
# @param datas dict : key == field name value are field values
|
124
|
115
|
# @param complete bool : if True expect that datas provide values for all non internal fields
|
|
116
|
+ # @param allow_internal bool : if True don't raise an error if a field is internal
|
125
|
117
|
# @throw TypeError If the datas are not valids
|
126
|
118
|
# @throw AttributeError if datas provides values for automatic fields
|
127
|
119
|
# @throw AttributeError if datas provides values for fields that doesn't exists
|
128
|
120
|
@classmethod
|
129
|
|
- def check_datas_or_raise(cls, datas, complete = False):
|
|
121
|
+ def check_datas_or_raise(cls, datas, complete = False, allow_internal = True):
|
130
|
122
|
autom_fields = [f for f, ft in cls._fieldtypes.items() if hasattr(ft,'internal') and ft.internal]
|
131
|
123
|
for dname, dval in datas.items():
|
132
|
|
- if dname in autom_fields:
|
|
124
|
+ if not allow_internal and dname in autom_fields:
|
133
|
125
|
raise AttributeError("The field '%s' is internal"%(dname))
|
134
|
126
|
if dname not in cls._fields:
|
135
|
127
|
raise AttributeError("No such field '%s' for %s"%(dname, self.__class__.__name__))
|
|
@@ -138,6 +130,7 @@ class LeType(leobject.leobject._LeObject):
|
138
|
130
|
fields = [f for f, ft in cls._fieldtypes.items() if not hasattr(ft,'internal') or not ft.internal]
|
139
|
131
|
if complete and len(datas) < len(fields):
|
140
|
132
|
raise LeObjectError("The argument complete was True but some fields are missing : %s"%(set(fields) - set(datas.keys())))
|
|
133
|
+
|
141
|
134
|
|
142
|
135
|
## @brief Check that datas are valid for this type
|
143
|
136
|
# @param datas dict : key == field name value are field values
|
|
@@ -160,24 +153,3 @@ class LeType(leobject.leobject._LeObject):
|
160
|
153
|
self._fieldtypes[name].check_or_raise(value)
|
161
|
154
|
return super(LeType, self).__setattr__(name, value)
|
162
|
155
|
|
163
|
|
- ## @brief Fetch superiors
|
164
|
|
- # @param nature str : The relation nature
|
165
|
|
- # @return if no nature given return a dict with nature as key and arrays of LeObject as value. Else return an array of LeObject
|
166
|
|
- def superiors(self, nature = None):
|
167
|
|
- pass
|
168
|
|
-
|
169
|
|
- ## @brief Fetch subordinates
|
170
|
|
- # @param nature str : The relation nature
|
171
|
|
- # @return if no nature given return a dict with nature as key and arrays of LeObject as value. Else return an array of LeObject
|
172
|
|
- def subordinates(self, nature = None):
|
173
|
|
- pass
|
174
|
|
-
|
175
|
|
- ## @brief Add a superior
|
176
|
|
- # @param nature str : The raltion nature
|
177
|
|
- # @param leo LeObject : The superior
|
178
|
|
- # @return True if done False if already done
|
179
|
|
- # @throw A Leo exception if trying to link with an invalid leo
|
180
|
|
- # @throw InvalidArgumentError if invalid argument
|
181
|
|
- def set_superior(self, nature, leo):
|
182
|
|
- pass
|
183
|
|
-
|