mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 13:52:15 +01:00
implemented some convertion methods
This commit is contained in:
parent
68d20b910e
commit
eec4119177
3 changed files with 25 additions and 1 deletions
|
|
@ -46,6 +46,12 @@ class EnumEntity(InputEntity):
|
|||
|
||||
super(EnumEntity, self).schema_validations()
|
||||
|
||||
def _convert_to_valid_type(self, value):
|
||||
if self.multiselection:
|
||||
if isinstance(value, (set, tuple)):
|
||||
return list(value)
|
||||
return NOT_SET
|
||||
|
||||
def set(self, value):
|
||||
if self.multiselection:
|
||||
if not isinstance(value, list):
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ class NumberEntity(InputEntity):
|
|||
self.decimal = self.schema_data.get("decimal", 0)
|
||||
|
||||
if self.decimal:
|
||||
valid_value_types = (int, float)
|
||||
valid_value_types = (float, )
|
||||
else:
|
||||
valid_value_types = (int, )
|
||||
self.valid_value_types = valid_value_types
|
||||
|
|
@ -340,6 +340,19 @@ class NumberEntity(InputEntity):
|
|||
# TODO check number for floats, integers and point
|
||||
self._validate_value_type(value)
|
||||
super(NumberEntity, self).set(value)
|
||||
def _convert_to_valid_type(self, value):
|
||||
if self.decimal:
|
||||
if isinstance(value, int):
|
||||
return float(value)
|
||||
else:
|
||||
if isinstance(value, float):
|
||||
new_value = int(value)
|
||||
if new_value != value:
|
||||
self.log.info("Converted float {} to int {}".format(
|
||||
value, new_value
|
||||
))
|
||||
return new_value
|
||||
return NOT_SET
|
||||
|
||||
|
||||
class BoolEntity(InputEntity):
|
||||
|
|
|
|||
|
|
@ -126,6 +126,11 @@ class ListEntity(EndpointEntity):
|
|||
)
|
||||
self.on_change()
|
||||
|
||||
def _convert_to_valid_type(self, value):
|
||||
if isinstance(value, (set, tuple)):
|
||||
return list(value)
|
||||
return NOT_SET
|
||||
|
||||
def _item_initalization(self):
|
||||
self.valid_value_types = (list, )
|
||||
self.children = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue