Browse Source

Better comments for set_rank method

Yann Weber 9 years ago
parent
commit
cd37b0129f
1 changed files with 7 additions and 6 deletions
  1. 7
    6
      EditorialModel/components.py

+ 7
- 6
EditorialModel/components.py View File

@@ -279,6 +279,7 @@ class EmComponent(object):
279 279
             return -1
280 280
 
281 281
     ## Set a new rank for this component
282
+    # @note This function assume that ranks are properly set from 1 to x with no gap
282 283
     # @param new_rank int: The new rank
283 284
     # @return True if success False if not
284 285
     # @throw TypeError If bad argument type
@@ -288,13 +289,13 @@ class EmComponent(object):
288 289
             raise TypeError("Excepted <class int> but got "+str(type(new_rank)))
289 290
         if new_rank < 0 or new_rank > self.get_max_rank(getattr(self, self.ranked_in)):
290 291
             raise ValueError("Invalid new rank : "+str(new_rank))
291
-        #more checks to be done here
292
-        mod = new_rank - self.rank
293 292
 
294
-        if mod == 0:
293
+        mod = new_rank - self.rank #Allow to know the "direction" of the "move"
294
+
295
+        if mod == 0: #No modifications
295 296
             return True
296 297
 
297
-        limits = [ self.rank + ( 1 if mod > 0 else -1), new_rank ]
298
+        limits = [ self.rank + ( 1 if mod > 0 else -1), new_rank ] #The range of modified ranks
298 299
         limits.sort()
299 300
 
300 301
         dbe = self.db_engine()
@@ -305,13 +306,12 @@ class EmComponent(object):
305 306
         req = table.select().where( getattr(table.c, self.ranked_in) == getattr(self, self.ranked_in)).where(table.c.rank >= limits[0]).where(table.c.rank <= limits[1])
306 307
 
307 308
         res = conn.execute(req)
308
-        if not res:
309
+        if not res: #Db error... Maybe false is a bit silent for a failuer
309 310
             return False
310 311
 
311 312
         rows = res.fetchall()
312 313
 
313 314
         updated_ranks = [{'b_uid': self.uid, 'b_rank': new_rank}]
314
-
315 315
         for row in rows:
316 316
             updated_ranks.append({'b_uid': row['uid'], 'b_rank': row['rank'] + (-1 if mod > 0 else 1)})
317 317
         req = table.update().where(table.c.uid == sql.bindparam('b_uid')).values(rank=sql.bindparam('b_rank'))
@@ -319,6 +319,7 @@ class EmComponent(object):
319 319
         conn.close()
320 320
         
321 321
         if res:
322
+            #Instance rank update
322 323
             self._fields['rank'].value = new_rank
323 324
         return bool(res)
324 325
     

Loading…
Cancel
Save