django-components 0.88__tar.gz → 0.89__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 (57) hide show
  1. {django_components-0.88/src/django_components.egg-info → django_components-0.89}/PKG-INFO +2 -2
  2. {django_components-0.88 → django_components-0.89}/README.md +1 -1
  3. {django_components-0.88 → django_components-0.89}/pyproject.toml +1 -1
  4. {django_components-0.88 → django_components-0.89}/src/django_components/component.py +8 -10
  5. {django_components-0.88 → django_components-0.89/src/django_components.egg-info}/PKG-INFO +2 -2
  6. {django_components-0.88 → django_components-0.89}/tests/test_component.py +46 -2
  7. {django_components-0.88 → django_components-0.89}/LICENSE +0 -0
  8. {django_components-0.88 → django_components-0.89}/setup.cfg +0 -0
  9. {django_components-0.88 → django_components-0.89}/src/django_components/__init__.py +0 -0
  10. {django_components-0.88 → django_components-0.89}/src/django_components/app_settings.py +0 -0
  11. {django_components-0.88 → django_components-0.89}/src/django_components/apps.py +0 -0
  12. {django_components-0.88 → django_components-0.89}/src/django_components/attributes.py +0 -0
  13. {django_components-0.88 → django_components-0.89}/src/django_components/autodiscover.py +0 -0
  14. {django_components-0.88 → django_components-0.89}/src/django_components/component_media.py +0 -0
  15. {django_components-0.88 → django_components-0.89}/src/django_components/component_registry.py +0 -0
  16. {django_components-0.88 → django_components-0.89}/src/django_components/context.py +0 -0
  17. {django_components-0.88 → django_components-0.89}/src/django_components/expression.py +0 -0
  18. {django_components-0.88 → django_components-0.89}/src/django_components/logger.py +0 -0
  19. {django_components-0.88 → django_components-0.89}/src/django_components/management/__init__.py +0 -0
  20. {django_components-0.88 → django_components-0.89}/src/django_components/management/commands/__init__.py +0 -0
  21. {django_components-0.88 → django_components-0.89}/src/django_components/management/commands/startcomponent.py +0 -0
  22. {django_components-0.88 → django_components-0.89}/src/django_components/management/commands/upgradecomponent.py +0 -0
  23. {django_components-0.88 → django_components-0.89}/src/django_components/middleware.py +0 -0
  24. {django_components-0.88 → django_components-0.89}/src/django_components/node.py +0 -0
  25. {django_components-0.88 → django_components-0.89}/src/django_components/provide.py +0 -0
  26. {django_components-0.88 → django_components-0.89}/src/django_components/py.typed +0 -0
  27. {django_components-0.88 → django_components-0.89}/src/django_components/safer_staticfiles/__init__.py +0 -0
  28. {django_components-0.88 → django_components-0.89}/src/django_components/safer_staticfiles/apps.py +0 -0
  29. {django_components-0.88 → django_components-0.89}/src/django_components/slots.py +0 -0
  30. {django_components-0.88 → django_components-0.89}/src/django_components/template_loader.py +0 -0
  31. {django_components-0.88 → django_components-0.89}/src/django_components/template_parser.py +0 -0
  32. {django_components-0.88 → django_components-0.89}/src/django_components/templatetags/__init__.py +0 -0
  33. {django_components-0.88 → django_components-0.89}/src/django_components/templatetags/component_tags.py +0 -0
  34. {django_components-0.88 → django_components-0.89}/src/django_components/types.py +0 -0
  35. {django_components-0.88 → django_components-0.89}/src/django_components/utils.py +0 -0
  36. {django_components-0.88 → django_components-0.89}/src/django_components.egg-info/SOURCES.txt +0 -0
  37. {django_components-0.88 → django_components-0.89}/src/django_components.egg-info/dependency_links.txt +0 -0
  38. {django_components-0.88 → django_components-0.89}/src/django_components.egg-info/requires.txt +0 -0
  39. {django_components-0.88 → django_components-0.89}/src/django_components.egg-info/top_level.txt +0 -0
  40. {django_components-0.88 → django_components-0.89}/tests/test_attributes.py +0 -0
  41. {django_components-0.88 → django_components-0.89}/tests/test_autodiscover.py +0 -0
  42. {django_components-0.88 → django_components-0.89}/tests/test_command_startcomponent.py +0 -0
  43. {django_components-0.88 → django_components-0.89}/tests/test_component_as_view.py +0 -0
  44. {django_components-0.88 → django_components-0.89}/tests/test_component_media.py +0 -0
  45. {django_components-0.88 → django_components-0.89}/tests/test_context.py +0 -0
  46. {django_components-0.88 → django_components-0.89}/tests/test_dependency_rendering.py +0 -0
  47. {django_components-0.88 → django_components-0.89}/tests/test_registry.py +0 -0
  48. {django_components-0.88 → django_components-0.89}/tests/test_safer_staticfiles.py +0 -0
  49. {django_components-0.88 → django_components-0.89}/tests/test_settings.py +0 -0
  50. {django_components-0.88 → django_components-0.89}/tests/test_template_loader.py +0 -0
  51. {django_components-0.88 → django_components-0.89}/tests/test_template_parser.py +0 -0
  52. {django_components-0.88 → django_components-0.89}/tests/test_templatetags.py +0 -0
  53. {django_components-0.88 → django_components-0.89}/tests/test_templatetags_component.py +0 -0
  54. {django_components-0.88 → django_components-0.89}/tests/test_templatetags_provide.py +0 -0
  55. {django_components-0.88 → django_components-0.89}/tests/test_templatetags_slot_fill.py +0 -0
  56. {django_components-0.88 → django_components-0.89}/tests/test_templatetags_templating.py +0 -0
  57. {django_components-0.88 → django_components-0.89}/tests/testutils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django_components
