@@ -36,81 +36,33 @@ class FileUpload(DescriptionWidget, ValueWidget, CoreWidget):
36
36
"""
37
37
_model_name = Unicode ('FileUploadModel' ).tag (sync = True )
38
38
_view_name = Unicode ('FileUploadView' ).tag (sync = True )
39
-
40
39
_counter = Int (0 ).tag (sync = True )
41
40
42
- help = 'Type of files the input accepts. None for all. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-accept'
43
- accept = Unicode (help = help ).tag (sync = True )
44
-
45
- help = 'If true, allow for multiple files upload, else only accept one'
46
- multiple = Bool (False , help = help ).tag (sync = True )
47
-
48
- help = 'Enable or disable button'
49
- disabled = Bool (False , help = help ).tag (sync = True )
50
-
51
- help = 'Optional style for button (label element)'
52
- style_button = Unicode ('' , help = help ).tag (sync = True )
53
-
54
- help = 'Compress level: from 1 to 9 - 0 for no compression'
55
- compress_level = Int (0 , help = help ).tag (sync = True )
56
-
57
- help = 'List of file metadata'
58
- li_metadata = List (Dict , help = help ).tag (sync = True )
59
-
60
- help = 'List of file content (bytes)'
61
- li_content = List (Bytes , help = help ).tag (sync = True , from_json = content_from_json )
62
-
63
- help = 'Error message'
64
- error = Unicode ('' , help = help ).tag (sync = True )
65
-
66
- value = Dict ({}).tag (sync = False )
41
+ accept = Unicode (help = 'File types to accept, empty string for all' ).tag (sync = True )
42
+ multiple = Bool (False , help = 'If True, allow for multiple file upload' ).tag (sync = True )
43
+ disabled = Bool (False , help = 'Enable or disable button' ).tag (sync = True )
44
+ compress_level = Int (help = 'Compression level: from 0 to 9 - 0 for no compression' ).tag (sync = True )
45
+ li_metadata = List (Dict , help = 'List of file metadata' ).tag (sync = True )
46
+ li_content = List (Bytes , help = 'List of file content (bytes)' ).tag (sync = True , from_json = content_from_json )
47
+ error = Unicode (help = 'Error message' ).tag (sync = True )
67
48
68
- def __init__ (self ,
69
- accept = '' ,
70
- multiple = False ,
71
- disabled = False ,
72
- style_button = '' ,
73
- compress_level = 0 ,
74
- ):
75
- """
76
- Instantiate widget
77
- """
78
-
79
- if accept is None :
80
- accept = ''
81
-
82
- if style_button is None :
83
- style_button = ''
84
-
85
- self ._counter = 0
86
- self .accept = accept
87
- self .disabled = disabled
88
- self .multiple = multiple
89
- self .style_button = style_button
90
- self .compress_level = compress_level
91
- self .value = {}
92
-
93
- super (FileUpload , self ).__init__ ()
49
+ value = Dict ()
94
50
95
51
@validate ('compress_level' )
96
52
def _valid_compress_level (self , proposal ):
97
- if proposal [ ' value' ] not in range (10 ):
53
+ if proposal . value not in range (10 ):
98
54
raise TraitError ('compress_level must be an int from 0 to 9 incl.' )
99
- return proposal [ ' value' ]
55
+ return proposal . value
100
56
101
57
@observe ('_counter' )
102
58
def on_incr_counter (self , change ):
103
59
"""
104
60
counter increment triggers the update of trait value
105
61
"""
106
62
res = {}
107
-
108
63
msg = 'Error: length of li_metadata and li_content must be equal'
109
64
assert len (self .li_metadata ) == len (self .li_content ), msg
110
-
111
- for metadata , content in zip (self .li_metadata ,
112
- self .li_content ):
65
+ for metadata , content in zip (self .li_metadata , self .li_content ):
113
66
name = metadata ['name' ]
114
67
res [name ] = {'metadata' : metadata , 'content' : content }
115
-
116
68
self .value = res
0 commit comments