From c0c9e145a97743e94cf885c583f2da36825064ef Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 08:07:45 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/django_components/component.py | 16 +++++++--------- src/django_components/slots.py | 5 +++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/django_components/component.py b/src/django_components/component.py index 2f7ba442..509c9c89 100644 --- a/src/django_components/component.py +++ b/src/django_components/component.py @@ -23,13 +23,13 @@ from django_components.component_registry import AlreadyRegistered, ComponentReg from django_components.logger import logger from django_components.middleware import is_dependency_middleware_active from django_components.slots import ( + DEFAULT_SLOT_KEY, + OUTER_CONTEXT_CONTEXT_KEY, + FillContent, ImplicitFillNode, NamedFillNode, - FillContent, SlotName, render_component_template_with_slots, - OUTER_CONTEXT_CONTEXT_KEY, - DEFAULT_SLOT_KEY, ) from django_components.utils import search @@ -322,7 +322,7 @@ class ComponentNode(Node): # so it can be used by nested Slots. root_ctx_already_defined = OUTER_CONTEXT_CONTEXT_KEY in context if not root_ctx_already_defined: - context.push({ OUTER_CONTEXT_CONTEXT_KEY: context.__copy__() }) + context.push({OUTER_CONTEXT_CONTEXT_KEY: context.__copy__()}) # Resolve FilterExpressions and Variables that were passed as args to the # component, then call component's context method @@ -331,9 +331,7 @@ class ComponentNode(Node): resolved_context_kwargs = {key: safe_resolve(kwarg, context) for key, kwarg in self.context_kwargs.items()} if len(self.fill_nodes) == 1 and isinstance(self.fill_nodes[0], ImplicitFillNode): - fill_content: Dict[str, FillContent] = { - DEFAULT_SLOT_KEY: FillContent(self.fill_nodes[0].nodelist, None) - } + fill_content: Dict[str, FillContent] = {DEFAULT_SLOT_KEY: FillContent(self.fill_nodes[0].nodelist, None)} else: fill_content = {} for fill_node in self.fill_nodes: @@ -358,8 +356,8 @@ class ComponentNode(Node): # the original context. orig_ctx = context context = context.new() - context.push({ OUTER_CONTEXT_CONTEXT_KEY: orig_ctx }) - + context.push({OUTER_CONTEXT_CONTEXT_KEY: orig_ctx}) + with context.update(component_context): rendered_component = component.render(context) diff --git a/src/django_components/slots.py b/src/django_components/slots.py index fe9fa5c5..c83bec84 100644 --- a/src/django_components/slots.py +++ b/src/django_components/slots.py @@ -18,7 +18,7 @@ from django.template.defaulttags import CommentNode from django.template.exceptions import TemplateSyntaxError from django.utils.safestring import SafeString, mark_safe -from django_components.app_settings import app_settings, SlotContextBehavior +from django_components.app_settings import SlotContextBehavior, app_settings FILLED_SLOTS_CONTENT_CONTEXT_KEY = "_DJANGO_COMPONENTS_FILLED_SLOTS" DEFAULT_SLOT_KEY = "_DJANGO_COMPONENTS_DEFAULT_SLOT" @@ -32,6 +32,7 @@ AliasName = str class FillContent(NamedTuple): """Data passed from component to slot to render that slot""" + nodes: NodeList alias: Optional[AliasName] @@ -127,7 +128,7 @@ class SlotNode(Node, TemplateAwareNodeMixin): used_ctx = self.resolve_slot_context(context) with used_ctx.update(extra_context): return nodelist.render(used_ctx) - + def resolve_slot_context(self, context: Context) -> Context: """ Prepare the context used in a slot fill based on the settings.