Browse Source

LeRelation : Modification de l'implémentation du max_rank

Roland Haroutiounian 9 years ago
parent
commit
6f4f69ec6e
2 changed files with 7 additions and 4 deletions
  1. 4
    3
      DataSource/MySQL/leapidatasource.py
  2. 3
    1
      leapi/lerelation.py

+ 4
- 3
DataSource/MySQL/leapidatasource.py View File

@@ -423,11 +423,12 @@ class LeDataSourceSQL(DummyDatasource):
423 423
     # TODO Conserver cette méthode dans le datasource du fait des requêtes SQL. Elle est appelée par le set_rank de LeRelation
424 424
     def update_rank(self, le_relation, rank):
425 425
 
426
-        lesup = le_relation.lesup
427
-        lesub = le_relation.lesub
426
+        lesup = le_relation.id_sup
427
+        lesub = le_relation.id_sub
428 428
         current_rank = le_relation.rank
429 429
 
430
-        relations = self.get_related(lesup, lesub.__class__, get_sub=True)
430
+        relations = le_relation.__class__.get(query_filters=[('id_sup', '=', lesup)], order=[('rank', 'ASC')])
431
+        # relations = self.get_related(lesup, lesub.__class__, get_sub=True)
431 432
 
432 433
         # insert the relation at the right position considering its new rank
433 434
         our_relation = relations.pop(current_rank)

+ 3
- 1
leapi/lerelation.py View File

@@ -133,7 +133,9 @@ class _LeRelation(lecrud._LeCrud):
133 133
     ## @returns The maximum assignable rank for this relation
134 134
     # @todo implementation
135 135
     def get_max_rank(self):
136
-        return self._datasource.select(self.__class__, ['rank'])
136
+        max_rank_result = self.__class__.get(query_filters=['*'],field_list=['rank'], order=[('rank', 'DESC')], limit=1)
137
+        max_rank = max_rank_result[0].rank
138
+        return max_rank+1
137 139
 
138 140
 ## @brief Abstract class to handle hierarchy relations
139 141
 class _LeHierarch(_LeRelation):

Loading…
Cancel
Save