1
0
mirror of https://github.com/django/django.git synced 2025-03-31 19:46:42 +00:00

Refs #35738 -- Refactored code to meet the standards.

This commit is contained in:
sanjeevholla26 2024-09-07 10:32:11 +05:30
parent fea2c90322
commit 70707e2fc7

View File

@ -54,7 +54,6 @@ import inspect
import logging import logging
import re import re
import warnings import warnings
from django.utils.deprecation import RemovedInDjango61Warning
from enum import Enum from enum import Enum
from django.template.context import BaseContext from django.template.context import BaseContext
@ -65,6 +64,7 @@ from django.utils.safestring import SafeData, SafeString, mark_safe
from django.utils.text import get_text_list, smart_split, unescape_string_literal from django.utils.text import get_text_list, smart_split, unescape_string_literal
from django.utils.timezone import template_localtime from django.utils.timezone import template_localtime
from django.utils.translation import gettext_lazy, pgettext_lazy from django.utils.translation import gettext_lazy, pgettext_lazy
from django.utils.deprecation import RemovedInDjango61Warning
from .exceptions import TemplateSyntaxError from .exceptions import TemplateSyntaxError
@ -488,7 +488,9 @@ class Parser:
token, "Empty variable tag on line %d" % token.lineno token, "Empty variable tag on line %d" % token.lineno
) )
try: try:
filter_expression = self.compile_filter(token.contents, token.lineno) filter_expression = self.compile_filter(
token.contents, token.lineno
)
except TemplateSyntaxError as e: except TemplateSyntaxError as e:
raise self.error(token, e) raise self.error(token, e)
var_node = VariableNode(filter_expression) var_node = VariableNode(filter_expression)
@ -700,7 +702,9 @@ class FilterExpression:
filter_name = match["filter_name"] filter_name = match["filter_name"]
args = [] args = []
if constant_arg := match["constant_arg"]: if constant_arg := match["constant_arg"]:
args.append((False, Variable(constant_arg, self.lineno).resolve({}))) args.append(
(False, Variable(constant_arg, self.lineno).resolve({}))
)
elif var_arg := match["var_arg"]: elif var_arg := match["var_arg"]:
args.append((True, Variable(var_arg, self.lineno))) args.append((True, Variable(var_arg, self.lineno)))
filter_func = parser.find_filter(filter_name) filter_func = parser.find_filter(filter_name)
@ -857,7 +861,7 @@ class Variable:
f"Double-dot lookup (e.g., '{{{{ {var} }}}}') in template {engine.current_template_name}[{self.lineno}] " f"Double-dot lookup (e.g., '{{{{ {var} }}}}') in template {engine.current_template_name}[{self.lineno}] "
"is deprecated.", "is deprecated.",
RemovedInDjango61Warning, RemovedInDjango61Warning,
stacklevel=2 stacklevel=2,
) )
def resolve(self, context): def resolve(self, context):