[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-06-02 14:23:56 +00:00
parent 5f07f3d4da
commit a5a0c74d31
4 changed files with 7 additions and 8 deletions

View file

@ -202,6 +202,7 @@ class Component(View, metaclass=SimplifiedInterfaceMediaDefiningClass):
class Media:
"""Defines JS and CSS media files associated with this component."""
css: Optional[Union[str, List[str], Dict[str, str], Dict[str, List[str]]]] = None
js: Optional[Union[str, List[str]]] = None
@ -492,14 +493,13 @@ class Component(View, metaclass=SimplifiedInterfaceMediaDefiningClass):
) -> Dict[SlotName, FillContent]:
"""Fill component slots outside of template rendering."""
slot_fills = {}
for (slot_name, content) in slots_data.items():
for slot_name, content in slots_data.items():
if isinstance(content, (str, SafeString)):
content_func = nodelist_to_render_func(
NodeList([
TextNode(escape(content) if escape_content else content)
])
NodeList([TextNode(escape(content) if escape_content else content)])
)
else:
def content_func(ctx: Context) -> RenderedContent:
rendered = content(ctx)
return escape(rendered) if escape_content else rendered

View file

@ -13,6 +13,7 @@ RenderFunc = Callable[[Context], RenderedContent]
def nodelist_to_render_func(nodelist: NodeList) -> RenderFunc:
def render_func(ctx: Context) -> RenderedContent:
return nodelist.render(ctx)
return render_func

View file

@ -3,8 +3,8 @@ Tests focusing on the Component class.
For tests focusing on the `component` tag, see `test_templatetags_component.py`
"""
from django.http import HttpResponse
from django.core.exceptions import ImproperlyConfigured
from django.http import HttpResponse
from django.template import Context, Template, TemplateSyntaxError
# isort: off

View file

@ -141,9 +141,7 @@ class InlineComponentTest(BaseTestCase):
"var2": var2,
}
rendered = FilteredComponent.render(
kwargs={"var1": "test1", "var2": "test2"}
)
rendered = FilteredComponent.render(kwargs={"var1": "test1", "var2": "test2"})
self.assertHTMLEqual(
rendered,
"""