Browse Source

Updated fieldtypes to make easier the check_data_value inheritance

Yann Weber 9 years ago
parent
commit
df40d5f17d

+ 2
- 8
EditorialModel/fieldtypes/generic.py View File

@@ -37,16 +37,10 @@ class GenericFieldType(object):
37 37
         if ftype not in self._allowed_ftype:
38 38
             raise AttributeError("Ftype '%s' not known" % ftype)
39 39
 
40
-        if check_data_value is None:
41
-            check_data_value = self.dummy_check_data_value
42
-        elif not callable(check_data_value):
43
-            raise AttributeError("check_data_value argument has to be a function it is a %s" % type(check_data_value))
44
-
45 40
         if ftype != self.__class__.ftype:
46 41
             raise RuntimeError("The ftype is not the same for the instance and the class. Maybe %s reimplement ftype at class level but shouldn't" % self.name)
47 42
 
48 43
         self.ftype = ftype
49
-        self._check_data_value = check_data_value
50 44
         self.nullable = bool(nullable)
51 45
         self.uniq = bool(uniq)
52 46
 
@@ -92,10 +86,10 @@ class GenericFieldType(object):
92 86
     def check_data_consistency(self, lec, fname, datas):
93 87
         return True
94 88
 
95
-    ## @brief Check if a value is correct
89
+    ## @brief Dummy check, designed to be implemented in child classes
96 90
     # @param value * : The value
97 91
     # @return (checked_and_casted_value, Exception|None)
98
-    def dummy_check_data_value(self, value):
92
+    def _check_data_value(self, value):
99 93
         return (value, None)
100 94
 
101 95
     ## @brief Given a fieldtype name return the associated python class

+ 1
- 3
EditorialModel/fieldtypes/integer.py View File

@@ -10,11 +10,9 @@ class EmFieldType(GenericFieldType):
10 10
     ftype = 'int'
11 11
 
12 12
     def __init__(self, **kwargs):
13
-        if 'check_data_value' not in kwargs:
14
-            kwargs['check_data_value'] = self.check_value
15 13
         super(EmFieldType, self).__init__(ftype='int', **kwargs)
16 14
 
17
-    def check_value(self, value):
15
+    def _check_data_value(self, value):
18 16
         error = None
19 17
         try:
20 18
             value = int(value)

+ 1
- 1
EditorialModel/fieldtypes/regexchar.py View File

@@ -19,7 +19,7 @@ class EmFieldType(char.EmFieldType):
19 19
 
20 20
         super(EmFieldType, self).__init__(check_data_value=check_value, max_length=max_length, **kwargs)
21 21
 
22
-    def check_value(value):
22
+    def _check_data_value(self,value):
23 23
         error = None
24 24
         if not self.compiled_re.match(value):
25 25
             value = ''

Loading…
Cancel
Save