django-components 0.78__tar.gz → 0.79__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.
Files changed (51) hide show
  1. {django_components-0.78/src/django_components.egg-info → django_components-0.79}/PKG-INFO +62 -42
  2. {django_components-0.78 → django_components-0.79}/README.md +61 -41
  3. {django_components-0.78 → django_components-0.79}/pyproject.toml +1 -1
  4. {django_components-0.78 → django_components-0.79}/src/django_components/app_settings.py +1 -1
  5. {django_components-0.78 → django_components-0.79/src/django_components.egg-info}/PKG-INFO +62 -42
  6. {django_components-0.78 → django_components-0.79}/LICENSE +0 -0
  7. {django_components-0.78 → django_components-0.79}/setup.cfg +0 -0
  8. {django_components-0.78 → django_components-0.79}/src/django_components/__init__.py +0 -0
  9. {django_components-0.78 → django_components-0.79}/src/django_components/apps.py +0 -0
  10. {django_components-0.78 → django_components-0.79}/src/django_components/attributes.py +0 -0
  11. {django_components-0.78 → django_components-0.79}/src/django_components/component.py +0 -0
  12. {django_components-0.78 → django_components-0.79}/src/django_components/component_registry.py +0 -0
  13. {django_components-0.78 → django_components-0.79}/src/django_components/context.py +0 -0
  14. {django_components-0.78 → django_components-0.79}/src/django_components/expression.py +0 -0
  15. {django_components-0.78 → django_components-0.79}/src/django_components/logger.py +0 -0
  16. {django_components-0.78 → django_components-0.79}/src/django_components/management/__init__.py +0 -0
  17. {django_components-0.78 → django_components-0.79}/src/django_components/management/commands/__init__.py +0 -0
  18. {django_components-0.78 → django_components-0.79}/src/django_components/management/commands/startcomponent.py +0 -0
  19. {django_components-0.78 → django_components-0.79}/src/django_components/management/commands/upgradecomponent.py +0 -0
  20. {django_components-0.78 → django_components-0.79}/src/django_components/middleware.py +0 -0
  21. {django_components-0.78 → django_components-0.79}/src/django_components/node.py +0 -0
  22. {django_components-0.78 → django_components-0.79}/src/django_components/py.typed +0 -0
  23. {django_components-0.78 → django_components-0.79}/src/django_components/safer_staticfiles/__init__.py +0 -0
  24. {django_components-0.78 → django_components-0.79}/src/django_components/safer_staticfiles/apps.py +0 -0
  25. {django_components-0.78 → django_components-0.79}/src/django_components/slots.py +0 -0
  26. {django_components-0.78 → django_components-0.79}/src/django_components/template_loader.py +0 -0
  27. {django_components-0.78 → django_components-0.79}/src/django_components/template_parser.py +0 -0
  28. {django_components-0.78 → django_components-0.79}/src/django_components/templatetags/__init__.py +0 -0
  29. {django_components-0.78 → django_components-0.79}/src/django_components/templatetags/component_tags.py +0 -0
  30. {django_components-0.78 → django_components-0.79}/src/django_components/types.py +0 -0
  31. {django_components-0.78 → django_components-0.79}/src/django_components/utils.py +0 -0
  32. {django_components-0.78 → django_components-0.79}/src/django_components.egg-info/SOURCES.txt +0 -0
  33. {django_components-0.78 → django_components-0.79}/src/django_components.egg-info/dependency_links.txt +0 -0
  34. {django_components-0.78 → django_components-0.79}/src/django_components.egg-info/requires.txt +0 -0
  35. {django_components-0.78 → django_components-0.79}/src/django_components.egg-info/top_level.txt +0 -0
  36. {django_components-0.78 → django_components-0.79}/tests/test_attributes.py +0 -0
  37. {django_components-0.78 → django_components-0.79}/tests/test_autodiscover.py +0 -0
  38. {django_components-0.78 → django_components-0.79}/tests/test_command_startcomponent.py +0 -0
  39. {django_components-0.78 → django_components-0.79}/tests/test_component.py +0 -0
  40. {django_components-0.78 → django_components-0.79}/tests/test_component_as_view.py +0 -0
  41. {django_components-0.78 → django_components-0.79}/tests/test_component_media.py +0 -0
  42. {django_components-0.78 → django_components-0.79}/tests/test_context.py +0 -0
  43. {django_components-0.78 → django_components-0.79}/tests/test_dependency_rendering.py +0 -0
  44. {django_components-0.78 → django_components-0.79}/tests/test_registry.py +0 -0
  45. {django_components-0.78 → django_components-0.79}/tests/test_settings.py +0 -0
  46. {django_components-0.78 → django_components-0.79}/tests/test_template_parser.py +0 -0
  47. {django_components-0.78 → django_components-0.79}/tests/test_templatetags.py +0 -0
  48. {django_components-0.78 → django_components-0.79}/tests/test_templatetags_component.py +0 -0
  49. {django_components-0.78 → django_components-0.79}/tests/test_templatetags_slot_fill.py +0 -0
  50. {django_components-0.78 → django_components-0.79}/tests/test_templatetags_templating.py +0 -0
  51. {django_components-0.78 → django_components-0.79}/tests/testutils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django_components
