|
@@ -0,0 +1,99 @@
|
|
1
|
+#-*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+from leobject.leclass import LeClass
|
|
4
|
+
|
|
5
|
+## @brief Represent an EmType data instance
|
|
6
|
+class LeType(LeClass):
|
|
7
|
+
|
|
8
|
+ ## @brief Stores selected fields with key = name
|
|
9
|
+ _fields = list()
|
|
10
|
+ ## @brief Stores the class of LeClass
|
|
11
|
+ _leclass = None
|
|
12
|
+
|
|
13
|
+ ## @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:
|
|
18
|
+ raise NotImplementedError("Abstract class")
|
|
19
|
+ super(LeType, self).__init__(**kwargs)
|
|
20
|
+
|
|
21
|
+ ## @brief Insert a new LeType in the datasource
|
|
22
|
+ # @param datas dict : A dict containing the datas
|
|
23
|
+ # @return The lodel id of the new LeType or False
|
|
24
|
+ # @thorw A leo exception if invalid stuff
|
|
25
|
+ # @throw InvalidArgumentError if invalid argument
|
|
26
|
+ @classmethod
|
|
27
|
+ def insert(cls, datas):
|
|
28
|
+ pass
|
|
29
|
+
|
|
30
|
+ ## @brief Delete a LeType from the datasource
|
|
31
|
+ # @param lodel_id int : The lodel_id identifying the LeType
|
|
32
|
+ # @param return True if deleted False if not existing
|
|
33
|
+ # @throw InvalidArgumentError if invalid parameters
|
|
34
|
+ # @throw Leo exception if the lodel_id identify an object from another type
|
|
35
|
+ @classmethod
|
|
36
|
+ def c_delete(cls, lodel_id):
|
|
37
|
+ pass
|
|
38
|
+
|
|
39
|
+ ## @brief Update some objects in db
|
|
40
|
+ # @param lodel_id_l list : A list of lodel_id to update
|
|
41
|
+ # @param data dict : Represent the datas to update
|
|
42
|
+ # @return True if updated else False
|
|
43
|
+ # @throw InvalidArgumentError if invalid parameters
|
|
44
|
+ # @throw other Leo exceptions
|
|
45
|
+ @classmethod
|
|
46
|
+ def c_update(cls, lodel_id_l, datas):
|
|
47
|
+ pass
|
|
48
|
+
|
|
49
|
+ ## @brief Check that datas are valid for this type
|
|
50
|
+ # @param datas dict : key == field name value are field values
|
|
51
|
+ # @throw If the datas are not valids
|
|
52
|
+ @classmethod
|
|
53
|
+ def check_datas(cls, datas):
|
|
54
|
+ for dname, dval in datas.items():
|
|
55
|
+ if dname not in cls._fields.keys():
|
|
56
|
+ raise Exception()
|
|
57
|
+ cls._fields[dname].check_or_raise(dval)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+ ## @brief Implements the automatic checks of attributes
|
|
61
|
+ # @note Run data check from fieldtypes if we try to modify an field attribute of the LeType
|
|
62
|
+ # @param name str : The attribute name
|
|
63
|
+ # @param value * : The value
|
|
64
|
+ def __setattr__(self, name, value):
|
|
65
|
+ if name in self._fields.keys():
|
|
66
|
+ self._fields[name].check_or_raise(value)
|
|
67
|
+ return super(LeType, self).__setattr__(name, value)
|
|
68
|
+
|
|
69
|
+ ## @brief Delete the LeType
|
|
70
|
+ # @return True if deleted False if not
|
|
71
|
+ def delete(self):
|
|
72
|
+ return self.__class__.delete(self.lodel_id)
|
|
73
|
+
|
|
74
|
+ ## @brief Update a LeType
|
|
75
|
+ # @return True if ok else False
|
|
76
|
+ def update(self):
|
|
77
|
+ return self.__class__.update(self.lodel_id, self._datas)
|
|
78
|
+
|
|
79
|
+ ## @brief Fetch superiors
|
|
80
|
+ # @param nature str : The relation nature
|
|
81
|
+ # @return if no nature given return a dict with nature as key and arrays of LeObject as value. Else return an array of LeObject
|
|
82
|
+ def superiors(self, nature = None):
|
|
83
|
+ pass
|
|
84
|
+
|
|
85
|
+ ## @brief Fetch subordinates
|
|
86
|
+ # @param nature str : The relation nature
|
|
87
|
+ # @return if no nature given return a dict with nature as key and arrays of LeObject as value. Else return an array of LeObject
|
|
88
|
+ def subordinates(self, nature = None):
|
|
89
|
+ pass
|
|
90
|
+
|
|
91
|
+ ## @brief Add a superior
|
|
92
|
+ # @param nature str : The raltion nature
|
|
93
|
+ # @param leo LeObject : The superior
|
|
94
|
+ # @param return True if done False if already done
|
|
95
|
+ # @throw A Leo exception if trying to link with an invalid leo
|
|
96
|
+ # @throw InvalidArgumentError if invalid argument
|
|
97
|
+ def add_superior(self, nature, leo):
|
|
98
|
+ pass
|
|
99
|
+
|