Add support for float and integer on Property fields
issue4942 review18531002
This commit is contained in:
@@ -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
@@ -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,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:
|
||||
|
||||
Reference in New Issue
Block a user