Browse Source

Emtype: whitespace and syntax error (lint + pep8)

ArnAud 9 years ago
parent
commit
af878631a0
1 changed files with 14 additions and 14 deletions
  1. 14
    14
      EditorialModel/types.py

+ 14
- 14
EditorialModel/types.py View File

24
     ## Instanciate a new EmType
24
     ## Instanciate a new EmType
25
     # @todo define and check types for icon and sortcolumn
25
     # @todo define and check types for icon and sortcolumn
26
     # @todo better check self.subordinates
26
     # @todo better check self.subordinates
27
-    def __init__(self, model, uid, name, class_id, fields_list = None, superiors_list = None, icon = '0', sortcolumn = 'rank', string = None, help_text = None, date_update = None, date_create = None, rank = None):
27
+    def __init__(self, model, uid, name, class_id, fields_list=None, superiors_list=None, icon='0', sortcolumn='rank', string=None, help_text=None, date_update=None, date_create=None, rank=None):
28
         self.class_id = class_id
28
         self.class_id = class_id
29
         self.check_type('class_id', int)
29
         self.check_type('class_id', int)
30
         self.fields_list = fields_list if fields_list is not None else []
30
         self.fields_list = fields_list if fields_list is not None else []
146
     def _change_field_list(self, field, select=True):
146
     def _change_field_list(self, field, select=True):
147
         if not isinstance(field, EmField):
147
         if not isinstance(field, EmField):
148
             raise TypeError("Excepted <class EmField> as field argument. But got " + str(type(field)))
148
             raise TypeError("Excepted <class EmField> as field argument. But got " + str(type(field)))
149
-        if not field in self.em_class.fields():
149
+        if field not in self.em_class.fields():
150
             raise ValueError("This field " + str(field) + "is not part of the type " + str(self))
150
             raise ValueError("This field " + str(field) + "is not part of the type " + str(self))
151
         if not field.optional:
151
         if not field.optional:
152
             raise ValueError("This field is not optional")
152
             raise ValueError("This field is not optional")
211
     # @return Return a dict with relation nature as keys and an EmType as value
211
     # @return Return a dict with relation nature as keys and an EmType as value
212
     # @throw RuntimeError if a nature has multiple superiors
212
     # @throw RuntimeError if a nature has multiple superiors
213
     def superiors(self):
213
     def superiors(self):
214
-        return { nature:[self.model.component(superior_uid) for superior_uid in superiors_uid] for nature, superiors_uid in self.superiors_list.items() }
214
+        return {nature: [self.model.component(superior_uid) for superior_uid in superiors_uid] for nature, superiors_uid in self.superiors_list.items()}
215
 
215
 
216
     ## Add a superior in the type hierarchy
216
     ## Add a superior in the type hierarchy
217
     # @param em_type EmType: An EmType instance
217
     # @param em_type EmType: An EmType instance
292
         if not em_class:
292
         if not em_class:
293
             raise EmComponentCheckError("class_id contains an uid that does not exists '%d'" % self.class_id)
293
             raise EmComponentCheckError("class_id contains an uid that does not exists '%d'" % self.class_id)
294
         if not isinstance(em_class, EditorialModel.classes.EmClass):
294
         if not isinstance(em_class, EditorialModel.classes.EmClass):
295
-            raise EmComponentCheckError("class_id contains an uid from a component that is not an EmClass but a %s" % str(type(emc_class)))
295
+            raise EmComponentCheckError("class_id contains an uid from a component that is not an EmClass but a %s" % str(type(em_class)))
296
 
296
 
297
-        for i,f_uid in enumerate(self.fields_list):
297
+        for i, f_uid in enumerate(self.fields_list):
298
             field = self.model.component(f_uid)
298
             field = self.model.component(f_uid)
299
             if not field:
299
             if not field:
300
-                raise EmComponentCheckError("The element %d of selected_field is a non existing uid '%d'"%(i, f_uid))
300
+                raise EmComponentCheckError("The element %d of selected_field is a non existing uid '%d'" % (i, f_uid))
301
             if not isinstance(field, EmField):
301
             if not isinstance(field, EmField):
302
-                raise EmComponentCheckError("The element %d of selected_field is not an EmField but a %s" % (i, str(type(field)) ))
302
+                raise EmComponentCheckError("The element %d of selected_field is not an EmField but a %s" % (i, str(type(field))))
303
             if not field.optional:
303
             if not field.optional:
