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

+ 1
- 1
EditorialModel/model.py View File

141
         datas['uid'] = self.new_uid()
141
         datas['uid'] = self.new_uid()
142
         em_component = em_obj(self, **datas)
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
         self._components['uids'][em_component.uid] = em_component
146
         self._components['uids'][em_component.uid] = em_component
147
         self._components[self.name_from_emclass(em_component.__class__)].append(em_component)
147
         self._components[self.name_from_emclass(em_component.__class__)].append(em_component)

Loading…
Cancel
Save