3
- Version: 0.88
3
+ Version: 0.89
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
@@ -140,7 +140,7 @@ You probably don't want this, as parts of your backend logic will be exposed, po
140
140
  As of _v0.27_, django-components ships with an additional installable app _django_components.**safer_staticfiles**_.
141
141
  It is a drop-in replacement for _django.contrib.staticfiles_.
142
142
  Its behavior is 100% identical except it ignores .py and .html files, meaning these will not end up on your static files server.
143
- To use it, add it to INSTALLED*APPS and remove \_django.contrib.staticfiles*.
143
+ To use it, add it to INSTALLED_APPS and remove _django.contrib.staticfiles_.
144
144
 
145
145
  ```python
146
146
  INSTALLED_APPS = [
@@ -116,7 +116,7 @@ You probably don't want this, as parts of your backend logic will be exposed, po
116
116
  As of _v0.27_, django-components ships with an additional installable app _django_components.**safer_staticfiles**_.
117
117
  It is a drop-in replacement for _django.contrib.staticfiles_.
118
118
  Its behavior is 100% identical except it ignores .py and .html files, meaning these will not end up on your static files server.
119
- To use it, add it to INSTALLED*APPS and remove \_django.contrib.staticfiles*.
119
+ To use it, add it to INSTALLED_APPS and remove _django.contrib.staticfiles_.
120
120
 
121
121
  ```python
122
122
  INSTALLED_APPS = [
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "django_components"
7
- version = "0.88"
7
+ version = "0.89"
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"]
@@ -362,15 +362,11 @@ class Component(View, metaclass=ComponentMeta):
362
362
  slots: Optional[Mapping[SlotName, SlotContent]] = None,
363
363
  escape_slots_content: bool = True,
364
364
  ) -> str:
365
- # Allow to provide no args/kwargs
366
- args = args or []
367
- kwargs = kwargs or {}
368
-
369
- # Allow to provide no Context, so we can render component just with args + kwargs
370
- context_was_given = True
371
- if context is None:
372
- context = Context()
373
- context_was_given = False
365
+ # Allow to provide no args/kwargs/slots/context
366
+ args = args or [] # type: ignore[assignment]
367
+ kwargs = kwargs or {} # type: ignore[assignment]
368
+ slots = slots or {} # type: ignore[assignment]
369
+ context = context or Context()
374
370
 
