Commit 1a5d3920 authored by Pierre-Yves David's avatar Pierre-Yves David
Browse files

add Decimal type Support

parent 14346e160b4a
......@@ -4,6 +4,8 @@ ChangeLog for yams
--
* add attributs to dots view
* new Decimal Final
2008-05-08 -- 0.18.0
......
......@@ -21,7 +21,7 @@ __builtin__._ = unicode
from logilab.common.compat import set
BASE_TYPES = set(('String', 'Int', 'Float', 'Boolean', 'Date',
BASE_TYPES = set(('String', 'Int', 'Float', 'Boolean', 'Date', 'Decimal',
'Time', 'Datetime', 'Interval', 'Password', 'Bytes'))
from logilab.common import nullobject
......
......@@ -8,10 +8,13 @@
__docformat__ = "restructuredtext en"
from decimal import Decimal
import warnings
import re
from StringIO import StringIO
from yams.interfaces import IConstraint, IVocabularyConstraint
class BaseConstraint(object):
......@@ -268,6 +271,14 @@ def check_float(eschema, value):
except ValueError:
return False
return True
def check_decimal(eschema, value):
"""check value is a Decimal"""
try:
Decimal(value)
except ValueError:
return False
return True
def check_boolean(eschema, value):
"""check value is a boolean"""
......@@ -288,6 +299,7 @@ BASE_CHECKERS = {
'String' : check_string,
'Int' : check_int,
'Float' : check_float,
'Decimal' : check_decimal,
'Boolean' : check_boolean,
'Password' : check_password,
'Bytes' : check_file,
......@@ -297,4 +309,5 @@ BASE_CONVERTERS = {
'Int' : int,
'Float' : float,
'Boolean' : bool,
'Decimal' : Decimal,
}
......@@ -11,6 +11,7 @@ import warnings
from copy import deepcopy
from mx.DateTime import today, now, DateTimeFrom, DateFrom, TimeFrom
from decimal import Decimal
from logilab.common.decorators import cached
from logilab.common.compat import sorted
......@@ -438,6 +439,9 @@ class EntitySchema(ERSchema):
elif attrtype == 'Float':
if not isinstance(default, float):
default = float(default)
elif attrtype == 'Decimal':
if not isinstance(default, Decimal):
default = Decimal(default)
elif attrtype in ('Date', 'Datetime', 'Time'):
try:
default = KEYWORD_MAP[default.upper()]()
......
......@@ -72,10 +72,12 @@ class EsqlFileReader(FileReader):
int...)
"""
sqltype = sqltype.capitalize()
if sqltype in ('Integer', 'Numeric'):
if sqltype in ('Integer',):
return 'Int', [], 0
if sqltype == 'Float':
return 'Float', [], 0
if sqltype == ('Numeric', 'Decimal'):
return 'Decimal', [], 0
elif sqltype in ('Date', 'Time', 'Datetime', 'Boolean'):
return sqltype, [], 0
elif sqltype == 'Password':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment