@@ -32,24 +32,52 @@ def get_input_model_from_fields(name: str, input_fields: list) -> Type['BaseMode
32
32
'list' : list ,
33
33
'file' : str ,
34
34
'image' : str ,
35
- 'text' : str
35
+ 'text' : str ,
36
+ 'richtext' : str ,
37
+ 'datasource' : str ,
38
+ 'color' : str ,
39
+ 'voice' : str ,
36
40
}
37
41
38
42
fields = {}
39
43
for field in input_fields :
40
- datatype = datatype_map [ field ['type' ]
41
- ] if 'type' in field and field [ 'type' ] in datatype_map else str
44
+ field_type = field ['type' ] if 'type' in field else 'string'
45
+ datatype = datatype_map [ field_type ] if field_type in datatype_map else str
42
46
43
- if 'type' in field and field [ 'type' ] == 'file' :
47
+ if field_type == 'file' :
44
48
field ['widget' ] = 'file'
45
49
field ['format' ] = 'data-url'
46
50
field ['pattern' ] = "data:(.*);name=(.*);base64,(.*)"
47
- elif 'type' in field and field [ 'type' ] == 'image' :
51
+ elif field_type == 'image' :
48
52
field ['widget' ] = 'file'
49
53
field ['format' ] = 'data-url'
50
54
field ['pattern' ] = "data:(.*);name=(.*);base64,(.*)"
51
- elif 'type' in field and field [ 'type' ] == 'text' :
55
+ elif field_type == 'text' :
52
56
field ['widget' ] = 'textarea'
57
+ elif field_type == 'richtext' :
58
+ field ['widget' ] = 'richtext'
59
+ elif field_type == 'datasource' :
60
+ field ['widget' ] = 'datasource'
61
+ if 'default' not in field :
62
+ field ['default' ] = []
63
+ elif field_type == 'color' :
64
+ field ['widget' ] = 'color'
65
+ elif field_type == 'voice' :
66
+ field ['widget' ] = 'voice'
67
+ field ['format' ] = 'data-url'
68
+ field ['pattern' ] = "data:(.*);name=(.*);base64,(.*)"
69
+
70
+ if field_type == 'select' and 'options' in field and len (field ['options' ]) > 0 :
71
+ field ['enumNames' ] = [option ['label' ]
72
+ or '' for option in field ['options' ]]
73
+ field ['enum' ] = [option ['value' ]
74
+ or None for option in field ['options' ]]
75
+ field ['widget' ] = 'select'
76
+
77
+ # For select fields, the datatype is the type of the first option
78
+ datatype = type (field ['options' ][0 ]['value' ])
79
+
80
+ field .pop ('options' , None )
53
81
54
82
fields [field ['name' ]] = (datatype , Field (
55
83
** {k : field [k ] for k in field }))
0 commit comments