304
-                raise EmComponentCheckError("The element %d of selected_field is an EmField not optional"  % i )
305
-            if field.fieldgroup_id not in [ fg.uid for fg in self.fieldgroups() ]:
304
+                raise EmComponentCheckError("The element %d of selected_field is an EmField not optional" % i)
305
+            if field.fieldgroup_id not in [fg.uid for fg in self.fieldgroups()]:
306
                 raise EmComponentCheckError("The element %d of selected_field is an EmField that is part of an EmFieldGroup that is not associated with this EmType" % i)
306
                 raise EmComponentCheckError("The element %d of selected_field is an EmField that is part of an EmFieldGroup that is not associated with this EmType" % i)
307
 
307
 
308
         for nature, superiors_uid in self.superiors_list.items():
308
         for nature, superiors_uid in self.superiors_list.items():
313
                 if not isinstance(em_type, EmType):
313
                 if not isinstance(em_type, EmType):
314
                     raise EmComponentCheckError("The superior is a component that is not an EmType but a %s" % (str(type(em_type))))
314
                     raise EmComponentCheckError("The superior is a component that is not an EmType but a %s" % (str(type(em_type))))
315
                 if nature not in EmClassType.natures(self.em_class.classtype):
315
                 if nature not in EmClassType.natures(self.em_class.classtype):
316
-                    raise EmComponentCheckError("The relation nature '%s' of the superior is not valid for this EmType classtype '%s'", (nature, self.classtype) )
316
+                    raise EmComponentCheckError("The relation nature '%s' of the superior is not valid for this EmType classtype '%s'", (nature, self.classtype))
317
 
317
 
318
                 nat_spec = getattr(EmClassType, self.em_class.classtype)['hierarchy'][nature]
318
                 nat_spec = getattr(EmClassType, self.em_class.classtype)['hierarchy'][nature]
319
 
319
 
320
                 if nat_spec['attach'] == 'classtype':
320
                 if nat_spec['attach'] == 'classtype':
321
                     if self.classtype != em_type.classtype:
321
                     if self.classtype != em_type.classtype:
322
-                        raise EmComponentCheckError("The superior is of '%s' classtype. But the current type is of '%s' classtype, and relation nature '%s' require two EmType of same classtype" % (em_type.classtype, self.classtype, nature) )
322
+                        raise EmComponentCheckError("The superior is of '%s' classtype. But the current type is of '%s' classtype, and relation nature '%s' require two EmType of same classtype" % (em_type.classtype, self.classtype, nature))
323
                 elif nat_spec['attach'] == 'type':
323
                 elif nat_spec['attach'] == 'type':
324
                     if self.uid != em_type.uid:
324
                     if self.uid != em_type.uid:
325
                         raise EmComponentCheckError("The superior is a different EmType. But the relation nature '%s' require the same EmType" % (nature))
325
                         raise EmComponentCheckError("The superior is a different EmType. But the relation nature '%s' require the same EmType" % (nature))
330
                     depth = 1
330
                     depth = 1
331
                     cur_type = em_type
331
                     cur_type = em_type
332
                     while depth >= nat_spec['max_depth']:
332
                     while depth >= nat_spec['max_depth']:
333
-                        depth +=1
333
+                        depth += 1
334
                         if len(cur_type.subordinates()[nature]) == 0:
334
                         if len(cur_type.subordinates()[nature]) == 0:
335
                             break
335
                             break
336
                     else:
336
                     else:
337
-                        raise EmComponentCheckError("The relation with the element %d of subordinates has a depth superior than the maximum depth ( %d ) allowed by the relation's nature ( '%s' )" %( i, nat_spec['max_depth'], nature) )
337
+                        raise EmComponentCheckError("The relation with superior %d  has a depth superior than the maximum depth (%d) allowed by the relation's nature '%s'" % (superior_uid, nat_spec['max_depth'], nature))
338
 
338
 
339
         for nature in self.subordinates():
339
         for nature in self.subordinates():
340
             nat_spec = getattr(EmClassType, self.em_class.classtype)['hierarchy'][nature]
340
             nat_spec = getattr(EmClassType, self.em_class.classtype)['hierarchy'][nature]
341
             if 'max_child' in nat_spec and nat_spec['max_child'] > 0:
341
             if 'max_child' in nat_spec and nat_spec['max_child'] > 0:
342
                 if len(self.subordinates()[nature]) > nat_spec['max_child']:
342
                 if len(self.subordinates()[nature]) > nat_spec['max_child']:
343
-                    raise EmComponentCheckError("The EmType has more child than allowed in the relation's nature : %d > %d" (len(self.subordinates()[nature], nat_spec['max_child'])))
343
+                    raise EmComponentCheckError("The EmType has more child than allowed in the relation's nature : %d > %d" % (len(self.subordinates()[nature], nat_spec['max_child'])))

Loading…
Cancel
Save