diff --git a/last_commit.txt b/last_commit.txt index 9ba546abae..ea6d7be1e0 100644 --- a/last_commit.txt +++ b/last_commit.txt @@ -1,10 +1,10 @@ -Repository: plone.formwidget.namedfile +Repository: plone.app.z3cform Branch: refs/heads/master -Date: 2024-03-15T12:23:27+01:00 +Date: 2024-03-14T21:25:17+01:00 Author: Johannes Raggam (thet) -Commit: https://github.com/plone/plone.formwidget.namedfile/commit/49d47c6453e5545d1a11f49cf48477a0cfa1f0ff +Commit: https://github.com/plone/plone.app.z3cform/commit/c52dd4ec423f06e851830687c8e446cc14387451 Add support for the "accept" attribute on file inputs. @@ -16,55 +16,185 @@ This would restrict the allowed file types before uploading while still being checked on the server side. Fixes: https://github.com/plone/plone.formwidget.namedfile/issues/66 -Depends on: https://github.com/plone/plone.namedfile/pull/158 -[thet] +Depends on: +- https://github.com/plone/plone.namedfile/pull/158 +- https://github.com/plone/plone.formwidget.namedfile/pull/67 Files changed: -A news/67.feature -M plone/formwidget/namedfile/file_input.pt -M plone/formwidget/namedfile/image_input.pt -M plone/formwidget/namedfile/widget.py -M plone/formwidget/namedfile/widget.rst +A news/198.feature +M plone/app/z3cform/templates/file_input.pt +M plone/app/z3cform/templates/image_input.pt M setup.py -b'diff --git a/news/67.feature b/news/67.feature\nnew file mode 100644\nindex 0000000..ecbdb3a\n--- /dev/null\n+++ b/news/67.feature\n@@ -0,0 +1,12 @@\n+Add support for the "accept" attribute on file inputs.\n+\n+If the widget\'s field - if there is one - has the "accept" attribute set (the\n+`NamedImage` field has `image/*` set by default) then this is rendered as an\n+`accept` attribute on the file input.\n+\n+This would restrict the allowed file types before uploading while still being\n+checked on the server side.\n+\n+Fixes: https://github.com/plone/plone.formwidget.namedfile/issues/66\n+Depends on: https://github.com/plone/plone.namedfile/pull/158\n+[thet]\ndiff --git a/plone/formwidget/namedfile/file_input.pt b/plone/formwidget/namedfile/file_input.pt\nindex fb3bc0f..6bfb891 100644\n--- a/plone/formwidget/namedfile/file_input.pt\n+++ b/plone/formwidget/namedfile/file_input.pt\n@@ -130,7 +130,8 @@\n
\n- \n- >> image_widget.extract()\n \n \n-The rendering is unchanged:\n+The rendering is unchanged::\n \n >>> print(file_widget.render())\n \n@@ -284,7 +284,7 @@ At first, there is no value, so the behaviour is much like before::\n >>> image_widget.update()\n >>> print(image_widget.render())\n \n- \n+ \n \n \n However, if we now set a value, we will have the option of keeping it,\n@@ -388,6 +388,67 @@ stored in the field::\n True\n \n \n+Rendering field widgets with constraints on allowed media types\n+-----------------------------------------------------------------\n+\n+The NamedImage already has a constraint on `image/*` mime types for files and\n+this is also rendered for the input element. See above.\n+You can also customize the allowed media types with the `accept` attribute,\n+like shown here::\n+\n+ >>> class IContentConstrained(Interface):\n+ ... file_field = field.NamedFile(\n+ ... title=u"File",\n+ ... accept=("audio/mp3", "audio/flac", ".wav")\n+ ... )\n+ ... image_field = field.NamedImage(\n+ ... title=u"Image",\n+ ... accept=("image/webp", "image/png", ".jpg")\n+ ... )\n+\n+ >>> @implementer(IContentConstrained, IImageScaleTraversable, IAttributeAnnotatable)\n+ ... class ContentConstrained(object):\n+ ... def __init__(self, file, image):\n+ ... self.file_field = file\n+ ... self.image_field = image\n+ ... self._p_mtime = DateTime()\n+ ... self.path = \'/content_constrained\'\n+ ...\n+ ... def absolute_url(self):\n+ ... return root_url + self.path\n+ ...\n+ ... def Title(self):\n+ ... return \'A content item\'\n+\n+ >>> content_constrained = ContentConstrained(None, None)\n+\n+ >>> file_widget_constrained = NamedFileFieldWidget(IContentConstrained[\'file_field\'], make_request())\n+ >>> image_widget_constrained = NamedImageFieldWidget(IContentConstrained[\'image_field\'], make_request())\n+\n+ >>> file_widget_constrained.context = content_constrained\n+ >>> image_widget_constrained.context = content_constrained\n+\n+ >>> file_widget_constrained.id = \'widget.id.file\'\n+ >>> file_widget_constrained.name = \'widget.name.file\'\n+\n+ >>> image_widget_constrained.id = \'widget.id.image\'\n+ >>> image_widget_constrained.name = \'widget.name.image\'\n+\n+At first, there is no value, so the behaviour is much like before::\n+\n+ >>> file_widget_constrained.update()\n+ >>> print(file_widget_constrained.render())\n+ \n+ \n+ \n+\n+ >>> image_widget_constrained.update()\n+ >>> print(image_widget_constrained.render())\n+ \n+ \n+ \n+\n+\n Download view\n -------------\n \ndiff --git a/setup.py b/setup.py\nindex 6d5435d..d3a49bd 100644\n--- a/setup.py\n+++ b/setup.py\n@@ -35,7 +35,7 @@\n "BTrees",\n "setuptools",\n "plone.base",\n- "plone.namedfile",\n+ "plone.namedfile>=6.3.0",\n "Products.MimetypesRegistry",\n "persistent",\n "plone.registry",\n' +b'diff --git a/news/198.feature b/news/198.feature\nnew file mode 100644\nindex 00000000..1d722dc4\n--- /dev/null\n+++ b/news/198.feature\n@@ -0,0 +1,14 @@\n+Add support for the "accept" attribute on file inputs.\n+\n+If the widget\'s field - if there is one - has the "accept" attribute set (the\n+`NamedImage` field has `image/*` set by default) then this is rendered as an\n+`accept` attribute on the file input.\n+\n+This would restrict the allowed file types before uploading while still being\n+checked on the server side.\n+\n+Fixes: https://github.com/plone/plone.formwidget.namedfile/issues/66\n+Depends on:\n+- https://github.com/plone/plone.namedfile/pull/158\n+- https://github.com/plone/plone.formwidget.namedfile/pull/67\n+[thet]\ndiff --git a/plone/app/z3cform/templates/file_input.pt b/plone/app/z3cform/templates/file_input.pt\nindex 14bd91a5..5df43142 100644\n--- a/plone/app/z3cform/templates/file_input.pt\n+++ b/plone/app/z3cform/templates/file_input.pt\n@@ -90,6 +90,7 @@\n \n =1.3.6",\n "plone.base",\n "plone.app.contentlisting",\n+ "plone.formwidget.namedfile>3.0.3",\n "plone.i18n",\n "plone.protect",\n "plone.registry",\n' -Repository: plone.formwidget.namedfile +Repository: plone.app.z3cform Branch: refs/heads/master -Date: 2024-03-15T12:23:27+01:00 +Date: 2024-03-14T23:02:39+01:00 Author: Johannes Raggam (thet) -Commit: https://github.com/plone/plone.formwidget.namedfile/commit/57815fea54f1e96bff16d9d258ee208acb4ec37c +Commit: https://github.com/plone/plone.app.z3cform/commit/c6e1d78a2ee4b27f0bc3dea87873122511ca31ed file input: Show accepted media types. Files changed: -M plone/formwidget/namedfile/file_input.pt -M plone/formwidget/namedfile/image_input.pt -M plone/formwidget/namedfile/widget.rst +M plone/app/z3cform/templates/file_input.pt +M plone/app/z3cform/templates/image_input.pt -b'diff --git a/plone/formwidget/namedfile/file_input.pt b/plone/formwidget/namedfile/file_input.pt\nindex 6bfb891..fc07c2c 100644\n--- a/plone/formwidget/namedfile/file_input.pt\n+++ b/plone/formwidget/namedfile/file_input.pt\n@@ -140,6 +140,14 @@\n maxlength view/maxlength;\n "\n />\n+
\n+ Allowed types:\n+ ${view/accept}.\n+
\n+\n