mirror of
https://github.com/yweber/lodel2.git
synced 2026-03-22 02:52:02 +01:00
Updated fieldtypes to make easier the check_data_value inheritance
This commit is contained in:
parent
9cc1e8ab96
commit
df40d5f17d
3 changed files with 4 additions and 12 deletions
|
|
@ -37,16 +37,10 @@ class GenericFieldType(object):
|
|||
if ftype not in self._allowed_ftype:
|
||||
raise AttributeError("Ftype '%s' not known" % ftype)
|
||||
|
||||
if check_data_value is None:
|
||||
check_data_value = self.dummy_check_data_value
|
||||
elif not callable(check_data_value):
|
||||
raise AttributeError("check_data_value argument has to be a function it is a %s" % type(check_data_value))
|
||||
|
||||
if ftype != self.__class__.ftype:
|
||||
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)
|
||||
|
||||
self.ftype = ftype
|
||||
self._check_data_value = check_data_value
|
||||
self.nullable = bool(nullable)
|
||||
self.uniq = bool(uniq)
|
||||
|
||||
|
|
@ -92,10 +86,10 @@ class GenericFieldType(object):
|
|||
def check_data_consistency(self, lec, fname, datas):
|
||||
return True
|
||||
|
||||
## @brief Check if a value is correct
|
||||
## @brief Dummy check, designed to be implemented in child classes
|
||||
# @param value * : The value
|
||||
# @return (checked_and_casted_value, Exception|None)
|
||||
def dummy_check_data_value(self, value):
|
||||
def _check_data_value(self, value):
|
||||
return (value, None)
|
||||
|
||||
## @brief Given a fieldtype name return the associated python class
|
||||
|
|
|
|||
|
|
@ -10,11 +10,9 @@ class EmFieldType(GenericFieldType):
|
|||
ftype = 'int'
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
if 'check_data_value' not in kwargs:
|
||||
kwargs['check_data_value'] = self.check_value
|
||||
super(EmFieldType, self).__init__(ftype='int', **kwargs)
|
||||
|
||||
def check_value(self, value):
|
||||
def _check_data_value(self, value):
|
||||
error = None
|
||||
try:
|
||||
value = int(value)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class EmFieldType(char.EmFieldType):
|
|||
|
||||
super(EmFieldType, self).__init__(check_data_value=check_value, max_length=max_length, **kwargs)
|
||||
|
||||
def check_value(value):
|
||||
def _check_data_value(self,value):
|
||||
error = None
|
||||
if not self.compiled_re.match(value):
|
||||
value = ''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue