mirror of
https://github.com/django-components/django-components.git
synced 2025-08-11 17:57:59 +00:00
refactor: fix slot context behavior (#445)
This commit is contained in:
parent
f3d6337ecc
commit
3ad0dd8677
6 changed files with 287 additions and 80 deletions
|
@ -1,6 +1,6 @@
|
|||
import glob
|
||||
from pathlib import Path
|
||||
from typing import List, NamedTuple, Optional
|
||||
from typing import Any, Callable, List, NamedTuple, Optional
|
||||
|
||||
from django.template.engine import Engine
|
||||
|
||||
|
@ -49,3 +49,10 @@ def gen_id(length: int = 5) -> str:
|
|||
|
||||
# Pad the ID with `0`s up to 4 digits, e.g. `0007`
|
||||
return f"{_id:04}"
|
||||
|
||||
|
||||
def find_last_index(lst: List, predicate: Callable[[Any], bool]) -> Any:
|
||||
for r_idx, elem in enumerate(reversed(lst)):
|
||||
if predicate(elem):
|
||||
return len(lst) - 1 - r_idx
|
||||
return -1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue