Commit 20d96098 authored by Alexandre Boeglin's avatar Alexandre Boeglin

- use isinstance() instead of type() == type()

- if type is object, do not check, as it can be anything


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10853 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 74d444b0
...@@ -32,9 +32,9 @@ from Constraint import Constraint ...@@ -32,9 +32,9 @@ from Constraint import Constraint
from DateTime import DateTime from DateTime import DateTime
try: try:
boolean_types = (type(1), type(True)) boolean_types = (int, bool)
except NameError: except NameError:
boolean_types = (type(1), ) boolean_types = (int, )
class PropertyTypeValidity(Constraint): class PropertyTypeValidity(Constraint):
""" """
...@@ -45,21 +45,23 @@ class PropertyTypeValidity(Constraint): ...@@ -45,21 +45,23 @@ class PropertyTypeValidity(Constraint):
# Initialize type dict # Initialize type dict
_type_dict = { _type_dict = {
'object': (type('a'), ), 'string': (str, ),
'string': (type('a'), ), 'text': (str, ),
'text': (type('a'), ), 'int': (int, ),
'int': (type(1), ),
'boolean': boolean_types, 'boolean': boolean_types,
'float': (type(1.0), ), 'float': (float, ),
'long': (type(1L), ), 'long': (long, ),
'tales': (type('string:3'), ), 'tales': (str, ),
'lines': (type([]), type(())), 'lines': (list, tuple),
'tokens': (type([]), type(())), 'tokens': (list, tuple),
'selection': (type([]), type(())), 'selection': (list, tuple),
'multiple selection': (type([]), type(())), 'multiple selection': (list, tuple),
'date': (type(DateTime()), ), 'date': (DateTime, ),
} }
# Properties of type eg. "object" can hold anything
_permissive_type_list = ('object')
def checkConsistency(self, obj, fixit=0): def checkConsistency(self, obj, fixit=0):
""" """
This is the check method, we return a list of string, This is the check method, we return a list of string,
...@@ -73,6 +75,8 @@ class PropertyTypeValidity(Constraint): ...@@ -73,6 +75,8 @@ class PropertyTypeValidity(Constraint):
property_type = 'lines' property_type = 'lines'
else: else:
property_type = prop['type'] property_type = prop['type']
if property_type in self._permissive_type_list:
continue
wrong_type = 0 wrong_type = 0
if property_type == 'tales': if property_type == 'tales':
value = obj.getProperty(property_id, evaluate=0) value = obj.getProperty(property_id, evaluate=0)
...@@ -81,7 +85,7 @@ class PropertyTypeValidity(Constraint): ...@@ -81,7 +85,7 @@ class PropertyTypeValidity(Constraint):
if value is not None: if value is not None:
# Check known type # Check known type
try: try:
wrong_type = (type(value) not in self._type_dict[property_type]) wrong_type = not isinstance(value, self._type_dict[property_type])
except KeyError: except KeyError:
wrong_type = 0 wrong_type = 0
error_message = "Attribute %s is defined with unknown type %s" % \ error_message = "Attribute %s is defined with unknown type %s" % \
......
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