|
@@ -159,6 +159,7 @@ class EmComponent(object):
|
159
|
159
|
#
|
160
|
160
|
# @return bool: True en cas de réussite False en cas d'echec.
|
161
|
161
|
def modify_rank(self, new_rank, sign = '='):
|
|
162
|
+
|
162
|
163
|
if(type(new_rank) is int):
|
163
|
164
|
if(new_rank >= 0):
|
164
|
165
|
dbe = self.__class__.getDbE()
|
|
@@ -169,16 +170,16 @@ class EmComponent(object):
|
169
|
170
|
logger.error("Bad argument")
|
170
|
171
|
raise TypeError('Excepted a string (\'=\' or \'+\' or \'-\') not a '+str(type(sign)))
|
171
|
172
|
|
172
|
|
- req = req.where((getattr(component.c, self.ranked_in) == getattr(self, self.ranked_in)) & (component.c.rank == new_rank))
|
173
|
|
- c = dbe.connect()
|
174
|
|
- res = c.execute(req)
|
175
|
|
- res = res.fetchone()
|
176
|
|
- c.close()
|
|
173
|
+ if(sign == '='):
|
177
|
174
|
|
178
|
|
- req = sql.sql.select([component.c.uid, component.c.rank])
|
|
175
|
+ req = sql.sql.select([component.c.uid, component.c.rank])
|
|
176
|
+ req = req.where((getattr(component.c, self.ranked_in) == getattr(self, self.ranked_in)) & (component.c.rank == new_rank))
|
|
177
|
+ c = dbe.connect()
|
|
178
|
+ res = c.execute(req)
|
|
179
|
+ res = res.fetchone()
|
|
180
|
+ c.close()
|
179
|
181
|
|
180
|
|
- if(res != None):
|
181
|
|
- if(sign == '='):
|
|
182
|
+ if(res != None):
|
182
|
183
|
if(new_rank < self.rank):
|
183
|
184
|
req = req.where((getattr(component.c, self.ranked_in) == getattr(self, self.ranked_in)) & ( component.c.rank >= new_rank) & (component.c.rank < self.rank))
|
184
|
185
|
else:
|
|
@@ -203,7 +204,19 @@ class EmComponent(object):
|
203
|
204
|
c.close()
|
204
|
205
|
|
205
|
206
|
self.rank = new_rank
|
206
|
|
- elif(sign == '+'):
|
|
207
|
+
|
|
208
|
+ else:
|
|
209
|
+ logger.error("Bad argument")
|
|
210
|
+ raise ValueError('new_rank to big, new_rank - 1 doesn\'t exist. new_rank = '+str((new_rank)))
|
|
211
|
+ elif(sign == '+'):
|
|
212
|
+ req = sql.sql.select([component.c.uid, component.c.rank])
|
|
213
|
+ req = req.where((getattr(component.c, self.ranked_in) == getattr(self, self.ranked_in)) & (component.c.rank == self.rank + new_rank))
|
|
214
|
+ c = dbe.connect()
|
|
215
|
+ res = c.execute(req)
|
|
216
|
+ res = res.fetchone()
|
|
217
|
+ c.close()
|
|
218
|
+
|
|
219
|
+ if(res != None):
|
207
|
220
|
if(new_rank != 0):
|
208
|
221
|
req = req.where((getattr(component.c, self.ranked_in) == getattr(self, self.ranked_in)) & (component.c.rank <= self.rank + new_rank) & (component.c.rank > self.rank))
|
209
|
222
|
|
|
@@ -225,7 +238,11 @@ class EmComponent(object):
|
225
|
238
|
else:
|
226
|
239
|
logger.error("Bad argument")
|
227
|
240
|
raise ValueError('Excepted a positive int not a null. new_rank = '+str((new_rank)))
|
228
|
|
- elif(sign == '-'):
|
|
241
|
+ else:
|
|
242
|
+ logger.error("Bad argument")
|
|
243
|
+ raise ValueError('new_rank to big, rank + new rank doesn\'t exist. new_rank = '+str((new_rank)))
|
|
244
|
+ elif(sign == '-'):
|
|
245
|
+ if((self.rank + new_rank) > 0):
|
229
|
246
|
if(new_rank != 0):
|
230
|
247
|
req = req.where((getattr(component.c, self.ranked_in) == getattr(self, self.ranked_in)) & (component.c.rank >= self.rank - new_rank) & (component.c.rank < self.rank))
|
231
|
248
|
|
|
@@ -249,10 +266,11 @@ class EmComponent(object):
|
249
|
266
|
raise ValueError('Excepted a positive int not a null. new_rank = '+str((new_rank)))
|
250
|
267
|
else:
|
251
|
268
|
logger.error("Bad argument")
|
252
|
|
- raise ValueError('Excepted a string (\'=\' or \'+\' or \'-\') not a '+str((sign)))
|
|
269
|
+ raise ValueError('new_rank to big, rank - new rank is negative. new_rank = '+str((new_rank)))
|
253
|
270
|
else:
|
254
|
271
|
logger.error("Bad argument")
|
255
|
|
- raise ValueError('new_rank to big, new_rank - 1 doesn\'t exist. new_rank = '+str((new_rank)))
|
|
272
|
+ raise ValueError('Excepted a string (\'=\' or \'+\' or \'-\') not a '+str((sign)))
|
|
273
|
+
|
256
|
274
|
else:
|
257
|
275
|
logger.error("Bad argument")
|
258
|
276
|
raise ValueError('Excepted a positive int not a negative. new_rank = '+str((new_rank)))
|