Browse Source

Some bugfix in components.max_rank model.create_component in the random em generator and in the file fieldtype

Yann Weber 9 years ago
parent
commit
36ffdfdf0c

+ 2
- 2
EditorialModel/components.py View File

141
         raise NotImplementedError("Virtual method")
141
         raise NotImplementedError("Virtual method")
142
 
142
 
143
     ## @brief Get the maximum rank given an EmComponent child class and a ranked_in filter
143
     ## @brief Get the maximum rank given an EmComponent child class and a ranked_in filter
144
-    # @return The max rank is the rank group or -1 if no components in that group
144
+    # @return The max rank is the rank group or 0 if no components in that group
145
     def get_max_rank(self):
145
     def get_max_rank(self):
146
         same_rgroup = self.same_rank_group()
146
         same_rgroup = self.same_rank_group()
147
-        return max([comp.rank for comp in same_rgroup]) if len(same_rgroup) > 0 else -1
147
+        return max([comp.rank for comp in same_rgroup]) if len(same_rgroup) > 0 else 0
148
 
148
 
149
     ## Return an array of instances that are concerned by the same rank
149
     ## Return an array of instances that are concerned by the same rank
150
     # @return An array of instances that are concerned by the same rank
150
     # @return An array of instances that are concerned by the same rank

+ 1
- 1
EditorialModel/fieldtypes/file.py View File

12
     # @brief max_length int : The maximum length of this field
12
     # @brief max_length int : The maximum length of this field
13
     def __init__(self, upload_path=None, **kwargs):
13
     def __init__(self, upload_path=None, **kwargs):
14
         self.upload_path = upload_path
14
         self.upload_path = upload_path
15
-        super(EmFieldType, self).__init__(ftype='char',**kwargs)
15
+        super(EmFieldType, self).__init__(ftype='char', max_length=512,**kwargs)
16
 
16
 

+ 3
- 1
EditorialModel/model.py View File

176
     # @todo Transform the datas arg in **datas ?
176
     # @todo Transform the datas arg in **datas ?
177
     def create_component(self, component_type, datas, uid=None):
177
     def create_component(self, component_type, datas, uid=None):
178
         if not (uid is None) and (not isinstance(uid, int) or uid <= 0 or uid in self._components['uids']):
178
         if not (uid is None) and (not isinstance(uid, int) or uid <= 0 or uid in self._components['uids']):
179
-            raise ValueError("Invalid uid provided")
179
+            raise ValueError("Invalid uid provided : %s"%repr(uid))
180
         
180
         
181
         if component_type not in [ n for n in self._components.keys() if n != 'uids' ]:
181
         if component_type not in [ n for n in self._components.keys() if n != 'uids' ]:
182
             raise ValueError("Invalid component_type rpovided")
182
             raise ValueError("Invalid component_type rpovided")
216
         if uid is None and component_type == 'EmClass':
216
         if uid is None and component_type == 'EmClass':
217
             # !!! If uid is not None it means that we shouldn't create components automatically !!!
217
             # !!! If uid is not None it means that we shouldn't create components automatically !!!
218
             self.add_default_class_fields(em_component.uid)
218
             self.add_default_class_fields(em_component.uid)
219
+            #Checking the component
220
+            em_component.check()
219
 
221
 
220
         return em_component
222
         return em_component
221
 
223
 

+ 3
- 3
EditorialModel/randomem.py View File

107
                         emtype.add_superior(possible[nat][i], nat)
107
                         emtype.add_superior(possible[nat][i], nat)
108
 
108
 
109
         #fields creation
109
         #fields creation
110
-        ft_l = EmField.fieldtypes_list()
110
+        ft_l = [ ftname for ftname in EmField.fieldtypes_list() if ftname != 'pk' ]
111
         for emfg in ed_mod.components(EmFieldGroup):
111
         for emfg in ed_mod.components(EmFieldGroup):
112
             if random.randint(0, chances['nofields']) != 0:
112
             if random.randint(0, chances['nofields']) != 0:
113
                 for _ in range(random.randint(1, chances['nfields'])):
113
                 for _ in range(random.randint(1, chances['nfields'])):
123
                     ed_mod.create_component('EmField', fdats)
123
                     ed_mod.create_component('EmField', fdats)
124
 
124
 
125
         #relationnal fiels creation
125
         #relationnal fiels creation
126
-        ft_l = [field_type for field_type in EmField.fieldtypes_list() if field_type != 'rel2type']
127
-        for emrelf in [f for f in ed_mod.components(EmField) if f.ftype == 'rel2type']:
126
+        ft_l = [field_type for field_type in EmField.fieldtypes_list() if field_type != 'rel2type' and field_type  != 'pk']
127
+        for emrelf in [f for f in ed_mod.components(EmField) if f.fieldtype == 'rel2type']:
128
             for _ in range(0, chances['rfields']):
128
             for _ in range(0, chances['rfields']):
129
                 field_type = ft_l[random.randint(0, len(ft_l) - 1)]
129
                 field_type = ft_l[random.randint(0, len(ft_l) - 1)]
130
                 fdats = cls._rnd_component_datas()
130
                 fdats = cls._rnd_component_datas()

Loading…
Cancel
Save