3
- Version: 0.78
3
+ Version: 0.79
4
4
  Summary: A way to create simple reusable template components in Django.
5
5
  Author-email: Emil Stenström <emil@emilstenstrom.se>
6
6
  License: MIT
@@ -68,6 +68,11 @@ Read on to learn about the details!
68
68
 
69
69
  ## Release notes
70
70
 
71
+ 🚨📢 **Version 0.79**
72
+
73
+ - BREAKING CHANGE: Default value for the `COMPONENTS.context_behavior` setting was changes from `"isolated"` to `"django"`. If you did not set this value explicitly before, this may be a breaking change. See the rationale for change [here](https://github.com/EmilStenstrom/django-components/issues/498).
74
+
75
+
71
76
  🚨📢 **Version 0.77** CHANGED the syntax for accessing default slot content.
72
77
  - Previously, the syntax was
73
78
  `{% fill "my_slot" as "alias" %}` and `{{ alias.default }}`.
@@ -1384,9 +1389,11 @@ attributes_to_string(attrs)
1384
1389
 
1385
1390
  ## Component context and scope
1386
1391
 
1387
- By default, components are ISOLATED and CANNOT access context variables from the parent template. This is useful if you want to make sure that components don't accidentally access the outer context.
1392
+ By default, context variables are passed down the template as in regular Django - deeper scopes can access the variables from the outer scopes. So if you have several nested forloops, then inside the deep-most loop you can access variables defined by all previous loops.
1388
1393
 
1389
- You can set the [context_behavior](#context-behavior) option to `"django"`, to make components behave just like templates that are included with the `{% include %}` tag. Just like with `{% include %}`, if you don't want a specific component template to have access to the parent context, add `only` to the end of the `{% component %}` tag:
1394
+ With this in mind, the `{% component %}` tag behaves similarly to `{% include %}` tag - inside the component tag, you can access all variables that were defined outside of it.
1395
+
1396
+ And just like with `{% include %}`, if you don't want a specific component template to have access to the parent context, add `only` to the end of the `{% component %}` tag:
1390
1397
 
1391
1398
  ```htmldjango
1392
1399
  {% component "calendar" date="2015-06-19" only %}{% endcomponent %}
@@ -1394,7 +1401,9 @@ You can set the [context_behavior](#context-behavior) option to `"django"`, to m
1394
1401
 
1395
1402
  NOTE: `{% csrf_token %}` tags need access to the top-level context, and they will not function properly if they are rendered in a component that is called with the `only` modifier.
1396
1403
 
1397
- Components can also access the outer context in their context methods by accessing the property `outer_context`.
1404
+ If you find yourself using the `only` modifier often, you can set the [context_behavior](#context-behavior) option to `"isolated"`, which automatically applies the `only` modifier. This is useful if you want to make sure that components don't accidentally access the outer context.
1405
+
1406
+ Components can also access the outer context in their context methods like `get_context_data` by accessing the property `self.outer_context`.
1398
1407
 
1399
1408
  ## Rendering JS and CSS dependencies
1400
1409
 
@@ -1472,15 +1481,25 @@ COMPONENTS = {
1472
1481
 
1473
1482
  > NOTE: `context_behavior` and `slot_context_behavior` options were merged in v0.70.
1474
1483
  >
1475
- > If you are migrating from BEFORE v0.67, set `context_behavior` to `"django"`. From v0.67 and later use the default value `"isolated"`.
1484
+ > If you are migrating from BEFORE v0.67, set `context_behavior` to `"django"`. From v0.67 to v0.78 (incl) the default value was `"isolated"`.
1485
+ >
1486
+ > For v0.79 and later, the default is again `"django"`. See the rationale for change [here](https://github.com/EmilStenstrom/django-components/issues/498).
1476
1487
 
1477
1488
  You can configure what variables are available inside the `{% fill %}` tags. See [Component context and scope](#component-context-and-scope).
1478
1489
 
1479
1490
  This has two modes:
1480
1491
 
1481
- - `"django"` - Context variables are taken from its surroundings (default before v0.67)
1492
+ - `"django"` - Default - The default Django template behavior.
1482
1493
 
1483
- - `"isolated"` - Default - Similar behavior to [Vue](https://vuejs.org/guide/components/slots.html#render-scope) or React - variables are taken ONLY from `get_context_data()` method of the component which defines the `{% fill %}` tag. This is useful if you want to make sure that components don't accidentally access the outer context.
1494
+ Inside the `{% fill %}` tag, the context variables you can access are a union of:
1495
+ - All the variables that were OUTSIDE the fill tag, including any loops or with tag
1496
+ - Data returned from `get_context_data()` of the component that wraps the fill tag.
1497
+
1498
+ - `"isolated"` - Similar behavior to [Vue](https://vuejs.org/guide/components/slots.html#render-scope) or React, this is useful if you want to make sure that components don't accidentally access variables defined outside of the component.
1499
+
1500
+ Inside the `{% fill %}` tag, you can ONLY access variables from 2 places:
1501
+ - `get_context_data()` of the component which defined the template (AKA the "root" component)
1502
+ - Any loops (`{% for ... %}`) that the `{% fill %}` tag is part of.
1484
1503
 
1485
1504
  ```python
1486
1505
  COMPONENTS = {
@@ -1490,75 +1509,76 @@ COMPONENTS = {
1490
1509
 
1491
1510
  #### Example "django"
1492
1511
 
1493
- Given this template
1494
-
1495
- ```django
1496
- {% with cheese="feta" %}
1497
- {% component 'my_comp' %}
1498
- {{ my_var }} # my_var
1499
- {{ cheese }} # cheese
1500
- {% endcomponent %}
1501
- {% endwith %}
1502
- ```
1503
-
1504
- and this context returned from the `get_context_data()` method
1512
+ Given this template:
1505
1513
 
1506
1514
  ```py
1507
- { "my_var": 123 }
1515
+ class RootComp(component.Component):
1516
+ template = """
1517
+ {% with cheese="feta" %}
1518
+ {% component 'my_comp' %}
1519
+ {{ my_var }} # my_var
1520
+ {{ cheese }} # cheese
1521
+ {% endcomponent %}
1522
+ {% endwith %}
1523
+ """
1524
+ def get_context_data(self):
1525
+ return { "my_var": 123 }
1508
1526
  ```
1509
1527
 
1510
- Then if component "my_comp" defines context
1528
+ Then if `get_context_data()` of the component `"my_comp"` returns following data:
1511
1529
 
1512
1530
  ```py
1513
1531
  { "my_var": 456 }
1514
1532
  ```
1515
1533
 
1516
- Then this will render:
1534
+ Then the template will be rendered as:
1517
1535
 
1518
1536
  ```django
1519
1537
  456 # my_var
1520
1538
  feta # cheese
1521
1539
  ```
1522
1540
 
1523
- Because "my_comp" overrides the variable "my_var",
1541
+ Because `"my_comp"` overshadows the variable `"my_var"`,
1524
1542
  so `{{ my_var }}` equals `456`.
1525
- And variable "cheese" equals `feta`, because the fill CAN access
1526
- the current context.
1527
1543
 
1528
- #### Example "isolated"
1529
-
1530
- Given this template
1544
+ And variable `"cheese"` equals `feta`, because the fill CAN access
1545
+ all the data defined in the outer layers, like the `{% with %}` tag.
1531
1546
 
1532
- ```django
1533
- {% with cheese="feta" %}
1534
- {% component 'my_comp' %}
1535
- {{ my_var }} # my_var
1536
- {{ cheese }} # cheese
1537
- {% endcomponent %}
1538
- {% endwith %}
1539
- ```
1547
+ #### Example "isolated"
1540
1548
 
1541
- and this context returned from the `get_context_data()` method
1549
+ Given this template:
1542
1550
 
1543
1551
  ```py
1544
- { "my_var": 123 }
1552
+ class RootComp(component.Component):
1553
+ template = """
1554
+ {% with cheese="feta" %}
1555
+ {% component 'my_comp' %}
1556
+ {{ my_var }} # my_var
1557
+ {{ cheese }} # cheese
1558
+ {% endcomponent %}
1559
+ {% endwith %}
1560
+ """
1561
+ def get_context_data(self):
1562
+ return { "my_var": 123 }
1545
1563
  ```
1546
1564
 
1547
- Then if component "my_comp" defines context
1565
+ Then if `get_context_data()` of the component `"my_comp"` returns following data:
1548
1566
 
1549
1567
  ```py
1550
1568
  { "my_var": 456 }
1551
1569
  ```
1552
1570
 
1553
- Then this will render:
1571
+ Then the template will be rendered as:
1554
1572
 
1555
1573
  ```django
1556
1574
  123 # my_var
1557
1575
  # cheese
1558
1576
  ```
1559
1577
 
1560
- Because both variables "my_var" and "cheese" are taken from the parent's `get_context_data()`.
1561
- But since "cheese" is not defined there, it's empty.
1578
+ Because variables `"my_var"` and `"cheese"` are searched only inside `RootComponent.get_context_data()`.
1579
+ But since `"cheese"` is not defined there, it's empty.
1580
+
1581
+ Notice that the variables defined with the `{% with %}` tag are ignored inside the `{% fill %}` tag with the `"isolated"` mode.
1562
1582
 
1563
1583
  ## Logging and debugging
1564
1584
 
@@ -44,6 +44,11 @@ Read on to learn about the details!
44
44
 
45
45
  ## Release notes
46
46
 
47
+ 🚨📢 **Version 0.79**
48
+
49
+ - BREAKING CHANGE: Default value for the `COMPONENTS.context_behavior` setting was changes from `"isolated"` to `"django"`. If you did not set this value explicitly before, this may be a breaking change. See the rationale for change [here](https://github.com/EmilStenstrom/django-components/issues/498).
50
+
51
+
47
52
  🚨📢 **Version 0.77** CHANGED the syntax for accessing default slot content.
48
53
  - Previously, the syntax was
49
54
  `{% fill "my_slot" as "alias" %}` and `{{ alias.default }}`.
@@ -1360,9 +1365,11 @@ attributes_to_string(attrs)
1360
1365
 
1361
1366
  ## Component context and scope
1362
1367
 
1363
- By default, components are ISOLATED and CANNOT access context variables from the parent template. This is useful if you want to make sure that components don't accidentally access the outer context.
1368
+ By default, context variables are passed down the template as in regular Django - deeper scopes can access the variables from the outer scopes. So if you have several nested forloops, then inside the deep-most loop you can access variables defined by all previous loops.
1364
1369
 
1365
- You can set the [context_behavior](#context-behavior) option to `"django"`, to make components behave just like templates that are included with the `{% include %}` tag. Just like with `{% include %}`, if you don't want a specific component template to have access to the parent context, add `only` to the end of the `{% component %}` tag:
1370
+ With this in mind, the `{% component %}` tag behaves similarly to `{% include %}` tag - inside the component tag, you can access all variables that were defined outside of it.
1371
+
1372
+ And just like with `{% include %}`, if you don't want a specific component template to have access to the parent context, add `only` to the end of the `{% component %}` tag:
1366
1373
 
1367
1374
  ```htmldjango
1368
1375
  {% component "calendar" date="2015-06-19" only %}{% endcomponent %}
@@ -1370,7 +1377,9 @@ You can set the [context_behavior](#context-behavior) option to `"django"`, to m
1370
1377
 
1371
1378
  NOTE: `{% csrf_token %}` tags need access to the top-level context, and they will not function properly if they are rendered in a component that is called with the `only` modifier.
1372
1379
 
1373
- Components can also access the outer context in their context methods by accessing the property `outer_context`.
1380
+ If you find yourself using the `only` modifier often, you can set the [context_behavior](#context-behavior) option to `"isolated"`, which automatically applies the `only` modifier. This is useful if you want to make sure that components don't accidentally access the outer context.
1381
+
1382
+ Components can also access the outer context in their context methods like `get_context_data` by accessing the property `self.outer_context`.
1374
1383
 
1375
1384
  ## Rendering JS and CSS dependencies
1376
1385
 
@@ -1448,15 +1457,25 @@ COMPONENTS = {
1448
1457
 
1449
1458
  > NOTE: `context_behavior` and `slot_context_behavior` options were merged in v0.70.
1450
1459
  >
1451
- > If you are migrating from BEFORE v0.67, set `context_behavior` to `"django"`. From v0.67 and later use the default value `"isolated"`.
1460
+ > If you are migrating from BEFORE v0.67, set `context_behavior` to `"django"`. From v0.67 to v0.78 (incl) the default value was `"isolated"`.
1461
+ >
1462
+ > For v0.79 and later, the default is again `"django"`. See the rationale for change [here](https://github.com/EmilStenstrom/django-components/issues/498).
1452
1463
 
1453
1464
  You can configure what variables are available inside the `{% fill %}` tags. See [Component context and scope](#component-context-and-scope).
1454
1465
 
1455
1466
  This has two modes:
1456
1467
 
1457
- - `"django"` - Context variables are taken from its surroundings (default before v0.67)
1468
+ - `"django"` - Default - The default Django template behavior.
1458
1469
 
1459
- - `"isolated"` - Default - Similar behavior to [Vue](https://vuejs.org/guide/components/slots.html#render-scope) or React - variables are taken ONLY from `get_context_data()` method of the component which defines the `{% fill %}` tag. This is useful if you want to make sure that components don't accidentally access the outer context.
1470
+ Inside the `{% fill %}` tag, the context variables you can access are a union of:
1471
+ - All the variables that were OUTSIDE the fill tag, including any loops or with tag
1472
+ - Data returned from `get_context_data()` of the component that wraps the fill tag.
1473
+
1474
+ - `"isolated"` - Similar behavior to [Vue](https://vuejs.org/guide/components/slots.html#render-scope) or React, this is useful if you want to make sure that components don't accidentally access variables defined outside of the component.
1475
+
1476
+ Inside the `{% fill %}` tag, you can ONLY access variables from 2 places:
1477
+ - `get_context_data()` of the component which defined the template (AKA the "root" component)
1478
+ - Any loops (`{% for ... %}`) that the `{% fill %}` tag is part of.
1460
1479
 
1461
1480
  ```python
1462
1481
  COMPONENTS = {
@@ -1466,75 +1485,76 @@ COMPONENTS = {
1466
1485
 
1467
1486
  #### Example "django"
1468
1487
 
1469
- Given this template
1470
-
1471
- ```django
1472
- {% with cheese="feta" %}
1473
- {% component 'my_comp' %}
1474
- {{ my_var }} # my_var
1475
- {{ cheese }} # cheese
1476
- {% endcomponent %}
1477
- {% endwith %}
1478
- ```
1479
-
1480
- and this context returned from the `get_context_data()` method
1488
+ Given this template:
1481
1489
 
1482
1490
  ```py
1483
- { "my_var": 123 }
1491
+ class RootComp(component.Component):
1492
+ template = """
1493
+ {% with cheese="feta" %}
1494
+ {% component 'my_comp' %}
1495
+ {{ my_var }} # my_var
1496
+ {{ cheese }} # cheese
1497
+ {% endcomponent %}
1498
+ {% endwith %}
1499
+ """
1500
+ def get_context_data(self):
1501
+ return { "my_var": 123 }
1484
1502
  ```
1485
1503
 
1486
- Then if component "my_comp" defines context
1504
+ Then if `get_context_data()` of the component `"my_comp"` returns following data:
1487
1505
 
1488
1506
  ```py
1489
1507
  { "my_var": 456 }
1490
1508
  ```
1491
1509
 
1492
- Then this will render:
1510
+ Then the template will be rendered as:
1493
1511
 
1494
1512
  ```django
1495
1513
  456 # my_var
1496
1514
  feta # cheese
1497
1515
  ```
1498
1516
 
1499
- Because "my_comp" overrides the variable "my_var",
1517
+ Because `"my_comp"` overshadows the variable `"my_var"`,
1500
1518
  so `{{ my_var }}` equals `456`.
1501
- And variable "cheese" equals `feta`, because the fill CAN access
1502
- the current context.
1503
1519
 
1504
- #### Example "isolated"
1505
-
1506
- Given this template
1520
+ And variable `"cheese"` equals `feta`, because the fill CAN access
1521
+ all the data defined in the outer layers, like the `{% with %}` tag.
1507
1522
 
1508
- ```django
1509
- {% with cheese="feta" %}
1510
- {% component 'my_comp' %}
1511
- {{ my_var }} # my_var
1512
- {{ cheese }} # cheese
1513
- {% endcomponent %}
1514
- {% endwith %}
1515
- ```
1523
+ #### Example "isolated"
1516
1524
 
1517
- and this context returned from the `get_context_data()` method
1525
+ Given this template:
1518
1526
 
1519
1527
  ```py
1520
- { "my_var": 123 }
1528
+ class RootComp(component.Component):
1529
+ template = """
1530
+ {% with cheese="feta" %}
1531
+ {% component 'my_comp' %}
1532
+ {{ my_var }} # my_var
1533
+ {{ cheese }} # cheese
1534
+ {% endcomponent %}
1535
+ {% endwith %}
1536
+ """
1537
+ def get_context_data(self):
1538
+ return { "my_var": 123 }
1521
1539
  ```
1522
1540
 
1523
- Then if component "my_comp" defines context
1541
+ Then if `get_context_data()` of the component `"my_comp"` returns following data:
1524
1542
 
1525
1543
  ```py
1526
1544
  { "my_var": 456 }
1527
1545
  ```
1528
1546
 
1529
- Then this will render:
1547
+ Then the template will be rendered as:
1530
1548
 
1531
1549
  ```django
1532
1550
  123 # my_var
1533
1551
  # cheese
1534
1552
  ```
1535
1553
 
1536
- Because both variables "my_var" and "cheese" are taken from the parent's `get_context_data()`.
1537
- But since "cheese" is not defined there, it's empty.
1554
+ Because variables `"my_var"` and `"cheese"` are searched only inside `RootComponent.get_context_data()`.
1555
+ But since `"cheese"` is not defined there, it's empty.
1556
+
1557
+ Notice that the variables defined with the `{% with %}` tag are ignored inside the `{% fill %}` tag with the `"isolated"` mode.
1538
1558
 
1539
1559
  ## Logging and debugging
1540
1560
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "django_components"
7
- version = "0.78"
7
+ version = "0.79"
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"]
@@ -105,7 +105,7 @@ class AppSettings:
105
105
 
106
106
  @property
107
107
  def CONTEXT_BEHAVIOR(self) -> ContextBehavior:
108
- raw_value = self.settings.get("context_behavior", ContextBehavior.ISOLATED.value)
108
+ raw_value = self.settings.get("context_behavior", ContextBehavior.DJANGO.value)
109
109
  return self._validate_context_behavior(raw_value)
110
110
 
111
111
  def _validate_context_behavior(self, raw_value: ContextBehavior) -> ContextBehavior:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django_components
3
- Version: 0.78
3
+ Version: 0.79
4
4
  Summary: A way to create simple reusable template components in Django.
5
5
  Author-email: Emil Stenström <emil@emilstenstrom.se>
6
6
  License: MIT
@@ -68,6 +68,11 @@ Read on to learn about the details!
68
68
 
69
69
  ## Release notes
70
70
 
71
+ 🚨📢 **Version 0.79**
72
+
73
+ - BREAKING CHANGE: Default value for the `COMPONENTS.context_behavior` setting was changes from `"isolated"` to `"django"`. If you did not set this value explicitly before, this may be a breaking change. See the rationale for change [here](https://github.com/EmilStenstrom/django-components/issues/498).
74
+
75
+
71
76
  🚨📢 **Version 0.77** CHANGED the syntax for accessing default slot content.
72
77
  - Previously, the syntax was
73
78
  `{% fill "my_slot" as "alias" %}` and `{{ alias.default }}`.
@@ -1384,9 +1389,11 @@ attributes_to_string(attrs)
1384
1389
 
1385
1390
  ## Component context and scope
1386
1391
 
1387
- By default, components are ISOLATED and CANNOT access context variables from the parent template. This is useful if you want to make sure that components don't accidentally access the outer context.
1392
+ By default, context variables are passed down the template as in regular Django - deeper scopes can access the variables from the outer scopes. So if you have several nested forloops, then inside the deep-most loop you can access variables defined by all previous loops.
1388
1393
 
1389
- You can set the [context_behavior](#context-behavior) option to `"django"`, to make components behave just like templates that are included with the `{% include %}` tag. Just like with `{% include %}`, if you don't want a specific component template to have access to the parent context, add `only` to the end of the `{% component %}` tag:
1394
+ With this in mind, the `{% component %}` tag behaves similarly to `{% include %}` tag - inside the component tag, you can access all variables that were defined outside of it.
1395
+
1396
+ And just like with `{% include %}`, if you don't want a specific component template to have access to the parent context, add `only` to the end of the `{% component %}` tag:
1390
1397
 
1391
1398
  ```htmldjango
1392
1399
  {% component "calendar" date="2015-06-19" only %}{% endcomponent %}
@@ -1394,7 +1401,9 @@ You can set the [context_behavior](#context-behavior) option to `"django"`, to m
1394
1401
 
1395
1402
  NOTE: `{% csrf_token %}` tags need access to the top-level context, and they will not function properly if they are rendered in a component that is called with the `only` modifier.
1396
1403
 
1397
- Components can also access the outer context in their context methods by accessing the property `outer_context`.
1404
+ If you find yourself using the `only` modifier often, you can set the [context_behavior](#context-behavior) option to `"isolated"`, which automatically applies the `only` modifier. This is useful if you want to make sure that components don't accidentally access the outer context.
1405
+
1406
+ Components can also access the outer context in their context methods like `get_context_data` by accessing the property `self.outer_context`.
1398
1407
 
1399
1408
  ## Rendering JS and CSS dependencies
1400
1409
 
@@ -1472,15 +1481,25 @@ COMPONENTS = {
1472
1481
 
1473
1482
  > NOTE: `context_behavior` and `slot_context_behavior` options were merged in v0.70.
1474
1483
  >
1475
- > If you are migrating from BEFORE v0.67, set `context_behavior` to `"django"`. From v0.67 and later use the default value `"isolated"`.
1484
+ > If you are migrating from BEFORE v0.67, set `context_behavior` to `"django"`. From v0.67 to v0.78 (incl) the default value was `"isolated"`.
1485
+ >
1486
+ > For v0.79 and later, the default is again `"django"`. See the rationale for change [here](https://github.com/EmilStenstrom/django-components/issues/498).
1476
1487
 
1477
1488
  You can configure what variables are available inside the `{% fill %}` tags. See [Component context and scope](#component-context-and-scope).
1478
1489
 
1479
1490
  This has two modes:
1480
1491
 
1481
- - `"django"` - Context variables are taken from its surroundings (default before v0.67)
1492
+ - `"django"` - Default - The default Django template behavior.
1482
1493
 
1483
- - `"isolated"` - Default - Similar behavior to [Vue](https://vuejs.org/guide/components/slots.html#render-scope) or React - variables are taken ONLY from `get_context_data()` method of the component which defines the `{% fill %}` tag. This is useful if you want to make sure that components don't accidentally access the outer context.
1494
+ Inside the `{% fill %}` tag, the context variables you can access are a union of:
1495
+ - All the variables that were OUTSIDE the fill tag, including any loops or with tag
1496
+ - Data returned from `get_context_data()` of the component that wraps the fill tag.
1497
+
1498
+ - `"isolated"` - Similar behavior to [Vue](https://vuejs.org/guide/components/slots.html#render-scope) or React, this is useful if you want to make sure that components don't accidentally access variables defined outside of the component.
1499
+
1500
+ Inside the `{% fill %}` tag, you can ONLY access variables from 2 places:
1501
+ - `get_context_data()` of the component which defined the template (AKA the "root" component)
1502
+ - Any loops (`{% for ... %}`) that the `{% fill %}` tag is part of.
1484
1503
 
1485
1504
  ```python
1486
1505
  COMPONENTS = {
@@ -1490,75 +1509,76 @@ COMPONENTS = {
1490
1509
 
1491
1510
  #### Example "django"
1492
1511
 
1493
- Given this template
1494
-
1495
- ```django
1496
- {% with cheese="feta" %}
1497
- {% component 'my_comp' %}
1498
- {{ my_var }} # my_var
1499
- {{ cheese }} # cheese
1500
- {% endcomponent %}
1501
- {% endwith %}
1502
- ```
1503
-
1504
- and this context returned from the `get_context_data()` method
1512
+ Given this template:
1505
1513
 
1506
1514
  ```py
1507
- { "my_var": 123 }
1515
+ class RootComp(component.Component):
1516
+ template = """
1517
+ {% with cheese="feta" %}
1518
+ {% component 'my_comp' %}
1519
+ {{ my_var }} # my_var
1520
+ {{ cheese }} # cheese
1521
+ {% endcomponent %}
1522
+ {% endwith %}
1523
+ """
1524
+ def get_context_data(self):
1525
+ return { "my_var": 123 }
1508
1526
  ```
1509
1527
 
1510
- Then if component "my_comp" defines context
1528
+ Then if `get_context_data()` of the component `"my_comp"` returns following data:
1511
1529
 
1512
1530
  ```py
1513
1531
  { "my_var": 456 }
1514
1532
  ```
1515
1533
 
1516
- Then this will render:
1534
+ Then the template will be rendered as:
1517
1535
 
1518
1536
  ```django
1519
1537
  456 # my_var
1520
1538
  feta # cheese
1521
1539
  ```
1522
1540
 
1523
- Because "my_comp" overrides the variable "my_var",
1541
+ Because `"my_comp"` overshadows the variable `"my_var"`,
1524
1542
  so `{{ my_var }}` equals `456`.
1525
- And variable "cheese" equals `feta`, because the fill CAN access
1526
- the current context.
1527
1543
 
1528
- #### Example "isolated"
1529
-
1530
- Given this template
1544
+ And variable `"cheese"` equals `feta`, because the fill CAN access
1545
+ all the data defined in the outer layers, like the `{% with %}` tag.
1531
1546
 
1532
- ```django
1533
- {% with cheese="feta" %}
1534
- {% component 'my_comp' %}
1535
- {{ my_var }} # my_var
1536
- {{ cheese }} # cheese
1537
- {% endcomponent %}
1538
- {% endwith %}
1539
- ```
1547
+ #### Example "isolated"
1540
1548
 
1541
- and this context returned from the `get_context_data()` method
1549
+ Given this template:
1542
1550
 
1543
1551
  ```py
1544
- { "my_var": 123 }
1552
+ class RootComp(component.Component):
1553
+ template = """
1554
+ {% with cheese="feta" %}
1555
+ {% component 'my_comp' %}
1556
+ {{ my_var }} # my_var
1557
+ {{ cheese }} # cheese
1558
+ {% endcomponent %}
1559
+ {% endwith %}
1560
+ """
1561
+ def get_context_data(self):
1562
+ return { "my_var": 123 }
1545
1563
  ```
1546
1564
 
1547
- Then if component "my_comp" defines context
1565
+ Then if `get_context_data()` of the component `"my_comp"` returns following data:
1548
1566
 
1549
1567
  ```py
1550
1568
  { "my_var": 456 }
1551
1569
  ```
1552
1570
 
1553
- Then this will render:
1571
+ Then the template will be rendered as:
1554
1572
 
1555
1573
  ```django
1556
1574
  123 # my_var
1557
1575
  # cheese
1558
1576
  ```
1559
1577
 
1560
- Because both variables "my_var" and "cheese" are taken from the parent's `get_context_data()`.
1561
- But since "cheese" is not defined there, it's empty.
1578
+ Because variables `"my_var"` and `"cheese"` are searched only inside `RootComponent.get_context_data()`.
1579
+ But since `"cheese"` is not defined there, it's empty.
1580
+
1581
+ Notice that the variables defined with the `{% with %}` tag are ignored inside the `{% fill %}` tag with the `"isolated"` mode.
1562
1582
 
1563
1583
  ## Logging and debugging
1564
1584