From 390b16f76459093a3282f05f94c8ab87333c8cdf Mon Sep 17 00:00:00 2001 From: Juro Oravec Date: Mon, 15 Apr 2024 13:24:40 +0200 Subject: [PATCH] refactor: fix minor errors --- src/django_components/component.py | 9 ++++++++- src/django_components/slots.py | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/django_components/component.py b/src/django_components/component.py index 66ad82cf..4974b78e 100644 --- a/src/django_components/component.py +++ b/src/django_components/component.py @@ -22,7 +22,14 @@ from django_components.component_registry import registry # NOQA from django_components.component_registry import AlreadyRegistered, ComponentRegistry, NotRegistered, register # NOQA from django_components.logger import logger from django_components.middleware import is_dependency_middleware_active -from django_components.slots import FillContent, FillNode, SlotName, render_component_template_with_slots +from django_components.slots import ( + FillContent, + FillNode, + SlotName, + render_component_template_with_slots, + OUTER_CONTEXT_CONTEXT_KEY, + DEFAULT_SLOT_KEY, +) from django_components.utils import search RENDERED_COMMENT_TEMPLATE = "" diff --git a/src/django_components/slots.py b/src/django_components/slots.py index afd75ce0..ac188659 100644 --- a/src/django_components/slots.py +++ b/src/django_components/slots.py @@ -14,7 +14,7 @@ else: from typing import TypeAlias from django.template import Context, Template -from django.template.base import FilterExpression, Node, NodeList, Parser, TextNode +from django.template.base import FilterExpression, Node, NodeList, TextNode, Parser from django.template.defaulttags import CommentNode from django.template.exceptions import TemplateSyntaxError from django.utils.safestring import SafeString, mark_safe @@ -143,8 +143,8 @@ class SlotNode(Node, TemplateAwareNodeMixin): elif app_settings.SLOT_CONTEXT_BEHAVIOR == SlotContextBehavior.ISOLATED: return root_ctx elif app_settings.SLOT_CONTEXT_BEHAVIOR == SlotContextBehavior.PREFER_ROOT: - new_context = context.__copy__() - new_context.push(root_ctx) + new_context: Context = context.__copy__() + new_context.update(root_ctx) return new_context else: raise ValueError(f"Unknown value for SLOT_CONTEXT_BEHAVIOR: '{app_settings.SLOT_CONTEXT_BEHAVIOR}'")