Browse Source

PEP8/Pylint on model.py

Roland Haroutiounian 9 years ago
parent
commit
3090208987
1 changed files with 14 additions and 15 deletions
  1. 14
    15
      EditorialModel/model.py

+ 14
- 15
EditorialModel/model.py View File

@@ -104,7 +104,7 @@ class Model(object):
104 104
 
105 105
     ## Saves data using the current backend
106 106
     # @param filename str | None : if None use the current backend file (provided at backend instanciation)
107
-    def save(self, filename = None):
107
+    def save(self, filename=None):
108 108
         return self.backend.save(self, filename)
109 109
 
110 110
     ## Given a EmComponent child class return a list of instances
@@ -117,7 +117,7 @@ class Model(object):
117 117
             if not cls:
118 118
                 return False
119 119
         if cls is None:
120
-            return [ self.component(uid) for uid in self._components['uids'] ]
120
+            return [self.component(uid) for uid in self._components['uids']]
121 121
         key_name = self.name_from_emclass(cls)
122 122
         return False if key_name is False else self._components[key_name]
123 123
 
@@ -131,15 +131,15 @@ class Model(object):
131 131
     # @param name str : the searched name
132 132
     # @param comp_cls str|EmComponent : filter on component type (see components() method)
133 133
     # @return a list of component with a specific name
134
-    def component_from_name(self, name, comp_cls = None):
134
+    def component_from_name(self, name, comp_cls=None):
135 135
         if comp_cls == EmField or comp_cls == 'EmField':
136 136
             res = list()
137
-            for field, fieldname in [ (f, f.name) for f in self.components('EmField')]:
137
+            for field, fieldname in [(f, f.name) for f in self.components('EmField')]:
138 138
                 if fieldname == name:
139 139
                     res.append(field)
140 140
             return res
141 141
 
142
-        for comp,compname in [ (c, c.name) for c in self.components(comp_cls)]:
142
+        for comp, compname in [(c, c.name) for c in self.components(comp_cls)]:
143 143
             if compname == name:
144 144
                 return comp
145 145
 
@@ -176,9 +176,9 @@ class Model(object):
176 176
     # @todo Transform the datas arg in **datas ?
177 177
     def create_component(self, component_type, datas, uid=None):
178 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 : %s"%repr(uid))
180
-        
181
-        if component_type not in [ n for n in self._components.keys() if n != 'uids' ]:
179
+            raise ValueError("Invalid uid provided : %s" % repr(uid))
180
+
181
+        if component_type not in [n for n in self._components.keys() if n != 'uids']:
182 182
             raise ValueError("Invalid component_type rpovided")
183 183
         else:
184 184
             em_obj = self.emclass_from_name(component_type)
@@ -191,7 +191,7 @@ class Model(object):
191 191
         datas['uid'] = uid if uid else self.new_uid()
192 192
         em_component = em_obj(model=self, **datas)
193 193
 
194
-        em_component.rank = em_component.get_max_rank() + 1 #  Inserting last by default
194
+        em_component.rank = em_component.get_max_rank() + 1  # Inserting last by default
195 195
 
196 196
         self._components['uids'][em_component.uid] = em_component
197 197
         self._components[component_type].append(em_component)
@@ -217,7 +217,7 @@ class Model(object):
217 217
             #Checking the component
218 218
             em_component.check()
219 219
             if component_type == 'EmClass':
220
-               # !!! If uid is not None it means that we shouldn't create components automatically !!!
220
+                # !!! If uid is not None it means that we shouldn't create components automatically !!!
221 221
                 self.add_default_class_fields(em_component.uid)
222 222
 
223 223
         return em_component
@@ -228,11 +228,11 @@ class Model(object):
228 228
     # @throw ValueError if class_uid in not an EmClass uid
229 229
     def add_default_class_fields(self, class_uid):
230 230
         if class_uid not in self._components['uids']:
231
-            raise ValueError("The uid '%d' don't exists"%class_uid)
231
+            raise ValueError("The uid '%d' don't exists" % class_uid)
232 232
         emclass = self._components['uids'][class_uid]
233 233
         if not isinstance(emclass, EditorialModel.classes.EmClass):
234
-            raise ValueError("The uid '%d' is not an EmClass uid"%class_uid)
235
-        
234
+            raise ValueError("The uid '%d' is not an EmClass uid" % class_uid)
235
+
236 236
         """
237 237
         fgroup_name = EmClass.default_fieldgroup
238 238
 
@@ -250,12 +250,11 @@ class Model(object):
250 250
 
251 251
         default_fields = emclass.default_fields_list()
252 252
         for fname, fdatas in default_fields.items():
253
-            if not (fname in [ f.name for f in emclass.fields() ]):
253
+            if not (fname in [f.name for f in emclass.fields()]):
254 254
                 #Adding the field
255 255
                 fdatas['name'] = fname
256 256
                 fdatas['class_id'] = class_uid
257 257
                 self.create_component('EmField', fdatas)
258
-        pass
259 258
 
260 259
     ## Delete a component
261 260
     # @param uid int : Component identifier

Loading…
Cancel
Save