Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
TYPES_TO_FIELDS = {
'binary': Binary,
'boolean': Boolean,
'char': Char,
'date': Date,
'datetime': Datetime,
'float': Float,
'html': Html,
'integer': Integer,
'many2many': Many2many,
'many2one': Many2one,
'one2many': One2many,
'reference': Reference,
'selection': Selection,
'text': Text,
}
def generate_field(name, data):
"""Generate a well-typed field according to the data dictionary supplied
(obtained via the `fields_get' method of any models).
"""
assert 'type' in data
field = TYPES_TO_FIELDS.get(data['type'], Unknown)(name, data)
return field
def __get__(self, instance, owner):
value = instance._values[self.name].get(instance.id)
if instance.id in instance._values_to_write[self.name]:
value = instance._values_to_write[self.name][instance.id]
return value
def __set__(self, instance, value):
if value is None:
value = False
value = self.check_value(value)
instance._values_to_write[self.name][instance.id] = value
super(Text, self).__set__(instance, value)
class Html(Text):
"""Equivalent of the `fields.Html` class."""
def __init__(self, name, data):
super(Html, self).__init__(name, data)
class Unknown(BaseField):
"""Represent an unknown field. This should not happen but this kind of
field only exists to avoid a blocking situation from a RPC point of view.
"""
def __init__(self, name, data):
super(Unknown, self).__init__(name, data)
def __get__(self, instance, owner):
value = instance._values[self.name][instance.id]
TYPES_TO_FIELDS = {
'binary': Binary,
'boolean': Boolean,
'char': Char,
'date': Date,
'datetime': Datetime,
'float': Float,
'html': Html,
'integer': Integer,
'many2many': Many2many,
'many2one': Many2one,
'one2many': One2many,
'reference': Reference,
'selection': Selection,
'text': Text,
}
def generate_field(name, data):
"""Generate a well-typed field according to the data dictionary supplied
(obtained via the `fields_get' method of any models).
"""
assert 'type' in data
field = TYPES_TO_FIELDS.get(data['type'], Unknown)(name, data)
return field
def __set__(self, instance, value):
if value is None:
value = False
value = self.check_value(value)
instance._values_to_write[self.name][instance.id] = value
super(Text, self).__set__(instance, value)
def __init__(self, name, data):
super(Text, self).__init__(name, data)
def __get__(self, instance, owner):
value = instance._values[self.name].get(instance.id)
if instance.id in instance._values_to_write[self.name]:
value = instance._values_to_write[self.name][instance.id]
return value
def __set__(self, instance, value):
if value is None:
value = False
value = self.check_value(value)
instance._values_to_write[self.name][instance.id] = value
super(Text, self).__set__(instance, value)
class Html(Text):
"""Equivalent of the `fields.Html` class."""
def __init__(self, name, data):
super(Html, self).__init__(name, data)
class Unknown(BaseField):
"""Represent an unknown field. This should not happen but this kind of
field only exists to avoid a blocking situation from a RPC point of view.
"""
def __init__(self, name, data):
super(Unknown, self).__init__(name, data)
def __get__(self, instance, owner):
value = instance._values[self.name][instance.id]
if instance.id in instance._values_to_write[self.name]:
value = instance._values_to_write[self.name][instance.id]