From 4030d4cd488f79d3101384d57d975614c74ac313 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Sat, 11 Jan 2020 16:24:45 +0100 Subject: [PATCH] Consolidate FileUpload value by using a single dict --- docs/source/examples/Widget List.ipynb | 9 ++++++--- packages/controls/src/widget_upload.ts | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/source/examples/Widget List.ipynb b/docs/source/examples/Widget List.ipynb index f42d775d11..0cc8a5c00d 100644 --- a/docs/source/examples/Widget List.ipynb +++ b/docs/source/examples/Widget List.ipynb @@ -1015,7 +1015,10 @@ "uploader.value\n", "#=> [\n", "#=> {\n", - "#=> 'metadata': {'name': 'example.txt', 'type': 'text/plain', 'size': 36, 'lastModified': 1578647380733}, \n", + "#=> 'name': 'example.txt',\n", + "#=> 'type': 'text/plain',\n", + "#=> 'size': 36,\n", + "#=> 'lastModified': 1578647380733, \n", "#=> 'content': \n", "#=> }\n", "#=> ]\n", @@ -1061,9 +1064,9 @@ " \n", "The `FileUpload` changed significantly in ipywidgets 8:\n", " \n", - "- The `.value` traitlet is now a list of dictionaries with a `metadata` and `content` entry, rather than a dictionary mapping the uploaded name to the content. To retrieve the original form, use `{f[\"metadata\"][\"name\"]: f[\"content\"].tobytes() for f in uploader.value}`.\n", + "- The `.value` traitlet is now a list of dictionaries, rather than a dictionary mapping the uploaded name to the content. To retrieve the original form, use `{f[\"name\"]: f[\"content\"].tobytes() for f in uploader.value}`.\n", "- The `.data` traitlet has been removed. To retrieve it, use `[f[\"content\"].tobytes() for f in uploader.value]`.\n", - "- The `.metadata` traitlet has been removed. To retrieve it, use `[f[\"metadata\"]. for f in uploader.value]`.\n", + "- The `.metadata` traitlet has been removed. To retrieve it, use `[{k: v for k, v in f.items() if k != \"content\"} for f in w.value]`.\n", "" ] }, diff --git a/packages/controls/src/widget_upload.ts b/packages/controls/src/widget_upload.ts index 5691951cb6..18269d80af 100644 --- a/packages/controls/src/widget_upload.ts +++ b/packages/controls/src/widget_upload.ts @@ -96,7 +96,7 @@ export class FileUploadView extends DOMWidgetView { .then(contents => { const value = contents.map(c => { return { - metadata: c.metadata, + ...c.metadata, content: c.buffer }; });