django-components 0.71__tar.gz → 0.73__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_components-0.71/src/django_components.egg-info → django_components-0.73}/PKG-INFO +1 -1
- {django_components-0.71 → django_components-0.73}/pyproject.toml +1 -1
- {django_components-0.71 → django_components-0.73}/src/django_components/slots.py +11 -1
- {django_components-0.71 → django_components-0.73}/src/django_components/template_loader.py +10 -0
- {django_components-0.71 → django_components-0.73/src/django_components.egg-info}/PKG-INFO +1 -1
- {django_components-0.71 → django_components-0.73}/tests/test_autodiscover.py +24 -0
- {django_components-0.71 → django_components-0.73}/tests/test_templatetags.py +35 -16
- {django_components-0.71 → django_components-0.73}/LICENSE +0 -0
- {django_components-0.71 → django_components-0.73}/README.md +0 -0
- {django_components-0.71 → django_components-0.73}/setup.cfg +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/__init__.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/app_settings.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/apps.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/component.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/component_registry.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/context.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/logger.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/management/__init__.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/management/commands/__init__.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/management/commands/startcomponent.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/management/commands/upgradecomponent.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/middleware.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/node.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/py.typed +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/safer_staticfiles/__init__.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/safer_staticfiles/apps.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/template_parser.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/templatetags/__init__.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/templatetags/component_tags.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/types.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components/utils.py +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components.egg-info/SOURCES.txt +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components.egg-info/dependency_links.txt +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components.egg-info/requires.txt +0 -0
- {django_components-0.71 → django_components-0.73}/src/django_components.egg-info/top_level.txt +0 -0
- {django_components-0.71 → django_components-0.73}/tests/test_component.py +0 -0
- {django_components-0.71 → django_components-0.73}/tests/test_component_as_view.py +0 -0
- {django_components-0.71 → django_components-0.73}/tests/test_context.py +0 -0
- {django_components-0.71 → django_components-0.73}/tests/test_dependency_rendering.py +0 -0
- {django_components-0.71 → django_components-0.73}/tests/test_registry.py +0 -0
- {django_components-0.71 → django_components-0.73}/tests/test_settings.py +0 -0
- {django_components-0.71 → django_components-0.73}/tests/test_startcomponent_command.py +0 -0
- {django_components-0.71 → django_components-0.73}/tests/test_template_parser.py +0 -0
- {django_components-0.71 → django_components-0.73}/tests/testutils.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "django_components"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.73"
|
|
8
8
|
requires-python = ">=3.8, <4.0"
|
|
9
9
|
description = "A way to create simple reusable template components in Django."
|
|
10
10
|
keywords = ["django", "components", "css", "js", "html"]
|
|
@@ -461,7 +461,17 @@ def _resolve_default_slot(
|
|
|
461
461
|
|
|
462
462
|
# Here we've identified which slot the default/implicit fill belongs to
|
|
463
463
|
if default_fill:
|
|
464
|
-
|
|
464
|
+
# NOTE: We recreate new instance, passing all fields, instead of using
|
|
465
|
+
# `NamedTuple._replace`, because `_replace` is not typed.
|
|
466
|
+
named_fills[slot.name] = SlotFill(
|
|
467
|
+
is_filled=default_fill.is_filled,
|
|
468
|
+
nodelist=default_fill.nodelist,
|
|
469
|
+
context_data=default_fill.context_data,
|
|
470
|
+
alias=default_fill.alias,
|
|
471
|
+
# Updated fields
|
|
472
|
+
name=slot.name,
|
|
473
|
+
escaped_name=_escape_slot_name(slot.name),
|
|
474
|
+
)
|
|
465
475
|
|
|
466
476
|
# Check: Only component templates that include a 'default' slot
|
|
467
477
|
# can be invoked with implicit filling.
|
|
@@ -37,6 +37,16 @@ class Loader(FilesystemLoader):
|
|
|
37
37
|
|
|
38
38
|
directories: Set[Path] = set()
|
|
39
39
|
for component_dir in component_dirs:
|
|
40
|
+
if isinstance(component_dir, (tuple, list)) and len(component_dir) == 2:
|
|
41
|
+
component_dir = component_dir[1]
|
|
42
|
+
try:
|
|
43
|
+
Path(component_dir)
|
|
44
|
+
except TypeError:
|
|
45
|
+
logger.warning(
|
|
46
|
+
f"STATICFILES_DIRS expected str, bytes or os.PathLike object, or tuple/list of length 2. "
|
|
47
|
+
f"See Django documentation. Got {type(component_dir)} : {component_dir}"
|
|
48
|
+
)
|
|
49
|
+
continue
|
|
40
50
|
curr_directories: Set[Path] = set()
|
|
41
51
|
|
|
42
52
|
# For each dir in `settings.STATICFILES_DIRS`, we go over all Django apps
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
from unittest import mock
|
|
3
|
+
from unittest.mock import MagicMock, patch
|
|
3
4
|
|
|
4
5
|
from django.template.engine import Engine
|
|
5
6
|
from django.urls import include, path
|
|
@@ -125,6 +126,29 @@ class TestBaseDir(BaseTestCase):
|
|
|
125
126
|
self.assertEqual(sorted(dirs), sorted(expected))
|
|
126
127
|
|
|
127
128
|
|
|
129
|
+
class TestStaticFilesDirs(BaseTestCase):
|
|
130
|
+
def setUp(self):
|
|
131
|
+
settings.STATICFILES_DIRS = [
|
|
132
|
+
"components",
|
|
133
|
+
("with_alias", "components"),
|
|
134
|
+
("too_many", "items", "components"),
|
|
135
|
+
("with_not_str_alias", 3),
|
|
136
|
+
] # noqa
|
|
137
|
+
|
|
138
|
+
def tearDown(self) -> None:
|
|
139
|
+
del settings.STATICFILES_DIRS # noqa
|
|
140
|
+
|
|
141
|
+
@patch("django_components.template_loader.logger.warning")
|
|
142
|
+
def test_static_files_dirs(self, mock_warning: MagicMock):
|
|
143
|
+
mock_warning.reset_mock()
|
|
144
|
+
current_engine = Engine.get_default()
|
|
145
|
+
Loader(current_engine).get_dirs()
|
|
146
|
+
|
|
147
|
+
warn_inputs = [warn.args[0] for warn in mock_warning.call_args_list]
|
|
148
|
+
assert "Got <class 'tuple'> : ('too_many', 'items', 'components')" in warn_inputs[0]
|
|
149
|
+
assert "Got <class 'int'> : 3" in warn_inputs[1]
|
|
150
|
+
|
|
151
|
+
|
|
128
152
|
class TestFilepathToPythonModule(BaseTestCase):
|
|
129
153
|
def test_prepares_path(self):
|
|
130
154
|
self.assertEqual(
|
|
@@ -1157,7 +1157,7 @@ class ComponentNestingTests(BaseTestCase):
|
|
|
1157
1157
|
class ComplexParentComponent(component.Component):
|
|
1158
1158
|
template: types.django_html = """
|
|
1159
1159
|
{% load component_tags %}
|
|
1160
|
-
ITEMS: {{ items }}
|
|
1160
|
+
ITEMS: {{ items|safe }}
|
|
1161
1161
|
{% for item in items %}
|
|
1162
1162
|
<li>
|
|
1163
1163
|
{% component "complex_child" %}
|
|
@@ -1296,7 +1296,7 @@ class ComponentNestingTests(BaseTestCase):
|
|
|
1296
1296
|
items = [{"value": 1}, {"value": 2}, {"value": 3}]
|
|
1297
1297
|
rendered = template.render(Context({"items": items}))
|
|
1298
1298
|
expected = """
|
|
1299
|
-
ITEMS: [{
|
|
1299
|
+
ITEMS: [{'value': 1}, {'value': 2}, {'value': 3}]
|
|
1300
1300
|
<li>
|
|
1301
1301
|
<div> 1 </div>
|
|
1302
1302
|
</li>
|
|
@@ -1522,12 +1522,12 @@ class ContextVarsTests(BaseTestCase):
|
|
|
1522
1522
|
template: types.django_html = """
|
|
1523
1523
|
{% load component_tags %}
|
|
1524
1524
|
<div class="frontmatter-component">
|
|
1525
|
-
{% slot "title" %}{% endslot %}
|
|
1525
|
+
{% slot "title" default %}{% endslot %}
|
|
1526
1526
|
{% slot "my_title" %}{% endslot %}
|
|
1527
1527
|
{% slot "my title 1" %}{% endslot %}
|
|
1528
1528
|
{% slot "my-title-2" %}{% endslot %}
|
|
1529
1529
|
{% slot "escape this: #$%^*()" %}{% endslot %}
|
|
1530
|
-
{{ component_vars.is_filled }}
|
|
1530
|
+
{{ component_vars.is_filled|safe }}
|
|
1531
1531
|
</div>
|
|
1532
1532
|
"""
|
|
1533
1533
|
|
|
@@ -1546,14 +1546,33 @@ class ContextVarsTests(BaseTestCase):
|
|
|
1546
1546
|
{% endcomponent %}
|
|
1547
1547
|
"""
|
|
1548
1548
|
rendered = Template(template).render(Context())
|
|
1549
|
-
# NOTE: `'` are escaped quotes
|
|
1550
1549
|
expected = """
|
|
1551
1550
|
<div class="frontmatter-component">
|
|
1552
|
-
{
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1551
|
+
{'title': True,
|
|
1552
|
+
'my_title': False,
|
|
1553
|
+
'my_title_1': False,
|
|
1554
|
+
'my_title_2': True,
|
|
1555
|
+
'escape_this_________': True}
|
|
1556
|
+
</div>
|
|
1557
|
+
"""
|
|
1558
|
+
self.assertHTMLEqual(rendered, expected)
|
|
1559
|
+
|
|
1560
|
+
def test_is_filled_vars_default(self):
|
|
1561
|
+
template: types.django_html = """
|
|
1562
|
+
{% load component_tags %}
|
|
1563
|
+
{% component "is_filled_vars" %}
|
|
1564
|
+
bla bla
|
|
1565
|
+
{% endcomponent %}
|
|
1566
|
+
"""
|
|
1567
|
+
rendered = Template(template).render(Context())
|
|
1568
|
+
expected = """
|
|
1569
|
+
<div class="frontmatter-component">
|
|
1570
|
+
bla bla
|
|
1571
|
+
{'title': True,
|
|
1572
|
+
'my_title': False,
|
|
1573
|
+
'my_title_1': False,
|
|
1574
|
+
'my_title_2': False,
|
|
1575
|
+
'escape_this_________': False}
|
|
1557
1576
|
</div>
|
|
1558
1577
|
"""
|
|
1559
1578
|
self.assertHTMLEqual(rendered, expected)
|
|
@@ -2337,10 +2356,10 @@ class IterationFillTest(BaseTestCase):
|
|
|
2337
2356
|
{% load component_tags %}
|
|
2338
2357
|
{% component "slot_in_a_loop" objects=objects %}
|
|
2339
2358
|
{% fill "slot_inner" %}
|
|
2340
|
-
{{ outer_scope_variable_1 }}
|
|
2359
|
+
{{ outer_scope_variable_1|safe }}
|
|
2341
2360
|
{% component "slot_in_a_loop" objects=objects %}
|
|
2342
2361
|
{% fill "slot_inner" as "super_slot_inner" %}
|
|
2343
|
-
{{ outer_scope_variable_2 }}
|
|
2362
|
+
{{ outer_scope_variable_2|safe }}
|
|
2344
2363
|
{{ super_slot_inner.default }}
|
|
2345
2364
|
{% endfill %}
|
|
2346
2365
|
{% endcomponent %}
|
|
@@ -2363,13 +2382,13 @@ class IterationFillTest(BaseTestCase):
|
|
|
2363
2382
|
"""
|
|
2364
2383
|
OUTER_SCOPE_VARIABLE1
|
|
2365
2384
|
OUTER_SCOPE_VARIABLE2
|
|
2366
|
-
{
|
|
2385
|
+
{'inner': ['ITER1_OBJ1', 'ITER1_OBJ2']} default
|
|
2367
2386
|
OUTER_SCOPE_VARIABLE2
|
|
2368
|
-
{
|
|
2387
|
+
{'inner': ['ITER2_OBJ1', 'ITER2_OBJ2']} default
|
|
2369
2388
|
OUTER_SCOPE_VARIABLE1
|
|
2370
2389
|
OUTER_SCOPE_VARIABLE2
|
|
2371
|
-
{
|
|
2390
|
+
{'inner': ['ITER1_OBJ1', 'ITER1_OBJ2']} default
|
|
2372
2391
|
OUTER_SCOPE_VARIABLE2
|
|
2373
|
-
{
|
|
2392
|
+
{'inner': ['ITER2_OBJ1', 'ITER2_OBJ2']} default
|
|
2374
2393
|
""",
|
|
2375
2394
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.71 → django_components-0.73}/src/django_components/component_registry.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.71 → django_components-0.73}/src/django_components/management/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.71 → django_components-0.73}/src/django_components/safer_staticfiles/apps.py
RENAMED
|
File without changes
|
|
File without changes
|
{django_components-0.71 → django_components-0.73}/src/django_components/templatetags/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.71 → django_components-0.73}/src/django_components.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{django_components-0.71 → django_components-0.73}/src/django_components.egg-info/requires.txt
RENAMED
|
File without changes
|
{django_components-0.71 → django_components-0.73}/src/django_components.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|