Browse Source

EmField enhancement in __init__

Add a check for the default value
Removed the _fieldtype_instance attribute
Yann Weber 9 years ago
parent
commit
4046af11eb
1 changed files with 8 additions and 2 deletions
  1. 8
    2
      EditorialModel/fields.py

+ 8
- 2
EditorialModel/fields.py View File

@@ -39,13 +39,19 @@ class EmField(EmComponent):
39 39
         self.fieldtype = fieldtype
40 40
         self._fieldtype_args = kwargs
41 41
         self._fieldtype_args.update({'nullable' : nullable, 'default' : default, 'uniq' : uniq})
42
-        self._fieldtype_instance = self._fieldtype_cls(**self._fieldtype_args)
42
+        try:
43
+            fieldtype_instance = self._fieldtype_cls(**self._fieldtype_args)
44
+        except AttributeError as e:
45
+            raise AttributeError("Error will instanciating fieldtype : %s"%e)
46
+
47
+        if not fieldtype_instance.check(default):
48
+            raise TypeError("Default value ('%s') is not valid given the fieldtype '%s'"%(default, fieldtype))
43 49
 
44 50
 
45 51
         self.nullable = nullable
46 52
         self.default = default
47 53
         self.uniq = uniq
48
- 
54
+
49 55
         for kname, kval in kwargs.items():
50 56
             setattr(self, kname, kval)
51 57
 

Loading…
Cancel
Save