Skip to content

Commit

Permalink
replace FilterExpression()'s with parser.compile_filter()
Browse files Browse the repository at this point in the history
  • Loading branch information
g-nie committed Nov 20, 2024
1 parent d2012f1 commit 7ac44f1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/django_xinclude/templatetags/xinclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import uuid
from typing import TYPE_CHECKING, Any

from django.template.base import FilterExpression, Parser, Token, Variable
from django.template.base import Parser, Token, Variable
from django.template.library import Library
from django.template.loader_tags import IncludeNode, do_include
from django.urls import reverse
Expand All @@ -16,7 +16,7 @@
from collections.abc import KeysView

from django.contrib.auth.models import AbstractUser, AnonymousUser
from django.template.base import NodeList
from django.template.base import FilterExpression, NodeList
from django.template.context import RequestContext
from django.utils.safestring import SafeString

Expand All @@ -34,7 +34,7 @@ class SpecialVariables:
def make_context_defaults(cls, ctx: dict[str, Any], parser: Parser) -> None:
for key, val in cls._vars.items():
if val is not None:
ctx.setdefault(key, FilterExpression(f'"{val}"', parser))
ctx.setdefault(key, parser.compile_filter(f'"{val}"'))

@classmethod
def keys(cls) -> KeysView[str]:
Expand Down Expand Up @@ -156,15 +156,15 @@ def do_xinclude(parser: Parser, token: Token) -> HtmxIncludeNode:
remaining_bits.append(option)
continue
if key in SpecialVariables.raw_list():
options[key.replace("-", "_")] = FilterExpression(value, parser)
options[key.replace("-", "_")] = parser.compile_filter(value)
else:
remaining_bits.append(option)

token = Token(
token.token_type, " ".join(remaining_bits), token.position, token.lineno
)
node = do_include(parser, token) # the regular IncludeNode
template = FilterExpression('"django_xinclude/include.html"', parser)
template = parser.compile_filter('"django_xinclude/include.html"')
context = {**node.extra_context, **options}
# add the variable defaults to context
SpecialVariables.make_context_defaults(context, parser)
Expand Down

0 comments on commit 7ac44f1

Please sign in to comment.