375
371
  # Allow to provide a dict instead of Context
376
372
  # NOTE: This if/else is important to avoid nested Contexts,
@@ -387,9 +383,11 @@ class Component(View, metaclass=ComponentMeta):
387
383
  with context.update(context_data):
388
384
  template = self.get_template(context)
389
385
  _monkeypatch_template(template)
390
- if not context_was_given:
386
+
387
+ if context.template is None:
391
388
  # Associate the newly-created Context with a Template, otherwise we get
392
389
  # an error when we try to use `{% include %}` tag inside the template?
390
+ # See https://github.com/EmilStenstrom/django-components/issues/580
393
391
  context.template = template
394
392
  context.template_name = template.name
395
393
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django_components
3
- Version: 0.88
3
+ Version: 0.89
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
@@ -140,7 +140,7 @@ You probably don't want this, as parts of your backend logic will be exposed, po
140
140
  As of _v0.27_, django-components ships with an additional installable app _django_components.**safer_staticfiles**_.
141
141
  It is a drop-in replacement for _django.contrib.staticfiles_.
142
142
  Its behavior is 100% identical except it ignores .py and .html files, meaning these will not end up on your static files server.
143
- To use it, add it to INSTALLED*APPS and remove \_django.contrib.staticfiles*.
143
+ To use it, add it to INSTALLED_APPS and remove _django.contrib.staticfiles_.
144
144
 
145
145
  ```python
146
146
  INSTALLED_APPS = [
@@ -6,8 +6,8 @@ For tests focusing on the `component` tag, see `test_templatetags_component.py`
6
6
  from typing import Dict
7
7
 
8
8
  from django.core.exceptions import ImproperlyConfigured
9
- from django.http import HttpResponse
10
- from django.template import Context, Template, TemplateSyntaxError
9
+ from django.http import HttpRequest, HttpResponse
10
+ from django.template import Context, RequestContext, Template, TemplateSyntaxError
11
11
 
12
12
  from django_components import Component, registry, types
13
13
  from django_components.slots import SlotRef
@@ -448,6 +448,50 @@ class ComponentRenderTest(BaseTestCase):
448
448
  """,
449
449
  )
450
450
 
451
+ # See https://github.com/EmilStenstrom/django-components/issues/580
452
+ # And https://github.com/EmilStenstrom/django-components/commit/fee26ec1d8b46b5ee065ca1ce6143889b0f96764
453
+ @parametrize_context_behavior(["django", "isolated"])
454
+ def test_render_with_include_and_context(self):
455
+ class SimpleComponent(Component):
456
+ template: types.django_html = """
457
+ {% load component_tags %}
458
+ {% include 'slotted_template.html' %}
459
+ """
460
+
461
+ rendered = SimpleComponent.render(context=Context())
462
+ self.assertHTMLEqual(
463
+ rendered,
464
+ """
465
+ <custom-template>
466
+ <header>Default header</header>
467
+ <main>Default main</main>
468
+ <footer>Default footer</footer>
469
+ </custom-template>
470
+ """,
471
+ )
472
+
473
+ # See https://github.com/EmilStenstrom/django-components/issues/580
474
+ # And https://github.com/EmilStenstrom/django-components/commit/fee26ec1d8b46b5ee065ca1ce6143889b0f96764
475
+ @parametrize_context_behavior(["django", "isolated"])
476
+ def test_render_with_include_and_request_context(self):
477
+ class SimpleComponent(Component):
478
+ template: types.django_html = """
479
+ {% load component_tags %}
480
+ {% include 'slotted_template.html' %}
481
+ """
482
+
483
+ rendered = SimpleComponent.render(context=RequestContext(HttpRequest()))
484
+ self.assertHTMLEqual(
485
+ rendered,
486
+ """
487
+ <custom-template>
488
+ <header>Default header</header>
489
+ <main>Default main</main>
490
+ <footer>Default footer</footer>
491
+ </custom-template>
492
+ """,
493
+ )
494
+
451
495
  @parametrize_context_behavior(["django", "isolated"])
452
496
  def test_render_with_extends(self):
453
497
  class SimpleComponent(Component):