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
         self.fieldtype = fieldtype
39
         self.fieldtype = fieldtype
40
         self._fieldtype_args = kwargs
40
         self._fieldtype_args = kwargs
41
         self._fieldtype_args.update({'nullable' : nullable, 'default' : default, 'uniq' : uniq})
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
         self.nullable = nullable
51
         self.nullable = nullable
46
         self.default = default
52
         self.default = default
47
         self.uniq = uniq
53
         self.uniq = uniq
48
- 
54
+
49
         for kname, kval in kwargs.items():
55
         for kname, kval in kwargs.items():
50
             setattr(self, kname, kval)
56
             setattr(self, kname, kval)
51
 
57
 

Loading…
Cancel
Save