From 9226f683a70cb1f6f85c866e1cacf027376a6575 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Sun, 1 Jan 2023 23:39:33 -0800 Subject: [PATCH 1/9] Fix recursive fetch depth for ManyToOneRel --- src/django_idom/utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/django_idom/utils.py b/src/django_idom/utils.py index 0b0d2003..3ce96ad0 100644 --- a/src/django_idom/utils.py +++ b/src/django_idom/utils.py @@ -236,15 +236,16 @@ def django_query_postprocessor( elif many_to_many and isinstance(field, ManyToManyField): prefetch_fields.append(field.name) + + if prefetch_fields: + prefetch_related_objects([data], *prefetch_fields) + for field_str in prefetch_fields: django_query_postprocessor( - getattr(data, field.name).get_queryset(), + getattr(data, field_str).get_queryset(), many_to_many=many_to_many, many_to_one=many_to_one, ) - if prefetch_fields: - prefetch_related_objects([data], *prefetch_fields) - # Unrecognized type else: raise TypeError( From 4f5a09e19db916b388497fa71eedf3d01eb6771c Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Sun, 1 Jan 2023 23:45:29 -0800 Subject: [PATCH 2/9] add changelog entry --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ae0eb0a..4699a222 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,9 @@ Using the following categories, list your changes in this order: ## [Unreleased] -- Nothing (yet) +### Fixed + +- Fixed bug where `use_query` would not recursively fetch many-to-one relationships. ## [2.2.0] - 2022-12-28 From d32f2569662e43dbff6f81463017ce8139a035ad Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Sun, 1 Jan 2023 23:47:57 -0800 Subject: [PATCH 3/9] remove flakey test using idom export --- tests/test_app/components.py | 9 --------- tests/test_app/templates/base.html | 1 - tests/test_app/tests/test_components.py | 3 --- 3 files changed, 13 deletions(-) diff --git a/tests/test_app/components.py b/tests/test_app/components.py index 72581aed..e36e45f7 100644 --- a/tests/test_app/components.py +++ b/tests/test_app/components.py @@ -44,15 +44,6 @@ def parameterized_component(x, y): ) -victory = web.module_from_template("react", "victory-bar", fallback="...") -VictoryBar = web.export(victory, "VictoryBar") - - -@component -def simple_bar_chart(): - return html._(VictoryBar(), html.hr()) - - @component def use_websocket(): ws = django_idom.hooks.use_websocket() diff --git a/tests/test_app/templates/base.html b/tests/test_app/templates/base.html index ec99aa1f..3ba711c8 100644 --- a/tests/test_app/templates/base.html +++ b/tests/test_app/templates/base.html @@ -23,7 +23,6 @@

IDOM Test Page

{% component "test_app.components.hello_world" class="hello-world" %}
{% component "test_app.components.button" class="button" %}
{% component "test_app.components.parameterized_component" class="parametarized-component" x=123 y=456 %}
-
{% component "test_app.components.simple_bar_chart" %}
{% component "test_app.components.use_websocket" %}
{% component "test_app.components.use_scope" %}
{% component "test_app.components.use_location" %}
diff --git a/tests/test_app/tests/test_components.py b/tests/test_app/tests/test_components.py index 7ded5a44..14fe73da 100644 --- a/tests/test_app/tests/test_components.py +++ b/tests/test_app/tests/test_components.py @@ -47,9 +47,6 @@ def test_counter(self): def test_parametrized_component(self): self.page.locator("#parametrized-component[data-value='579']").wait_for() - def test_component_from_web_module(self): - self.page.wait_for_selector(".VictoryContainer") - def test_use_websocket(self): self.page.locator("#use-websocket[data-success=true]").wait_for() From c40d55767b2c235c72a006e8024a58831b246ea9 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Sun, 1 Jan 2023 23:51:31 -0800 Subject: [PATCH 4/9] fix style --- tests/test_app/components.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_app/components.py b/tests/test_app/components.py index e36e45f7..40828485 100644 --- a/tests/test_app/components.py +++ b/tests/test_app/components.py @@ -2,7 +2,7 @@ from django.http import HttpRequest from django.shortcuts import render -from idom import component, hooks, html, web +from idom import component, hooks, html from test_app.models import ForiegnChild, RelationalChild, RelationalParent, TodoItem import django_idom From e164da3d9337f1905690021712487be1a5013d8c Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 2 Jan 2023 00:14:06 -0800 Subject: [PATCH 5/9] v2.2.1 --- CHANGELOG.md | 7 ++++++- src/django_idom/__init__.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4699a222..a8837865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,10 @@ Using the following categories, list your changes in this order: ## [Unreleased] +- Nothing (yet) + +## [2.2.1] - 2022-01-02 + ### Fixed - Fixed bug where `use_query` would not recursively fetch many-to-one relationships. @@ -186,7 +190,8 @@ Using the following categories, list your changes in this order: - Support for IDOM within the Django -[unreleased]: https://github.com/idom-team/django-idom/compare/2.2.0...HEAD +[unreleased]: https://github.com/idom-team/django-idom/compare/2.2.1...HEAD +[2.2.1]: https://github.com/idom-team/django-idom/compare/2.2.0...2.2.1 [2.2.0]: https://github.com/idom-team/django-idom/compare/2.1.0...2.2.0 [2.1.0]: https://github.com/idom-team/django-idom/compare/2.0.1...2.1.0 [2.0.1]: https://github.com/idom-team/django-idom/compare/2.0.0...2.0.1 diff --git a/src/django_idom/__init__.py b/src/django_idom/__init__.py index 32c4978c..c1991661 100644 --- a/src/django_idom/__init__.py +++ b/src/django_idom/__init__.py @@ -3,7 +3,7 @@ from django_idom.websocket.paths import IDOM_WEBSOCKET_PATH -__version__ = "2.2.0" +__version__ = "2.2.1" __all__ = [ "IDOM_WEBSOCKET_PATH", "IdomWebsocket", From 8976836e049ee2f1e3140ecc99fa48e704e4276b Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 9 Jan 2023 00:33:09 -0800 Subject: [PATCH 6/9] SimpleButton test --- tests/test_app/components.py | 16 +++++++++++++++- tests/test_app/static/simple-button.js | 25 +++++++++++++++++++++++++ tests/test_app/templates/base.html | 1 + tests/test_app/tests/test_components.py | 3 +++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/test_app/static/simple-button.js diff --git a/tests/test_app/components.py b/tests/test_app/components.py index 40828485..f93d45f4 100644 --- a/tests/test_app/components.py +++ b/tests/test_app/components.py @@ -2,7 +2,7 @@ from django.http import HttpRequest from django.shortcuts import render -from idom import component, hooks, html +from idom import component, hooks, html, web from test_app.models import ForiegnChild, RelationalChild, RelationalParent, TodoItem import django_idom @@ -44,6 +44,20 @@ def parameterized_component(x, y): ) +SimpleButtonModule = web.module_from_url( + "/static/simple-button.js", resolve_exports=False, fallback="..." +) +SimpleButton = web.export(SimpleButtonModule, "SimpleButton") + + +@component +def simple_button(): + return html._( + SimpleButton({"id": "simple-button"}), + html.hr(), + ) + + @component def use_websocket(): ws = django_idom.hooks.use_websocket() diff --git a/tests/test_app/static/simple-button.js b/tests/test_app/static/simple-button.js new file mode 100644 index 00000000..e68b9638 --- /dev/null +++ b/tests/test_app/static/simple-button.js @@ -0,0 +1,25 @@ +import { h, render } from "https://unpkg.com/preact?module"; +import htm from "https://unpkg.com/htm?module"; + +const html = htm.bind(h); + +export function bind(node, config) { + return { + create: (type, props, children) => h(type, props, ...children), + render: (element) => render(element, node), + unmount: () => render(null, node), + }; +} + +export function SimpleButton(props) { + return h( + "button", + { + id: props.id, + onClick(event) { + props.onClick({ data: props.eventResponseData }); + }, + }, + "simple button" + ); +} diff --git a/tests/test_app/templates/base.html b/tests/test_app/templates/base.html index 3ba711c8..ca196297 100644 --- a/tests/test_app/templates/base.html +++ b/tests/test_app/templates/base.html @@ -23,6 +23,7 @@

IDOM Test Page

{% component "test_app.components.hello_world" class="hello-world" %}
{% component "test_app.components.button" class="button" %}
{% component "test_app.components.parameterized_component" class="parametarized-component" x=123 y=456 %}
+
{% component "test_app.components.simple_button" %}
{% component "test_app.components.use_websocket" %}
{% component "test_app.components.use_scope" %}
{% component "test_app.components.use_location" %}
diff --git a/tests/test_app/tests/test_components.py b/tests/test_app/tests/test_components.py index 14fe73da..5c435f22 100644 --- a/tests/test_app/tests/test_components.py +++ b/tests/test_app/tests/test_components.py @@ -47,6 +47,9 @@ def test_counter(self): def test_parametrized_component(self): self.page.locator("#parametrized-component[data-value='579']").wait_for() + def test_component_from_web_module(self): + self.page.wait_for_selector("#simple-button") + def test_use_websocket(self): self.page.locator("#use-websocket[data-success=true]").wait_for() From 9775131485c2e990cf0de8a5fdcccc5980b42f09 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 9 Jan 2023 01:05:19 -0800 Subject: [PATCH 7/9] change IDOM preloader logging from error to exception --- src/django_idom/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/django_idom/utils.py b/src/django_idom/utils.py index 3ce96ad0..9c76a9f9 100644 --- a/src/django_idom/utils.py +++ b/src/django_idom/utils.py @@ -184,7 +184,7 @@ def _register_components(self, components: set[str]) -> None: _logger.info("IDOM preloader has detected component %s", component) _register_component(component) except Exception: - _logger.error( + _logger.exception( "\033[91m" "IDOM failed to register component '%s'! " "This component path may not be valid, " From c2e05a5e235b9d47d4c799783b3664e6069d3570 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 9 Jan 2023 01:05:32 -0800 Subject: [PATCH 8/9] use module_from_file --- CHANGELOG.md | 1 + tests/test_app/components.py | 8 ++++++-- tests/test_app/{static => tests/js}/simple-button.js | 0 3 files changed, 7 insertions(+), 2 deletions(-) rename tests/test_app/{static => tests/js}/simple-button.js (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8837865..db803659 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ Using the following categories, list your changes in this order: ### Fixed - Fixed bug where `use_query` would not recursively fetch many-to-one relationships. +- IDOM preloader will now print out the exception stack when failing to import a module. ## [2.2.0] - 2022-12-28 diff --git a/tests/test_app/components.py b/tests/test_app/components.py index f93d45f4..29c3da30 100644 --- a/tests/test_app/components.py +++ b/tests/test_app/components.py @@ -1,4 +1,5 @@ import inspect +from pathlib import Path from django.http import HttpRequest from django.shortcuts import render @@ -44,8 +45,11 @@ def parameterized_component(x, y): ) -SimpleButtonModule = web.module_from_url( - "/static/simple-button.js", resolve_exports=False, fallback="..." +SimpleButtonModule = web.module_from_file( + "SimpleButton", + Path(__file__).parent / "tests" / "js" / "simple-button.js", + resolve_exports=False, + fallback="...", ) SimpleButton = web.export(SimpleButtonModule, "SimpleButton") diff --git a/tests/test_app/static/simple-button.js b/tests/test_app/tests/js/simple-button.js similarity index 100% rename from tests/test_app/static/simple-button.js rename to tests/test_app/tests/js/simple-button.js From f0d5026ffc64b15dd557a6ce81f64434698bddd8 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 9 Jan 2023 14:45:43 -0800 Subject: [PATCH 9/9] bump date --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db803659..ce7c1daa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ Using the following categories, list your changes in this order: - Nothing (yet) -## [2.2.1] - 2022-01-02 +## [2.2.1] - 2022-01-09 ### Fixed