Browse Source

Code cleaning (PEP8 / Pylint) on fields.py

Roland Haroutiounian 9 years ago
parent
commit
49f4f210b6
1 changed files with 11 additions and 14 deletions
  1. 11
    14
      EditorialModel/fields.py

+ 11
- 14
EditorialModel/fields.py View File

7
 from EditorialModel.exceptions import EmComponentCheckError
7
 from EditorialModel.exceptions import EmComponentCheckError
8
 import EditorialModel
8
 import EditorialModel
9
 import EditorialModel.fieldtypes
9
 import EditorialModel.fieldtypes
10
-from django.db import models
10
+#from django.db import models
11
+
11
 
12
 
12
 ## EmField (Class)
13
 ## EmField (Class)
13
 #
14
 #
22
     ## Instanciate a new EmField
23
     ## Instanciate a new EmField
23
     # @todo define and test type for icon and fieldtype
24
     # @todo define and test type for icon and fieldtype
24
     # @warning nullable == True by default
25
     # @warning nullable == True by default
25
-    def __init__(self, model, uid, name, fieldgroup_id, fieldtype, optional=False, internal=False, rel_field_id=None, icon='0', string=None, help_text=None, date_update=None, date_create=None, rank=None, nullable = True, default = None, uniq = False, **kwargs):
26
+    def __init__(self, model, uid, name, fieldgroup_id, fieldtype, optional=False, internal=False, rel_field_id=None, icon='0', string=None, help_text=None, date_update=None, date_create=None, rank=None, nullable=True, default=None, uniq=False, **kwargs):
26
 
27
 
27
-        if self.ftype == None:
28
+        if self.ftype is None:
28
             raise NotImplementedError("Trying to instanciate an EmField and not one of the fieldtypes child classes")
29
             raise NotImplementedError("Trying to instanciate an EmField and not one of the fieldtypes child classes")
29
 
30
 
30
         self.fieldgroup_id = fieldgroup_id
31
         self.fieldgroup_id = fieldgroup_id
37
         self.check_type('rel_field_id', (int, type(None)))
38
         self.check_type('rel_field_id', (int, type(None)))
38
         self.icon = icon
39
         self.icon = icon
39
 
40
 
40
-
41
         #Field type elements
41
         #Field type elements
42
         self.fieldtype = fieldtype
42
         self.fieldtype = fieldtype
43
         self.nullable = nullable
43
         self.nullable = nullable
46
 
46
 
47
         if len(kwargs) > 0:
47
         if len(kwargs) > 0:
48
             for kwargs_f in kwargs:
48
             for kwargs_f in kwargs:
49
-                warnings.warn("Argument '%s' not used and will be invalid for EmField __init__"%kwargs_f,SyntaxWarning)
50
-            
49
+                warnings.warn("Argument '%s' not used and will be invalid for EmField __init__" % kwargs_f, SyntaxWarning)
51
 
50
 
52
         super(EmField, self).__init__(model=model, uid=uid, name=name, string=string, help_text=help_text, date_update=date_update, date_create=date_create, rank=rank)
51
         super(EmField, self).__init__(model=model, uid=uid, name=name, string=string, help_text=help_text, date_update=date_update, date_create=date_create, rank=rank)
53
 
52
 
60
         if ftype == 'integer':
59
         if ftype == 'integer':
61
             ftype_module = importlib.import_module('EditorialModel.fieldtypes.int')
60
             ftype_module = importlib.import_module('EditorialModel.fieldtypes.int')
62
         else:
61
         else:
63
-            ftype_module = importlib.import_module('EditorialModel.fieldtypes.%s'%ftype)
62
+            ftype_module = importlib.import_module('EditorialModel.fieldtypes.%s' % ftype)
64
 
63
 
65
         return ftype_module.fclass
64
         return ftype_module.fclass
66
 
65
 
67
     @staticmethod
66
     @staticmethod
68
     ## @brief Return the list of allowed field type
67
     ## @brief Return the list of allowed field type
69
     def fieldtypes_list():
68
     def fieldtypes_list():
70
-        return [ f for f in EditorialModel.fieldtypes.__all__ if f != '__init__' ]
69
+        return [f for f in EditorialModel.fieldtypes.__all__ if f != '__init__']
71
 
70
 
72
     ## @brief Abstract method that should return a validation function
71
     ## @brief Abstract method that should return a validation function
73
     # @param raise_e Exception : if not valid raise this exception
72
     # @param raise_e Exception : if not valid raise this exception
74
     # @param ret_valid : if valid return this value
73
     # @param ret_valid : if valid return this value
75
     # @param ret_invalid : if not valid return this value
74
     # @param ret_invalid : if not valid return this value
76
-    def validation_function(self, raise_e = None, ret_valid = None, ret_invalid = None):
75
+    def validation_function(self, raise_e=None, ret_valid=None, ret_invalid=None):
77
         if self.__class__ == EmField:
76
         if self.__class__ == EmField:
78
             raise NotImplementedError("Abstract method")
77
             raise NotImplementedError("Abstract method")
79
         if raise_e is None and ret_valid is None:
78
         if raise_e is None and ret_valid is None:
80
             raise AttributeError("Behavior doesn't allows to return a valid validation function")
79
             raise AttributeError("Behavior doesn't allows to return a valid validation function")
81
 
80
 
82
         return False
81
         return False
83
-            
84
 
82
 
85
     ## @brief Return the list of relation fields for a rel_to_type
83
     ## @brief Return the list of relation fields for a rel_to_type
86
     # @return None if the field is not a rel_to_type else return a list of EmField
84
     # @return None if the field is not a rel_to_type else return a list of EmField
87
     def rel_to_type_fields(self):
85
     def rel_to_type_fields(self):
88
-        if not self.rel_to_type_id:
86
+        if not self.rel_to_type_id:  # TODO Ajouter cette propriété
89
             return None
87
             return None
90
-        
91
-        return [ f for f in self.model.components(EmField) if f.rel_field_id == self.uid ]
88
+
89
+        return [f for f in self.model.components(EmField) if f.rel_field_id == self.uid]
92
 
90
 
93
     ## Check if the EmField is valid
91
     ## Check if the EmField is valid
94
     # @return True if valid False if not
92
     # @return True if valid False if not
105
     # @todo Check if unconditionnal deletion is correct
103
     # @todo Check if unconditionnal deletion is correct
106
     def delete_check(self):
104
     def delete_check(self):
107
         return True
105
         return True
108
-

Loading…
Cancel
Save