Skip to content

Commit 97cd0f1

Browse files
committed
Make FileUpload data and metadata private
1 parent 3fc2f14 commit 97cd0f1

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

ipywidgets/widgets/widget_upload.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class FileUpload(DescriptionWidget, ValueWidget, CoreWidget):
3434
_model_name = Unicode('FileUploadModel').tag(sync=True)
3535
_view_name = Unicode('FileUploadView').tag(sync=True)
3636
_counter = Int(read_only=True).tag(sync=True)
37+
_metadata = List(Dict(), read_only=True, help='List of file metadata').tag(sync=True)
38+
_data = List(Bytes(), read_only=True, help='List of file content (bytes)').tag(
39+
sync=True, from_json=content_from_json
40+
)
3741

3842
accept = Unicode(help='File types to accept, empty string for all').tag(sync=True)
3943
multiple = Bool(help='If True, allow for multiple files upload').tag(sync=True)
@@ -43,19 +47,15 @@ class FileUpload(DescriptionWidget, ValueWidget, CoreWidget):
4347
values=['primary', 'success', 'info', 'warning', 'danger', ''], default_value='',
4448
help="""Use a predefined styling for the button.""").tag(sync=True)
4549
style = InstanceDict(ButtonStyle).tag(sync=True, **widget_serialization)
46-
metadata = List(Dict(), read_only=True, help='List of file metadata').tag(sync=True)
47-
data = List(Bytes(), read_only=True, help='List of file content (bytes)').tag(
48-
sync=True, from_json=content_from_json
49-
)
5050
error = Unicode(help='Error message').tag(sync=True)
5151
value = Dict(read_only=True)
5252

5353
@observe('_counter')
5454
def on_incr_counter(self, change):
5555
res = {}
5656
msg = 'Error: length of metadata and data must be equal'
57-
assert len(self.metadata) == len(self.data), msg
58-
for metadata, content in zip(self.metadata, self.data):
57+
assert len(self._metadata) == len(self._data), msg
58+
for metadata, content in zip(self._metadata, self._data):
5959
name = metadata['name']
6060
res[name] = {'metadata': metadata, 'content': content}
6161
self.set_trait('value', res)

packages/controls/src/widget_upload.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ export class FileUploadModel extends CoreDOMWidgetModel {
1414

1515
_counter: 0,
1616
_file_count: 0,
17+
_data: [],
18+
_metadata: [],
1719
accept: '',
1820
description: 'Upload',
1921
tooltip: '',
2022
disabled: false,
2123
icon: 'upload',
2224
button_style: '',
2325
multiple: false,
24-
metadata: [],
25-
data: [],
2626
error: '',
2727
style: null
2828
});
2929
}
3030

3131
static serializers = {
3232
...CoreDOMWidgetModel.serializers,
33-
data: { serialize: (buffers: any) => { return [...buffers]; } },
33+
_data: { serialize: (buffers: any) => { return [...buffers]; } },
3434
};
3535
}
3636

@@ -107,8 +107,8 @@ export class FileUploadView extends DOMWidgetView {
107107
this.model.set({
108108
_counter: counter + contents.length,
109109
_file_count: contents.length,
110-
metadata,
111-
data: li_buffer,
110+
_metadata: metadata,
111+
_data: li_buffer,
112112
error: '',
113113
});
114114
this.touch();

packages/schema/jupyterwidgetmodels.latest.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ Attribute | Type | Default | Help
389389
Attribute | Type | Default | Help
390390
-----------------|------------------|------------------|----
391391
`_counter` | number (integer) | `0` |
392+
`_data` | array | `[]` | List of file content (bytes)
392393
`_dom_classes` | array of string | `[]` | CSS classes applied to widget DOM element
394+
`_metadata` | array | `[]` | List of file metadata
393395
`_model_module` | string | `'@jupyter-widgets/controls'` |
394396
`_model_module_version` | string | `'1.5.0'` |
395397
`_model_name` | string | `'FileUploadModel'` |
@@ -398,14 +400,12 @@ Attribute | Type | Default | Help
398400
`_view_name` | string | `'FileUploadView'` |
399401
`accept` | string | `''` | File types to accept, empty string for all
400402
`button_style` | string (one of `'primary'`, `'success'`, `'info'`, `'warning'`, `'danger'`, `''`) | `''` | Use a predefined styling for the button.
401-
`data` | array | `[]` | List of file content (bytes)
402403
`description` | string | `''` | Description of the control.
403404
`description_tooltip` | `null` or string | `null` | Tooltip for the description (defaults to description).
404405
`disabled` | boolean | `false` | Enable or disable button
405406
`error` | string | `''` | Error message
406407
`icon` | string | `'upload'` | Font-awesome icon name, without the 'fa-' prefix.
407408
`layout` | reference to Layout widget | reference to new instance |
408-
`metadata` | array | `[]` | List of file metadata
409409
`multiple` | boolean | `false` | If True, allow for multiple files upload
410410
`style` | reference to ButtonStyle widget | reference to new instance |
411411
`tabbable` | `null` or boolean | `null` | Is widget tabbable?

0 commit comments

Comments
 (0)