Add support for float and integer on Property fields

issue4942
review18531002
This commit is contained in:
Cédric Krier
2015-09-14 10:37:38 +02:00
parent 8299e1c133
commit c18ec6ba74
3 changed files with 24 additions and 8 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add support for float and integer on Property fields
* Remove foreign-key on create_uid and write_uid
* Prevent deletion of any user
* Manage PostgreSQL schema
+15 -6
View File
@@ -10,6 +10,12 @@ __all__ = [
'Property',
]
_CAST = {
'numeric': Decimal,
'integer': int,
'float': float,
}
class Property(ModelSQL, ModelView):
"Property"
@@ -70,8 +76,9 @@ class Property(ModelSQL, ModelView):
if not isinstance(value, basestring):
val = int(value)
else:
if property_.field.ttype == 'numeric':
val = Decimal(value.split(',')[1])
if property_.field.ttype in _CAST:
cast = _CAST[property_.field.ttype]
val = cast(value.split(',')[1])
elif property_.field.ttype in ('char', 'selection'):
val = value.split(',')[1]
else:
@@ -92,8 +99,9 @@ class Property(ModelSQL, ModelView):
if not isinstance(property_.value, basestring):
val = int(property_.value)
else:
if property_.field.ttype == 'numeric':
val = Decimal(property_.value.split(',')[1])
if property_.field.ttype in _CAST:
cast = _CAST[property_.field.ttype]
val = cast(property_.value.split(',')[1])
elif property_.field.ttype in ('char', 'selection'):
val = property_.value.split(',')[1]
else:
@@ -149,8 +157,9 @@ class Property(ModelSQL, ModelView):
if not isinstance(value, basestring):
default_val = int(value)
else:
if field._type == 'numeric':
default_val = Decimal(value.split(',')[1])
if field._type in _CAST:
cast = _CAST[field._type]
default_val = cast(value.split(',')[1])
elif field._type in ('char', 'selection'):
default_val = value.split(',')[1]
else:
+8 -2
View File
@@ -8,6 +8,8 @@ from sql.functions import Substring, Position
from .function import Function
from .field import Field, SQL_OPERATORS
from .numeric import Numeric
from .integer import Integer
from .float import Float
from ...transaction import Transaction
from ...pool import Pool
@@ -142,8 +144,12 @@ class Property(Function):
operator = clause[1]
value = clause[2]
numeric = Numeric('numeric')
if sql_type == numeric.sql_type().base and value:
sql_types = [
Numeric('numeric').sql_type().base,
Integer('integer').sql_type().base,
Float('float').sql_type().base,
]
if sql_type in sql_types and value:
if isinstance(value, (list, tuple)):
value = [Cast(v, sql_type) for v in value]
else: