|
@@ -175,8 +175,7 @@ class EmComponent(object):
|
175
|
175
|
dbe = cls.db_engine()
|
176
|
176
|
conn = dbe.connect()
|
177
|
177
|
|
178
|
|
-
|
179
|
|
- kwargs['rank'] = get_max_rank() + 1 #Warning !!!
|
|
178
|
+ kwargs['rank'] = cl.get_max_rank(kwargs[cl.ranked_in]) + 1 #Warning !!!
|
180
|
179
|
|
181
|
180
|
|
182
|
181
|
table = sql.Table(cls.table, sqlutils.meta(dbe))
|
|
@@ -239,16 +238,16 @@ class EmComponent(object):
|
239
|
238
|
## get_max_rank
|
240
|
239
|
# Retourne le rank le plus élevé pour le groupe de component au quel apartient l'objet actuelle
|
241
|
240
|
#return int
|
242
|
|
- def get_max_rank(self):
|
243
|
|
- dbe = self.__class__.db_engine()
|
244
|
|
- component = sql.Table(self.table, sqlutils.meta(dbe))
|
245
|
|
- req = sql.sql.select([component.c.rank]).where(getattr(component.c, self.ranked_in) == getattr(self, self.ranked_in)).order_by(component.c.rank.desc())
|
246
|
|
- conn = dbe.connect()
|
247
|
|
- res = conn.execute(req)
|
|
241
|
+ @classmethod
|
|
242
|
+ def get_max_rank(cls, ranked_in_value):
|
|
243
|
+ dbe = cls.getDbE()
|
|
244
|
+ component = sql.Table(cls.table, sqlutils.meta(dbe))
|
|
245
|
+ req = sql.sql.select([component.c.rank]).where(getattr(component.c, cls.ranked_in) == ranked_in_value).order_by(component.c.rank.desc())
|
|
246
|
+ c = dbe.connect()
|
|
247
|
+ res = c.execute(req)
|
248
|
248
|
res = res.fetchone()
|
249
|
|
- conn.close()
|
250
|
|
-
|
251
|
|
- if (res is not None):
|
|
249
|
+ c.close()
|
|
250
|
+ if(res != None):
|
252
|
251
|
return res['rank']
|
253
|
252
|
else:
|
254
|
253
|
return -1
|
|
@@ -313,9 +312,9 @@ class EmComponent(object):
|
313
|
312
|
|
314
|
313
|
else:
|
315
|
314
|
logger.error("Bad argument")
|
316
|
|
- raise ValueError('new_rank to big, new_rank - 1 doesn\'t exist. new_rank = ' + str((new_rank)))
|
317
|
|
- elif (sign == '+' and self.rank + new_rank <= self.get_max_rank()):
|
318
|
315
|
|
|
316
|
+ raise ValueError('new_rank to big, new_rank - 1 doesn\'t exist. new_rank = '+str((new_rank)))
|
|
317
|
+ elif(sign == '+' and self.rank + new_rank <= self.__class__.get_max_rank(getattr(self, self.__class__.ranked_in))):
|
319
|
318
|
req = sql.sql.select([component.c.uid, component.c.rank])
|
320
|
319
|
req = req.where((getattr(component.c, self.ranked_in) == getattr(self, self.ranked_in)) & (component.c.rank == self.rank + new_rank))
|
321
|
320
|
conn = dbe.connect()
|