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,7 +7,8 @@ from EditorialModel.components import EmComponent
7 7
 from EditorialModel.exceptions import EmComponentCheckError
8 8
 import EditorialModel
9 9
 import EditorialModel.fieldtypes
10
-from django.db import models
10
+#from django.db import models
11
+
11 12
 
12 13
 ## EmField (Class)
13 14
 #
@@ -22,9 +23,9 @@ class EmField(EmComponent):
22 23
     ## Instanciate a new EmField
23 24
     # @todo define and test type for icon and fieldtype
24 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 29
             raise NotImplementedError("Trying to instanciate an EmField and not one of the fieldtypes child classes")
29 30
 
30 31
         self.fieldgroup_id = fieldgroup_id
@@ -37,7 +38,6 @@ class EmField(EmComponent):
37 38
         self.check_type('rel_field_id', (int, type(None)))
38 39
         self.icon = icon
39 40
 
40
-
41 41
         #Field type elements
42 42
         self.fieldtype = fieldtype
43 43
         self.nullable = nullable
@@ -46,8 +46,7 @@ class EmField(EmComponent):
46 46
 
47 47
         if len(kwargs) > 0:
48 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 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,35 +59,34 @@ class EmField(EmComponent):
60 59
         if ftype == 'integer':
61 60
             ftype_module = importlib.import_module('EditorialModel.fieldtypes.int')
62 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 64
         return ftype_module.fclass
66 65
 
67 66
     @staticmethod
68 67
     ## @brief Return the list of allowed field type
69 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 71
     ## @brief Abstract method that should return a validation function
73 72
     # @param raise_e Exception : if not valid raise this exception
74 73
     # @param ret_valid : if valid return this value
75 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 76
         if self.__class__ == EmField:
78 77
             raise NotImplementedError("Abstract method")
79 78
         if raise_e is None and ret_valid is None:
80 79
             raise AttributeError("Behavior doesn't allows to return a valid validation function")
81 80
 
82 81
         return False
83
-            
84 82
 
85 83
     ## @brief Return the list of relation fields for a rel_to_type
86 84
     # @return None if the field is not a rel_to_type else return a list of EmField
87 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 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 91
     ## Check if the EmField is valid
94 92
     # @return True if valid False if not
@@ -105,4 +103,3 @@ class EmField(EmComponent):
105 103
     # @todo Check if unconditionnal deletion is correct
106 104
     def delete_check(self):
107 105
         return True
108
-

Loading…
Cancel
Save