Browse Source

Checking type of model argument (without importing Model)

The check is done on the __class__.__name__ attr of model argument (maybe not a good solution ?)
Yann Weber 9 years ago
parent
commit
d2f6509397
1 changed files with 4 additions and 2 deletions
  1. 4
    2
      EditorialModel/components.py

+ 4
- 2
EditorialModel/components.py View File

@@ -28,8 +28,10 @@ class EmComponent(object):
28 28
     def __init__(self, model, uid, name, string = None, help_text = None, date_update = None, date_create = None, rank = None):
29 29
         if type(self) == EmComponent:
30 30
            raise NotImplementedError('Abstract class')
31
- 
32
-        self.model = model # AHAH cannot check type without importing Model ? 
31
+        if model.__class__.__name__ != 'Model':
32
+            raise TypeError("Excepted type for 'model' arg is <class 'Model'> but got {} instead".format(type(model)))
33
+
34
+        self.model = model
33 35
 
34 36
         self.uid = uid
35 37
         self.check_type('uid', int)

Loading…
Cancel
Save