mirror of
https://github.com/django-components/django-components.git
synced 2025-08-09 00:37:59 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
d297249d9f
commit
c0c9e145a9
2 changed files with 10 additions and 11 deletions
|
@ -23,13 +23,13 @@ from django_components.component_registry import AlreadyRegistered, ComponentReg
|
||||||
from django_components.logger import logger
|
from django_components.logger import logger
|
||||||
from django_components.middleware import is_dependency_middleware_active
|
from django_components.middleware import is_dependency_middleware_active
|
||||||
from django_components.slots import (
|
from django_components.slots import (
|
||||||
|
DEFAULT_SLOT_KEY,
|
||||||
|
OUTER_CONTEXT_CONTEXT_KEY,
|
||||||
|
FillContent,
|
||||||
ImplicitFillNode,
|
ImplicitFillNode,
|
||||||
NamedFillNode,
|
NamedFillNode,
|
||||||
FillContent,
|
|
||||||
SlotName,
|
SlotName,
|
||||||
render_component_template_with_slots,
|
render_component_template_with_slots,
|
||||||
OUTER_CONTEXT_CONTEXT_KEY,
|
|
||||||
DEFAULT_SLOT_KEY,
|
|
||||||
)
|
)
|
||||||
from django_components.utils import search
|
from django_components.utils import search
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ class ComponentNode(Node):
|
||||||
# so it can be used by nested Slots.
|
# so it can be used by nested Slots.
|
||||||
root_ctx_already_defined = OUTER_CONTEXT_CONTEXT_KEY in context
|
root_ctx_already_defined = OUTER_CONTEXT_CONTEXT_KEY in context
|
||||||
if not root_ctx_already_defined:
|
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
|
# Resolve FilterExpressions and Variables that were passed as args to the
|
||||||
# component, then call component's context method
|
# 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()}
|
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):
|
if len(self.fill_nodes) == 1 and isinstance(self.fill_nodes[0], ImplicitFillNode):
|
||||||
fill_content: Dict[str, FillContent] = {
|
fill_content: Dict[str, FillContent] = {DEFAULT_SLOT_KEY: FillContent(self.fill_nodes[0].nodelist, None)}
|
||||||
DEFAULT_SLOT_KEY: FillContent(self.fill_nodes[0].nodelist, None)
|
|
||||||
}
|
|
||||||
else:
|
else:
|
||||||
fill_content = {}
|
fill_content = {}
|
||||||
for fill_node in self.fill_nodes:
|
for fill_node in self.fill_nodes:
|
||||||
|
@ -358,8 +356,8 @@ class ComponentNode(Node):
|
||||||
# the original context.
|
# the original context.
|
||||||
orig_ctx = context
|
orig_ctx = context
|
||||||
context = context.new()
|
context = context.new()
|
||||||
context.push({ OUTER_CONTEXT_CONTEXT_KEY: orig_ctx })
|
context.push({OUTER_CONTEXT_CONTEXT_KEY: orig_ctx})
|
||||||
|
|
||||||
with context.update(component_context):
|
with context.update(component_context):
|
||||||
rendered_component = component.render(context)
|
rendered_component = component.render(context)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ from django.template.defaulttags import CommentNode
|
||||||
from django.template.exceptions import TemplateSyntaxError
|
from django.template.exceptions import TemplateSyntaxError
|
||||||
from django.utils.safestring import SafeString, mark_safe
|
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"
|
FILLED_SLOTS_CONTENT_CONTEXT_KEY = "_DJANGO_COMPONENTS_FILLED_SLOTS"
|
||||||
DEFAULT_SLOT_KEY = "_DJANGO_COMPONENTS_DEFAULT_SLOT"
|
DEFAULT_SLOT_KEY = "_DJANGO_COMPONENTS_DEFAULT_SLOT"
|
||||||
|
@ -32,6 +32,7 @@ AliasName = str
|
||||||
|
|
||||||
class FillContent(NamedTuple):
|
class FillContent(NamedTuple):
|
||||||
"""Data passed from component to slot to render that slot"""
|
"""Data passed from component to slot to render that slot"""
|
||||||
|
|
||||||
nodes: NodeList
|
nodes: NodeList
|
||||||
alias: Optional[AliasName]
|
alias: Optional[AliasName]
|
||||||
|
|
||||||
|
@ -127,7 +128,7 @@ class SlotNode(Node, TemplateAwareNodeMixin):
|
||||||
used_ctx = self.resolve_slot_context(context)
|
used_ctx = self.resolve_slot_context(context)
|
||||||
with used_ctx.update(extra_context):
|
with used_ctx.update(extra_context):
|
||||||
return nodelist.render(used_ctx)
|
return nodelist.render(used_ctx)
|
||||||
|
|
||||||
def resolve_slot_context(self, context: Context) -> Context:
|
def resolve_slot_context(self, context: Context) -> Context:
|
||||||
"""
|
"""
|
||||||
Prepare the context used in a slot fill based on the settings.
|
Prepare the context used in a slot fill based on the settings.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue