misc: adapt skeletontemplate tag for 3.2 (#64298)

This follows this django change:

commit 04ac9b45a34440fa447feb6ae934687aacbfc5f4
Author: Alex Gaynor <alex.gaynor@gmail.com>
Date:   Tue Oct 8 22:25:20 2019 -0400

    Improved performance of django.template.base.Parser.

    pop(0), which is used to fetch each token, is O(n) in the length of the
    list. By reversing the list and operating off the end, we can perform
    next_token(), prepend_token(), and delete_first_token() in constant
    time.
This commit is contained in:
Frédéric Péters 2022-04-18 11:29:31 +02:00
parent b19febc92a
commit 68e7070377
1 changed files with 4 additions and 1 deletions

View File

@ -23,6 +23,7 @@ from decimal import Decimal
from decimal import DivisionByZero as DecimalDivisionByZero
from decimal import InvalidOperation as DecimalInvalidOperation
import django
from django import template
from django.core import signing
from django.core.exceptions import PermissionDenied
@ -171,9 +172,11 @@ def skeleton_extra_placeholder(parser, token):
raise template.TemplateSyntaxError("%r tag requires exactly one argument" % token.contents.split()[0])
tokens_copy = parser.tokens[:]
if django.VERSION < (3,):
tokens_copy.reverse()
text = []
while True:
token = tokens_copy.pop(0)
token = tokens_copy.pop()
if token.contents == 'end_skeleton_extra_placeholder':
break
if token.token_type == TOKEN_VAR: