From dee1524dc07cebfe2c4c9066418fb4ebe9b4f497 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 20:59:32 +0200 Subject: [PATCH 1/3] build(deps): bump django from 5.0.4 to 5.0.5 (#487) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 1c0185b3..2e27da7e 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -20,7 +20,7 @@ colorama==0.4.6 # via tox distlib==0.3.8 # via virtualenv -django==5.0.4 +django==5.0.5 # via -r requirements-dev.in filelock==3.13.1 # via From dd6540cfccaebd5de29b3715835a408c1e043570 Mon Sep 17 00:00:00 2001 From: Juro Oravec Date: Tue, 7 May 2024 15:11:40 +0200 Subject: [PATCH 2/3] fix: incorrect name for default slot in is_filled dict (#482) --- src/django_components/slots.py | 12 +++++++- tests/test_templatetags.py | 51 +++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/django_components/slots.py b/src/django_components/slots.py index 874e8a67..fa9c3fa3 100644 --- a/src/django_components/slots.py +++ b/src/django_components/slots.py @@ -461,7 +461,17 @@ def _resolve_default_slot( # Here we've identified which slot the default/implicit fill belongs to if default_fill: - named_fills[slot.name] = default_fill._replace(name=slot.name) + # NOTE: We recreate new instance, passing all fields, instead of using + # `NamedTuple._replace`, because `_replace` is not typed. + named_fills[slot.name] = SlotFill( + is_filled=default_fill.is_filled, + nodelist=default_fill.nodelist, + context_data=default_fill.context_data, + alias=default_fill.alias, + # Updated fields + name=slot.name, + escaped_name=_escape_slot_name(slot.name), + ) # Check: Only component templates that include a 'default' slot # can be invoked with implicit filling. diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index 364baa2f..4793ff04 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -1157,7 +1157,7 @@ class ComplexChildComponent(component.Component): class ComplexParentComponent(component.Component): template: types.django_html = """ {% load component_tags %} - ITEMS: {{ items }} + ITEMS: {{ items|safe }} {% for item in items %}
  • {% component "complex_child" %} @@ -1296,7 +1296,7 @@ def test_component_nesting_deep_slot_inside_component_fill__isolated(self): items = [{"value": 1}, {"value": 2}, {"value": 3}] rendered = template.render(Context({"items": items})) expected = """ - ITEMS: [{'value': 1}, {'value': 2}, {'value': 3}] + ITEMS: [{'value': 1}, {'value': 2}, {'value': 3}]
  • 1
  • @@ -1522,12 +1522,12 @@ class IsFilledVarsComponent(component.Component): template: types.django_html = """ {% load component_tags %}
    - {% slot "title" %}{% endslot %} + {% slot "title" default %}{% endslot %} {% slot "my_title" %}{% endslot %} {% slot "my title 1" %}{% endslot %} {% slot "my-title-2" %}{% endslot %} {% slot "escape this: #$%^*()" %}{% endslot %} - {{ component_vars.is_filled }} + {{ component_vars.is_filled|safe }}
    """ @@ -1546,14 +1546,33 @@ def test_is_filled_vars(self): {% endcomponent %} """ rendered = Template(template).render(Context()) - # NOTE: `'` are escaped quotes expected = """
    - {'title': True, - 'my_title': False, - 'my_title_1': False, - 'my_title_2': True, - 'escape_this_________': True} + {'title': True, + 'my_title': False, + 'my_title_1': False, + 'my_title_2': True, + 'escape_this_________': True} +
    + """ + self.assertHTMLEqual(rendered, expected) + + def test_is_filled_vars_default(self): + template: types.django_html = """ + {% load component_tags %} + {% component "is_filled_vars" %} + bla bla + {% endcomponent %} + """ + rendered = Template(template).render(Context()) + expected = """ +
    + bla bla + {'title': True, + 'my_title': False, + 'my_title_1': False, + 'my_title_2': False, + 'escape_this_________': False}
    """ self.assertHTMLEqual(rendered, expected) @@ -2337,10 +2356,10 @@ def test_inner_slot_iteration_nested_with_slot_default_and_outer_scope_variable_ {% load component_tags %} {% component "slot_in_a_loop" objects=objects %} {% fill "slot_inner" %} - {{ outer_scope_variable_1 }} + {{ outer_scope_variable_1|safe }} {% component "slot_in_a_loop" objects=objects %} {% fill "slot_inner" as "super_slot_inner" %} - {{ outer_scope_variable_2 }} + {{ outer_scope_variable_2|safe }} {{ super_slot_inner.default }} {% endfill %} {% endcomponent %} @@ -2363,13 +2382,13 @@ def test_inner_slot_iteration_nested_with_slot_default_and_outer_scope_variable_ """ OUTER_SCOPE_VARIABLE1 OUTER_SCOPE_VARIABLE2 - {'inner': ['ITER1_OBJ1', 'ITER1_OBJ2']} default + {'inner': ['ITER1_OBJ1', 'ITER1_OBJ2']} default OUTER_SCOPE_VARIABLE2 - {'inner': ['ITER2_OBJ1', 'ITER2_OBJ2']} default + {'inner': ['ITER2_OBJ1', 'ITER2_OBJ2']} default OUTER_SCOPE_VARIABLE1 OUTER_SCOPE_VARIABLE2 - {'inner': ['ITER1_OBJ1', 'ITER1_OBJ2']} default + {'inner': ['ITER1_OBJ1', 'ITER1_OBJ2']} default OUTER_SCOPE_VARIABLE2 - {'inner': ['ITER2_OBJ1', 'ITER2_OBJ2']} default + {'inner': ['ITER2_OBJ1', 'ITER2_OBJ2']} default """, ) From 085c60a8c96442d9fd4f72d66a7eb295e7cfb2d9 Mon Sep 17 00:00:00 2001 From: Juro Oravec Date: Tue, 7 May 2024 15:15:15 +0200 Subject: [PATCH 3/3] chore: bump v0.72 (#490) --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 71ddac82..e7876440 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "django_components" -version = "0.71" +version = "0.72" requires-python = ">=3.8, <4.0" description = "A way to create simple reusable template components in Django." keywords = ["django", "components", "css", "js", "html"]