|
@@ -13,9 +13,8 @@ class LeQuery(object):
|
13
|
13
|
## @brief The datasource object used for this Query class
|
14
|
14
|
_datasource = None
|
15
|
15
|
|
16
|
|
- ## @brief the operators map
|
17
|
|
- # assigns the right operator for a string based key (ex: "lte" => "<=" )
|
18
|
|
- _query_operators_map = {}
|
|
16
|
+ ## @brief the operators used in query definitions
|
|
17
|
+ _query_operators_map = ['=', '<=', '>=', '!=', '<', '>', ' in ', ' not in ', ' like ', ' not like ']
|
19
|
18
|
|
20
|
19
|
## @brief Constructor
|
21
|
20
|
# @param target_class LeObject class or childs : The LeObject child class concerned by this query
|
|
@@ -32,7 +31,7 @@ class LeQuery(object):
|
32
|
31
|
|
33
|
32
|
## @brief Executes the query
|
34
|
33
|
# @return dict : The results of the query
|
35
|
|
- def execute_query(self):
|
|
34
|
+ def execute(self):
|
36
|
35
|
return {}
|
37
|
36
|
|
38
|
37
|
|
|
@@ -77,6 +76,64 @@ class LeUpdateQuery(LeFilteredQuery):
|
77
|
76
|
# Name of the corresponding action
|
78
|
77
|
action = 'update'
|
79
|
78
|
|
|
79
|
+ def __init__(self, datas=None):
|
|
80
|
+ self.datas = datas if datas is None else locals()
|
|
81
|
+ del(self.datas['self'])
|
|
82
|
+
|
|
83
|
+ ## @brief executes the query, with corresponding hooks
|
|
84
|
+ # @return dict
|
|
85
|
+ def execute(self):
|
|
86
|
+ # LodelHook.call_hook('leapi_update_pre', self, None)
|
|
87
|
+ ret = self.update()
|
|
88
|
+ return self.after_update(ret)
|
|
89
|
+
|
|
90
|
+ ## @brief calls before-update hook(s)
|
|
91
|
+ # @return dict
|
|
92
|
+ # @todo to be implemented
|
|
93
|
+ def before_update(self):
|
|
94
|
+ return self.datas
|
|
95
|
+
|
|
96
|
+ ## @brief calls hook(s) after the update process
|
|
97
|
+ # @param ret : returned results
|
|
98
|
+ # @return bool : True if success
|
|
99
|
+ # @todo to be implemented
|
|
100
|
+ def after_update(self, ret):
|
|
101
|
+ return ret
|
|
102
|
+
|
|
103
|
+ ## @brief performs the update in the datasource
|
|
104
|
+ # @TODO the call to _datasource.update() will be changed when the corresponding method is implemented
|
|
105
|
+ # @TODO in case of an error, we should add code to manage it
|
|
106
|
+ def update(self):
|
|
107
|
+ if 'uid' not in self.datas:
|
|
108
|
+ raise LeQueryError("No object uid given to the query. The update can't be performed")
|
|
109
|
+ updated_datas = self.prepare_query()
|
|
110
|
+ ret = self._datasource.update(self.datas['uid'], **updated_datas)
|
|
111
|
+ if ret == 1:
|
|
112
|
+ return True
|
|
113
|
+ return False
|
|
114
|
+
|
|
115
|
+ ## @brief checks and prepare datas
|
|
116
|
+ # @return dict
|
|
117
|
+ def prepare_query(self):
|
|
118
|
+ ret_datas = self.check_datas_value(self.datas)
|
|
119
|
+ if isinstance(ret_datas, Exception):
|
|
120
|
+ raise ret_datas
|
|
121
|
+ ret_datas = self.construct_datas(ret_datas)
|
|
122
|
+ self.check_datas_consistency(ret_datas)
|
|
123
|
+ return ret_datas
|
|
124
|
+
|
|
125
|
+ def check_datas_value(self, datas):
|
|
126
|
+ err_l = dict() # Stores all errors occurring during the process
|
|
127
|
+ correct = [] # Valid fields name
|
|
128
|
+ mandatory = [] # mandatory fields name
|
|
129
|
+ pass
|
|
130
|
+
|
|
131
|
+ def construct_datas(self, datas):
|
|
132
|
+ pass
|
|
133
|
+
|
|
134
|
+ def check_datas_consistency(self, datas):
|
|
135
|
+ pass
|
|
136
|
+
|
80
|
137
|
|
81
|
138
|
## @brief Handles Delete queries
|
82
|
139
|
class LeDeleteQuery(LeFilteredQuery):
|