33import re
44from collections .abc import Callable
55from collections .abc import Generator
6- from collections .abc import Iterable
76from collections .abc import Iterator
87from pathlib import Path
98from typing import Any
1918from django .template .loader_tags import IncludeNode
2019from django .template .utils import get_app_template_dirs
2120
21+ from django_bird .utils import unique_ordered
22+
2223from ._typing import _has_nodelist
2324from .conf import app_settings
2425from .templatetags .tags .bird import TAG
2526from .templatetags .tags .bird import BirdNode
26-
27-
28- def get_component_directory_names ():
29- return list (dict .fromkeys ([* app_settings .COMPONENT_DIRS , "bird" ]))
27+ from .utils import get_files_from_dirs
3028
3129
3230def get_template_names (name : str ) -> list [str ]:
@@ -64,8 +62,8 @@ def get_template_names(name: str) -> list[str]:
6462 Returns:
6563 list[str]: A list of potential template names in resolution order.
6664 """
67- template_names = []
68- component_dirs = get_component_directory_names ()
65+ template_names : list [ str ] = []
66+ component_dirs = app_settings . get_component_directory_names ()
6967
7068 name_parts = name .split ("." )
7169 path_name = "/" .join (name_parts )
@@ -79,7 +77,7 @@ def get_template_names(name: str) -> list[str]:
7977 ]
8078 template_names .extend (potential_names )
8179
82- return list ( dict . fromkeys ( template_names ) )
80+ return unique_ordered ( template_names )
8381
8482
8583def get_template_directories () -> Generator [Path , Any , None ]:
@@ -99,19 +97,10 @@ def get_component_directories(
9997 return [
10098 Path (template_dir ) / component_dir
10199 for template_dir in template_dirs
102- for component_dir in get_component_directory_names ()
100+ for component_dir in app_settings . get_component_directory_names ()
103101 ]
104102
105103
106- def get_files_from_dirs (
107- dirs : Iterable [Path ],
108- ) -> Generator [tuple [Path , Path ], Any , None ]:
109- for dir in dirs :
110- for path in dir .rglob ("*" ):
111- if path .is_file ():
112- yield path , dir
113-
114-
115104BIRD_TAG_PATTERN = re .compile (
116105 rf"{{%\s*{ TAG } \s+(?:\"|')?([a-zA-Z0-9_.-]+)(?:\"|')?.*?%}}"
117106)
0 commit comments