From 7f1ae0c5a95cbf7be02a394cf3b202e643c7096a Mon Sep 17 00:00:00 2001 From: Thijs Damsma Date: Sun, 25 Oct 2020 16:47:45 +0100 Subject: [PATCH 01/16] support configuring resources without registry --- deform/field.py | 30 +++++++++++++++++++++++------- deform/widget.py | 6 ++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/deform/field.py b/deform/field.py index 9ddb1ba1..8a00f81f 100644 --- a/deform/field.py +++ b/deform/field.py @@ -451,14 +451,20 @@ def get_widget_requirements(self): requirements = self.widget.requirements if requirements: for requirement in requirements: - reqt = tuple(requirement) - if reqt not in L: - L.append(reqt) + if isinstance(requirement, dict): + L.append(requirement) + else: + reqt = tuple(requirement) + if reqt not in L: + L.append(reqt) for child in self.children: for requirement in child.get_widget_requirements(): - reqt = tuple(requirement) - if reqt not in L: - L.append(reqt) + if isinstance(requirement, dict): + L.append(requirement) + else: + reqt = tuple(requirement) + if reqt not in L: + L.append(reqt) return L def get_widget_resources(self, requirements=None): @@ -485,7 +491,17 @@ def get_widget_resources(self, requirements=None): """ if requirements is None: requirements = self.get_widget_requirements() - return self.resource_registry(requirements) + resources = self.resource_registry( + (req for req in requirements if not isinstance(req, dict)) + ) + for req in requirements: + if not isinstance(req, dict): + continue + if 'js' in req: + resources['js'].append(req['js']) + if 'css' in req: + resources['css'].append(req['css']) + return resources def set_widgets(self, values, separator="."): """set widgets of the child fields of this field diff --git a/deform/widget.py b/deform/widget.py index 6cbbb98b..44cc3ca6 100644 --- a/deform/widget.py +++ b/deform/widget.py @@ -141,6 +141,12 @@ class Widget(object): be added to the input tag. requirements + + The requirements are specified as a a sequence of either: + 1. two-tuples in the form ``(requirement_name, version_id)``. Using the + resource registry the **logical** requirement name identifiers are resolved + to concrete files using the resource_registry + 2. dicts that contcretly point to resources, e.g. ``{"js": "deform:static/tinymce/tinymce.min.js"}`` A sequence of two-tuples in the form ``( (requirement_name, version_id), ...)`` indicating the logical external requirements needed to make this widget render properly within From 444b4a5d559b62c334f8d8350493f2f198a10b74 Mon Sep 17 00:00:00 2001 From: Thijs Damsma Date: Sun, 25 Oct 2020 16:48:56 +0100 Subject: [PATCH 02/16] remove select2, tinymce and sortable from registry --- deform/widget.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/deform/widget.py b/deform/widget.py index 44cc3ca6..b5788f14 100644 --- a/deform/widget.py +++ b/deform/widget.py @@ -849,7 +849,7 @@ class RichTextWidget(TextInputWidget): delayed_load = False strip = True template = "richtext" - requirements = (("tinymce", None),) + requirements = ({"js": "deform:static/tinymce/tinymce.min.js"},) #: Default options passed to TinyMCE. Customise by using :attr:`options`. default_options = ( @@ -1170,7 +1170,13 @@ class Select2Widget(SelectWidget): """ template = "select2" - requirements = (("deform", None), ("select2", None)) + requirements = ( + ("deform", None), + { + "js": "deform:static/select2/select2.js", + "css": "deform:static/select2/select2.css", + }, + ) class RadioChoiceWidget(SelectWidget): @@ -1568,7 +1574,10 @@ class SequenceWidget(Widget): min_len = None max_len = None orderable = False - requirements = (("deform", None), ("sortable", None)) + requirements = ( + ("deform", None), + {"js": "deform:static/scripts/jquery-sortable.js"}, + ) def prototype(self, field): # we clone the item field to bump the oid (for easier @@ -1728,7 +1737,7 @@ class FileUploadWidget(Widget): readonly_template = "readonly/file_upload" accept = None - requirements = (("fileupload", None),) + requirements = ({"js": "deform:static/scripts/file_upload.js"},) _pstruct_schema = SchemaNode( Mapping(), @@ -2146,8 +2155,6 @@ def __call__(self, requirements): ) } }, - "tinymce": {None: {"js": "deform:static/tinymce/tinymce.min.js"}}, - "sortable": {None: {"js": "deform:static/scripts/jquery-sortable.js"}}, "typeahead": { None: { "js": "deform:static/scripts/typeahead.min.js", @@ -2174,12 +2181,6 @@ def __call__(self, requirements): ), } }, - "select2": { - None: { - "js": "deform:static/select2/select2.js", - "css": "deform:static/select2/select2.css", - } - }, "fileupload": {None: {"js": "deform:static/scripts/file_upload.js"}}, } From 6c91a892b11d790dffc0d0f7ce652b35eef36bc3 Mon Sep 17 00:00:00 2001 From: Thijs Damsma Date: Sat, 31 Oct 2020 21:32:39 +0100 Subject: [PATCH 03/16] fix test --- deform/tests/test_field.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deform/tests/test_field.py b/deform/tests/test_field.py index 255afb10..82cf9840 100644 --- a/deform/tests/test_field.py +++ b/deform/tests/test_field.py @@ -348,7 +348,7 @@ def test_get_widget_requirements(self): def test_get_widget_resources(self): def resource_registry(requirements): - self.assertEqual(requirements, [("abc", "123")]) + self.assertEqual(list(requirements), [("abc", "123")]) return "OK" schema = DummySchema() From 1f30925f1481c80a2d6a24d84c2afa25d193ec5c Mon Sep 17 00:00:00 2001 From: Thijs Damsma Date: Mon, 2 Nov 2020 10:37:40 +0100 Subject: [PATCH 04/16] add test test_get_widget_resources_without_registry --- deform/tests/test_field.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/deform/tests/test_field.py b/deform/tests/test_field.py index 82cf9840..53a9f806 100644 --- a/deform/tests/test_field.py +++ b/deform/tests/test_field.py @@ -346,7 +346,7 @@ def test_get_widget_requirements(self): result, [("abc", "123"), ("ghi", "789"), ("def", "456")] ) - def test_get_widget_resources(self): + def test_get_widget_resources_with_registry(self): def resource_registry(requirements): self.assertEqual(list(requirements), [("abc", "123")]) return "OK" @@ -358,6 +358,13 @@ def resource_registry(requirements): result = field.get_widget_resources() self.assertEqual(result, "OK") + def test_get_widget_resources_without_registry(self): + schema = DummySchema() + field = self._makeOne(schema) + field.widget.requirements = ({"js": "123.js"},) + result = field.get_widget_resources() + self.assertEqual(result['js'], ['123.js']) + def test_clone(self): schema = DummySchema() field = self._makeOne(schema, renderer="abc") From a128dd1d54cdff96d374def3c0ab56a3d8ba64be Mon Sep 17 00:00:00 2001 From: Thijs Damsma Date: Mon, 2 Nov 2020 11:25:03 +0100 Subject: [PATCH 05/16] improve test coverage an refine implementation --- deform/field.py | 10 ++++++---- deform/tests/test_field.py | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/deform/field.py b/deform/field.py index 8a00f81f..b62d686f 100644 --- a/deform/field.py +++ b/deform/field.py @@ -497,10 +497,12 @@ def get_widget_resources(self, requirements=None): for req in requirements: if not isinstance(req, dict): continue - if 'js' in req: - resources['js'].append(req['js']) - if 'css' in req: - resources['css'].append(req['css']) + for key in {'js', 'css'}.intersection(req): + value = req[key] + if isinstance(value, str): + resources[key].append(value) + else: + resources[key].extend(value) return resources def set_widgets(self, values, separator="."): diff --git a/deform/tests/test_field.py b/deform/tests/test_field.py index 53a9f806..1bcc93c6 100644 --- a/deform/tests/test_field.py +++ b/deform/tests/test_field.py @@ -361,9 +361,13 @@ def resource_registry(requirements): def test_get_widget_resources_without_registry(self): schema = DummySchema() field = self._makeOne(schema) - field.widget.requirements = ({"js": "123.js"},) + field.widget.requirements = ( + {"js": "123.js", "css": ["123.css"]}, + {"css": ["1.css", "2.css"]}, + ) result = field.get_widget_resources() self.assertEqual(result['js'], ['123.js']) + self.assertEqual(result['css'], ["123.css", "1.css", "2.css"]) def test_clone(self): schema = DummySchema() From 51b5418c4a78b035f1b95711cf82edbb2bb50dbb Mon Sep 17 00:00:00 2001 From: Thijs Damsma Date: Mon, 2 Nov 2020 13:52:56 +0100 Subject: [PATCH 06/16] Update deform/widget.py Co-authored-by: Steve Piercy --- deform/widget.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deform/widget.py b/deform/widget.py index b5788f14..3995391a 100644 --- a/deform/widget.py +++ b/deform/widget.py @@ -142,7 +142,8 @@ class Widget(object): requirements - The requirements are specified as a a sequence of either: + The requirements are specified as a sequence of either of the + following. 1. two-tuples in the form ``(requirement_name, version_id)``. Using the resource registry the **logical** requirement name identifiers are resolved to concrete files using the resource_registry From 6f3e6b396af9b3dc8e8b94d18043900bf1e3f6fb Mon Sep 17 00:00:00 2001 From: Thijs Damsma Date: Mon, 2 Nov 2020 14:11:53 +0100 Subject: [PATCH 07/16] more docs --- deform/widget.py | 18 +++++++++++++----- docs/widget.rst | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/deform/widget.py b/deform/widget.py index 3995391a..de81a0dd 100644 --- a/deform/widget.py +++ b/deform/widget.py @@ -144,11 +144,15 @@ class Widget(object): The requirements are specified as a sequence of either of the following. - 1. two-tuples in the form ``(requirement_name, version_id)``. Using the - resource registry the **logical** requirement name identifiers are resolved - to concrete files using the resource_registry - 2. dicts that contcretly point to resources, e.g. ``{"js": "deform:static/tinymce/tinymce.min.js"}`` - A sequence of two-tuples in the form ``( (requirement_name, + + 1. Two-tuples in the form ``(requirement_name, version_id)``. + Using the resource registry the **logical** requirement name + identifiers are resolved to concrete files using the + ``resource_registry``. + 2. Dicts that concretely point to resources such as ``{"js": + "deform:static/tinymce/tinymce.min.js"}``. + + A sequence of two-tuples should be in the form ``( (requirement_name, version_id), ...)`` indicating the logical external requirements needed to make this widget render properly within a form. The ``requirement_name`` is a string that *logically* @@ -164,6 +168,10 @@ class Widget(object): :ref:`specifying_widget_requirements` and :ref:`widget_requirements`. + If concrete resources are supplied as dicts, both ``js``and ``css`` + keys are accepted. Furthermore the value can be supplied as a string or + a list of strings. + Default: ``()`` (the empty tuple, meaning no special requirements). diff --git a/docs/widget.rst b/docs/widget.rst index 8dcd38ee..3f796eef 100644 --- a/docs/widget.rst +++ b/docs/widget.rst @@ -283,6 +283,25 @@ constructing the form. The default resource registry (:attr:`deform.widget.resource_registry`) does not contain resource mappings for your newly-created requirement. +If the required resources are tightly couopled to the new widget, it may +be easier to supply the direct links to the logical requirements in the form: + +.. code-block:: python + :linenos: + + from deform.widget import Widget + + class MyWidget(Widget): + requirements = ( { + 'js': ''my:static/path/to/jquery.js', + 'css': [ + 'my:static/path/to/jquery.css', + 'my:static:path/to/bootstrap.css'], + } ) + +The supplied paths sre resolved by ``request.get_path()`` so the requried +static resources should be included in the pyramid config. + .. _writing_a_widget: Writing Your Own Widget From 5bdef4e6d9bb8a9e0bf47dcae78e617e2f78ff43 Mon Sep 17 00:00:00 2001 From: Thijs Damsma Date: Mon, 2 Nov 2020 14:49:56 +0100 Subject: [PATCH 08/16] refactor child requirements loading --- deform/field.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/deform/field.py b/deform/field.py index b62d686f..3f39c77a 100644 --- a/deform/field.py +++ b/deform/field.py @@ -449,6 +449,9 @@ def get_widget_requirements(self): """ L = [] requirements = self.widget.requirements + for child in self.children: + requirements += child.get_widget_requirements() + if requirements: for requirement in requirements: if isinstance(requirement, dict): @@ -457,14 +460,6 @@ def get_widget_requirements(self): reqt = tuple(requirement) if reqt not in L: L.append(reqt) - for child in self.children: - for requirement in child.get_widget_requirements(): - if isinstance(requirement, dict): - L.append(requirement) - else: - reqt = tuple(requirement) - if reqt not in L: - L.append(reqt) return L def get_widget_resources(self, requirements=None): From 0c588e619736a016a75c04520bdd8181a4a8ebf3 Mon Sep 17 00:00:00 2001 From: Thijs Damsma Date: Tue, 3 Nov 2020 13:31:42 +0100 Subject: [PATCH 09/16] fix regression in requirements collection --- deform/field.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/deform/field.py b/deform/field.py index 3f39c77a..bf916f2a 100644 --- a/deform/field.py +++ b/deform/field.py @@ -448,9 +448,13 @@ def get_widget_requirements(self): requirements in :ref:`get_widget_requirements`. """ L = [] - requirements = self.widget.requirements - for child in self.children: - requirements += child.get_widget_requirements() + + requirements = [ + *self.widget.requirements, + *itertools.chain( + *(child.get_widget_requirements() for child in self.children) + ), + ] if requirements: for requirement in requirements: From c77522fc4d1d8681379b1fb8288e7363a6d4839d Mon Sep 17 00:00:00 2001 From: Thijs Damsma Date: Tue, 3 Nov 2020 13:46:43 +0100 Subject: [PATCH 10/16] also think of older python versions --- deform/field.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/deform/field.py b/deform/field.py index bf916f2a..3758bd8d 100644 --- a/deform/field.py +++ b/deform/field.py @@ -449,11 +449,10 @@ def get_widget_requirements(self): """ L = [] - requirements = [ - *self.widget.requirements, - *itertools.chain( - *(child.get_widget_requirements() for child in self.children) - ), + requirements = [req for req in self.widget.requirements] + [ + req + for child in self.children + for req in child.get_widget_requirements() ] if requirements: From 2ad4f952543490571d5a564f61ef759f3bdcdad2 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Thu, 5 Nov 2020 03:44:08 -0800 Subject: [PATCH 11/16] Improve docstrings and add narrative docs --- deform/widget.py | 34 ++++++++++++++----------- docs/widget.rst | 64 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 68 insertions(+), 30 deletions(-) diff --git a/deform/widget.py b/deform/widget.py index de81a0dd..e7fb35e0 100644 --- a/deform/widget.py +++ b/deform/widget.py @@ -146,15 +146,16 @@ class Widget(object): following. 1. Two-tuples in the form ``(requirement_name, version_id)``. - Using the resource registry the **logical** requirement name - identifiers are resolved to concrete files using the - ``resource_registry``. - 2. Dicts that concretely point to resources such as ``{"js": - "deform:static/tinymce/tinymce.min.js"}``. - - A sequence of two-tuples should be in the form ``( (requirement_name, - version_id), ...)`` indicating the logical external - requirements needed to make this widget render properly within + The **logical** requirement name identifiers are resolved to + concrete files using the ``resource_registry``. + 2. Dicts in the form ``{requirement_type: + requirement_location(s)}``. The ``resource_registry`` is + bypassed. This is useful for creating custom widgets with + their own resources. + + Requirements specified as a sequence of two-tuples should be in the + form ``( (requirement_name, version_id), ...)`` indicating the logical + external requirements needed to make this widget render properly within a form. The ``requirement_name`` is a string that *logically* (not concretely, it is not a filename) identifies *one or more* Javascript or CSS resources that must be included in the @@ -164,14 +165,19 @@ class Widget(object): 'tinymce' for Tiny MCE). The ``version_id`` is a string indicating the version number (or ``None`` if no particular version is required). For example, a rich text widget might - declare ``requirements = (('tinymce', '3.3.8'),)``. See also: + declare ``requirements = (('tinymce', '3.3.8'),)``. + + Requirements specified as a sequence of dicts should be in the form + ``({requirement_type: requirement_location(s)}, ...)``. The + ``requirement_type`` key must be either ``js`` or ``css``. The + ``requirement_location(s)`` value must be either a string or a list of + strings. Each string must resolve to a concrete resource. For example, + a widget might declare ``requirements = ({"js": "deform:static/tinymce/tinymce.min.js"}, {"css": "deform:static/tinymce/tinymce.min.css"}, )``. + + See also: :ref:`specifying_widget_requirements` and :ref:`widget_requirements`. - If concrete resources are supplied as dicts, both ``js``and ``css`` - keys are accepted. Furthermore the value can be supplied as a string or - a list of strings. - Default: ``()`` (the empty tuple, meaning no special requirements). diff --git a/docs/widget.rst b/docs/widget.rst index 3f796eef..d1a341ea 100644 --- a/docs/widget.rst +++ b/docs/widget.rst @@ -253,16 +253,25 @@ See also the documentation of the ``resource_registry`` argument in Specifying Widget Requirements ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -When creating a new widget, you may specify its requirements by using -the ``requirements`` attribute: +When instantiating a new widget, you may specify its requirements by using the ``requirements`` attribute. +There are two acceptable forms for the specification: two-tuples and dicts. +The two-tuple form is used by all core Deform widgets and uses the resource registry, taking advantage of its abstraction layer. +The dict form bypasses the resource registry. +The dict form may be easier to implement than the two-tuple form for custom widgets. + + +.. _two-tuple-widget-requirements: + +Using two-tuples for specifying widget requirements +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: python - :linenos: + :linenos: - from deform.widget import Widget + from deform.widget import Widget - class MyWidget(Widget): - requirements = ( ('jquery', '1.4.2'), ) + class MyWidget(Widget): + requirements = ( ("jquery", "1.4.2"), ) There are no hard-and-fast rules about the composition of a requirement name. Your widget's docstring should explain what its @@ -283,24 +292,47 @@ constructing the form. The default resource registry (:attr:`deform.widget.resource_registry`) does not contain resource mappings for your newly-created requirement. -If the required resources are tightly couopled to the new widget, it may +If the required resources are tightly coupled to the new widget, it may be easier to supply the direct links to the logical requirements in the form: .. code-block:: python - :linenos: + :linenos: - from deform.widget import Widget + from deform.widget import Widget - class MyWidget(Widget): + class MyWidget(Widget): requirements = ( { - 'js': ''my:static/path/to/jquery.js', - 'css': [ - 'my:static/path/to/jquery.css', - 'my:static:path/to/bootstrap.css'], + "js": "my:static/path/to/jquery.js", + "css": [ + "my:static/path/to/jquery.css", + "my:static:path/to/bootstrap.css"], } ) -The supplied paths sre resolved by ``request.get_path()`` so the requried -static resources should be included in the pyramid config. +The supplied paths are resolved by ``request.get_path()`` so the required +static resources should be included in the Pyramid config. + + +.. _dict-widget-requirements: + +Using dicts for specifying widget requirements +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Requirements specified as a sequence of dicts should be in the form``({requirement_type: requirement_location(s)}, ...)``. +The ``requirement_type`` key must be either ``js`` or ``css``. +The ``requirement_location(s)`` value must be either a string or a list of strings. +Each string must resolve to a concrete resource. + +.. code-block:: python + :linenos: + + from deform.widget import Widget + + class MyWidget(Widget): + requirements = ( + {"js": "deform:static/tinymce/tinymce.min.js"}, + {"css": "deform:static/tinymce/tinymce.min.css"}, + ) + .. _writing_a_widget: From fd8860af08eb6519cc78a3fd16ca639d4d16ae47 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Thu, 5 Nov 2020 05:15:34 -0800 Subject: [PATCH 12/16] reformat docstring --- deform/widget.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/deform/widget.py b/deform/widget.py index e7fb35e0..3b466656 100644 --- a/deform/widget.py +++ b/deform/widget.py @@ -172,7 +172,14 @@ class Widget(object): ``requirement_type`` key must be either ``js`` or ``css``. The ``requirement_location(s)`` value must be either a string or a list of strings. Each string must resolve to a concrete resource. For example, - a widget might declare ``requirements = ({"js": "deform:static/tinymce/tinymce.min.js"}, {"css": "deform:static/tinymce/tinymce.min.css"}, )``. + a widget might declare: + + .. code-block:: python + + requirements = ( + {"js": "deform:static/tinymce/tinymce.min.js"}, + {"css": "deform:static/tinymce/tinymce.min.css"}, + ) See also: :ref:`specifying_widget_requirements` and From 88b4978056198f3774bd075fdf75ca2334312aab Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Thu, 5 Nov 2020 15:50:50 -0800 Subject: [PATCH 13/16] Combine narrative docs. See discussion https://github.com/Pylons/deform/pull/486#pullrequestreview-524232706 --- docs/widget.rst | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/docs/widget.rst b/docs/widget.rst index d1a341ea..7c51c0aa 100644 --- a/docs/widget.rst +++ b/docs/widget.rst @@ -255,9 +255,13 @@ Specifying Widget Requirements When instantiating a new widget, you may specify its requirements by using the ``requirements`` attribute. There are two acceptable forms for the specification: two-tuples and dicts. -The two-tuple form is used by all core Deform widgets and uses the resource registry, taking advantage of its abstraction layer. + +The two-tuple form is used by all core Deform widgets and uses the resource registry. +The two-tuple form takes advantage of Deform's abstraction layer through the resource registry. + The dict form bypasses the resource registry. The dict form may be easier to implement than the two-tuple form for custom widgets. +This is especially true if the required resources are tightly coupled to a custom widget. .. _two-tuple-widget-requirements: @@ -292,25 +296,6 @@ constructing the form. The default resource registry (:attr:`deform.widget.resource_registry`) does not contain resource mappings for your newly-created requirement. -If the required resources are tightly coupled to the new widget, it may -be easier to supply the direct links to the logical requirements in the form: - -.. code-block:: python - :linenos: - - from deform.widget import Widget - - class MyWidget(Widget): - requirements = ( { - "js": "my:static/path/to/jquery.js", - "css": [ - "my:static/path/to/jquery.css", - "my:static:path/to/bootstrap.css"], - } ) - -The supplied paths are resolved by ``request.get_path()`` so the required -static resources should be included in the Pyramid config. - .. _dict-widget-requirements: @@ -328,10 +313,15 @@ Each string must resolve to a concrete resource. from deform.widget import Widget class MyWidget(Widget): - requirements = ( - {"js": "deform:static/tinymce/tinymce.min.js"}, - {"css": "deform:static/tinymce/tinymce.min.css"}, - ) + requirements = ( { + "js": "my:static/path/to/jquery.js", + "css": [ + "my:static/path/to/jquery.css", + "my:static:path/to/bootstrap.css"], + } ) + +The supplied paths are resolved by ``request.get_path()`` so the required +static resources should be included in the Pyramid config. .. _writing_a_widget: From 0d4683acc255fbb54b9c7de09870d6fdf17624c0 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Thu, 5 Nov 2020 15:55:32 -0800 Subject: [PATCH 14/16] Further revisions per @tdamsma review. See https://github.com/Pylons/deform/pull/486#discussion_r518034642 --- docs/widget.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/widget.rst b/docs/widget.rst index 7c51c0aa..96ee5575 100644 --- a/docs/widget.rst +++ b/docs/widget.rst @@ -254,13 +254,13 @@ Specifying Widget Requirements ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When instantiating a new widget, you may specify its requirements by using the ``requirements`` attribute. -There are two acceptable forms for the specification: two-tuples and dicts. +The requirements are specified as a sequence of two-tuples, dicts, or a combination of both two-tuples and dicts. The two-tuple form is used by all core Deform widgets and uses the resource registry. The two-tuple form takes advantage of Deform's abstraction layer through the resource registry. The dict form bypasses the resource registry. -The dict form may be easier to implement than the two-tuple form for custom widgets. +The dict form may be easier to implement than the two-tuple form for custom widgets because it does not introduce an implicit dependency on the resource registry. This is especially true if the required resources are tightly coupled to a custom widget. From 8d25cc9858ac7fd0f0e75316a94b3c3e3e23a719 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Fri, 6 Nov 2020 02:23:37 -0800 Subject: [PATCH 15/16] Most Deform widgets, not all, use two-tuple form --- docs/widget.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/widget.rst b/docs/widget.rst index 96ee5575..6542adf5 100644 --- a/docs/widget.rst +++ b/docs/widget.rst @@ -256,7 +256,7 @@ Specifying Widget Requirements When instantiating a new widget, you may specify its requirements by using the ``requirements`` attribute. The requirements are specified as a sequence of two-tuples, dicts, or a combination of both two-tuples and dicts. -The two-tuple form is used by all core Deform widgets and uses the resource registry. +The two-tuple form uses the resource registry and is used by most of the core Deform widgets. The two-tuple form takes advantage of Deform's abstraction layer through the resource registry. The dict form bypasses the resource registry. From ce574adf3774440c4e68833f9c55d0a53d724393 Mon Sep 17 00:00:00 2001 From: Thijs Damsma Date: Fri, 6 Nov 2020 11:45:15 +0100 Subject: [PATCH 16/16] remove file upload from registry --- deform/widget.py | 1 - 1 file changed, 1 deletion(-) diff --git a/deform/widget.py b/deform/widget.py index 3b466656..f5d54cb1 100644 --- a/deform/widget.py +++ b/deform/widget.py @@ -2203,7 +2203,6 @@ def __call__(self, requirements): ), } }, - "fileupload": {None: {"js": "deform:static/scripts/file_upload.js"}}, } default_resource_registry = ResourceRegistry()