Skip to content

Commit 250fd81

Browse files
committed
Make FileUpload data and metadata private
1 parent dab72aa commit 250fd81

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
@@ -35,6 +35,10 @@ class FileUpload(DescriptionWidget, ValueWidget, CoreWidget):
3535
_view_name = Unicode('FileUploadView').tag(sync=True)
3636
_counter = Int(read_only=True).tag(sync=True)
3737
_file_count = Int().tag(sync=True)
38+
_metadata = List(Dict(), read_only=True, help='List of file metadata').tag(sync=True)
39+
_data = List(Bytes(), read_only=True, help='List of file content (bytes)').tag(
40+
sync=True, from_json=content_from_json
41+
)
3842

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

5454
@observe('_counter')
5555
def on_incr_counter(self, change):
5656
res = {}
5757
msg = 'Error: length of metadata and data must be equal'
58-
assert len(self.metadata) == len(self.data), msg
59-
for metadata, content in zip(self.metadata, self.data):
58+
assert len(self._metadata) == len(self._data), msg
59+
for metadata, content in zip(self._metadata, self._data):
6060
name = metadata['name']
6161
res[name] = {'metadata': metadata, 'content': content}
6262
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
@@ -374,8 +374,10 @@ Attribute | Type | Default | Help
374374
Attribute | Type | Default | Help
375375
-----------------|------------------|------------------|----
376376
`_counter` | number (integer) | `0` |
377+
`_data` | array | `[]` | List of file content (bytes)
377378
`_dom_classes` | array of string | `[]` | CSS classes applied to widget DOM element
378379
`_file_count` | number (integer) | `0` |
380+
`_metadata` | array | `[]` | List of file metadata
379381
`_model_module` | string | `'@jupyter-widgets/controls'` |
380382
`_model_module_version` | string | `'1.5.0'` |
381383
`_model_name` | string | `'FileUploadModel'` |
@@ -384,14 +386,12 @@ Attribute | Type | Default | Help
384386
`_view_name` | string | `'FileUploadView'` |
385387
`accept` | string | `''` | File types to accept, empty string for all
386388
`button_style` | string (one of `'primary'`, `'success'`, `'info'`, `'warning'`, `'danger'`, `''`) | `''` | Use a predefined styling for the button.
387-
`data` | array | `[]` | List of file content (bytes)
388389
`description` | string | `''` | Description of the control.
389390
`description_tooltip` | `null` or string | `null` | Tooltip for the description (defaults to description).
390391
`disabled` | boolean | `false` | Enable or disable button
391392
`error` | string | `''` | Error message
392393
`icon` | string | `'upload'` | Font-awesome icon name, without the 'fa-' prefix.
393394
`layout` | reference to Layout widget | reference to new instance |
394-
`metadata` | array | `[]` | List of file metadata
395395
`multiple` | boolean | `false` | If True, allow for multiple files upload
396396
`style` | reference to ButtonStyle widget | reference to new instance |
397397

0 commit comments

Comments
 (0)