Browse Source

Solved a bug about checking ranks and getting max rank

Yann Weber 9 years ago
parent
commit
17c1eba918
2 changed files with 3 additions and 4 deletions
  1. 2
    3
      EditorialModel/components.py
  2. 1
    1
      EditorialModel/model.py

+ 2
- 3
EditorialModel/components.py View File

@@ -113,7 +113,7 @@ class EmComponent(object):
113 113
     # @throw EmComponentCheckError if fails
114 114
     def check(self):
115 115
         self.model.sort_components(self.__class__)
116
-        if self.get_max_rank() > len(self.same_rank_group()) or self.rank <= 0:
116
+        if self.get_max_rank() != len(self.same_rank_group()) or self.rank <= 0:
117 117
             #Non continuous ranks
118 118
             for i, component in enumerate(self.same_rank_group()):
119 119
                 component.rank = i + 1
@@ -127,8 +127,7 @@ class EmComponent(object):
127 127
     ## @brief Get the maximum rank given an EmComponent child class and a ranked_in filter
128 128
     # @return A positive integer or -1 if no components
129 129
     def get_max_rank(self):
130
-        components = self.same_rank_group()
131
-        return len(components) + 1
130
+        return len(self.same_rank_group())
132 131
 
133 132
     ## Return an array of instances that are concerned by the same rank
134 133
     # @return An array of instances that are concerned by the same rank

+ 1
- 1
EditorialModel/model.py View File

@@ -141,7 +141,7 @@ class Model(object):
141 141
         datas['uid'] = self.new_uid()
142 142
         em_component = em_obj(self, **datas)
143 143
 
144
-        em_component.rank = em_component.get_max_rank()
144
+        em_component.rank = em_component.get_max_rank() + 1 #Inserting last by default
145 145
 
146 146
         self._components['uids'][em_component.uid] = em_component
147 147
         self._components[self.name_from_emclass(em_component.__class__)].append(em_component)

Loading…
Cancel
Save