Coverage for sm / template / loaders / app_directories_enhanced.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-24 12:43 +0000

1""" 

2Extended wrapper for loading templates from app dirs. 

3Given server/list.html, will search in BASE_DIR/server/templates/list.html 

4""" 

5 

6import os 

7 

8from django.template import Origin 

9 

10from django.template.loaders import filesystem 

11from sm.settings import BASE_DIR 

12 

13 

14class Loader(filesystem.Loader): 

15 

16 def __init__(self, engine, dirs=None): 

17 super().__init__(engine) 

18 self.dirs = dirs 

19 

20 def get_template_sources(self, template_name, template_dirs=None): 

21 """ 

22 Return an Origin object pointing to an absolute path in application 

23 templates subdirectory. 

24 """ 

25 # Only check if there's a directory separator 

26 # This might be a dirty hack 

27 separator = os.path.join(".", "")[-1] 

28 if separator in template_name: 

29 template_path = os.path.join( 

30 BASE_DIR, 

31 os.path.dirname(template_name), 

32 "templates", 

33 os.path.basename(template_name), 

34 ) 

35 yield Origin( 

36 name=template_path, 

37 template_name=template_name, 

38 loader=self, 

39 )