|
@@ -4,7 +4,9 @@ import datetime
|
4
|
4
|
import time
|
5
|
5
|
import os
|
6
|
6
|
|
7
|
|
-from lodel.leapi.datahandlers.base_classes import DataField, FieldValidationError
|
|
7
|
+from lodel.leapi.datahandlers.base_classes import DataField
|
|
8
|
+from lodel.exceptions import *
|
|
9
|
+
|
8
|
10
|
|
9
|
11
|
##@brief Data field designed to handle boolean values
|
10
|
12
|
class Boolean(DataField):
|
|
@@ -18,6 +20,10 @@ class Boolean(DataField):
|
18
|
20
|
# kwargs['check_data_value'] = self._check_data_value
|
19
|
21
|
super().__init__(ftype='bool', **kwargs)
|
20
|
22
|
|
|
23
|
+ ##@brief Check and cast value in appropriate type
|
|
24
|
+ #@param value *
|
|
25
|
+ #@throw FieldValidationError if value is unappropriate or can not be cast
|
|
26
|
+ #@return value
|
21
|
27
|
def _check_data_value(self, value):
|
22
|
28
|
value = super()._check_data_value(value)
|
23
|
29
|
if not isinstance(value, bool):
|
|
@@ -34,6 +40,10 @@ class Integer(DataField):
|
34
|
40
|
def __init__(self, **kwargs):
|
35
|
41
|
super().__init__( **kwargs)
|
36
|
42
|
|
|
43
|
+ ##@brief Check and cast value in appropriate type
|
|
44
|
+ #@param value *
|
|
45
|
+ #@throw FieldValidationError if value is unappropriate or can not be cast
|
|
46
|
+ #@return value
|
37
|
47
|
def _check_data_value(self, value, strict = False):
|
38
|
48
|
value = super()._check_data_value(value)
|
39
|
49
|
if (strict and isinstance(value, int)):
|
|
@@ -68,6 +78,10 @@ class Varchar(DataField):
|
68
|
78
|
return False
|
69
|
79
|
return True
|
70
|
80
|
|
|
81
|
+ ##@brief Check and cast value in appropriate type
|
|
82
|
+ #@param value *
|
|
83
|
+ #@throw FieldValidationError if value is unappropriate or can not be cast
|
|
84
|
+ #@return value
|
71
|
85
|
def _check_data_value(self, value):
|
72
|
86
|
value = super()._check_data_value(value)
|
73
|
87
|
if not isinstance(value, str):
|
|
@@ -75,6 +89,7 @@ class Varchar(DataField):
|
75
|
89
|
if len(value) > self.max_length:
|
76
|
90
|
raise FieldValidationError("The value '%s' is longer than the maximum length of this field (%s)" % (value, self.max_length))
|
77
|
91
|
return value
|
|
92
|
+
|
78
|
93
|
##@brief Data field designed to handle date & time
|
79
|
94
|
class DateTime(DataField):
|
80
|
95
|
|
|
@@ -91,6 +106,10 @@ class DateTime(DataField):
|
91
|
106
|
self.datetime_format = '%Y-%m-%d' if 'format' not in kwargs else kwargs['format']
|
92
|
107
|
super().__init__(**kwargs)
|
93
|
108
|
|
|
109
|
+ ##@brief Check and cast value in appropriate type
|
|
110
|
+ #@param value *
|
|
111
|
+ #@throw FieldValidationError if value is unappropriate or can not be cast
|
|
112
|
+ #@return value
|
94
|
113
|
def _check_data_value(self, value):
|
95
|
114
|
value = super()._check_data_value(value)
|
96
|
115
|
if isinstance(value,str):
|
|
@@ -116,6 +135,10 @@ class Text(DataField):
|
116
|
135
|
def __init__(self, **kwargs):
|
117
|
136
|
super(self.__class__, self).__init__(ftype='text', **kwargs)
|
118
|
137
|
|
|
138
|
+ ##@brief Check and cast value in appropriate type
|
|
139
|
+ #@param value *
|
|
140
|
+ #@throw FieldValidationError if value is unappropriate or can not be cast
|
|
141
|
+ #@return value
|
119
|
142
|
def _check_data_value(self, value):
|
120
|
143
|
value = super()._check_data_value(value)
|
121
|
144
|
if not isinstance(value, str):
|