File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 328328 'InvenTree.context.user_roles' ,
329329 ],
330330 'loaders' : [(
331- 'django .template.loaders.cached.Loader ' , [
331+ 'InvenTree .template.InvenTreeTemplateLoader ' , [
332332 'plugin.template.PluginTemplateLoader' ,
333333 'django.template.loaders.filesystem.Loader' ,
334334 'django.template.loaders.app_directories.Loader' ,
Original file line number Diff line number Diff line change 1+ """Custom template loader for InvenTree"""
2+
3+ import os
4+
5+ from django .conf import settings
6+ from django .template .loaders .base import Loader as BaseLoader
7+ from django .template .loaders .cached import Loader as CachedLoader
8+
9+
10+ class InvenTreeTemplateLoader (CachedLoader ):
11+ """Custom template loader which bypasses cache for PDF export"""
12+
13+ def get_template (self , template_name , skip = None ):
14+ """Return a template object for the given template name.
15+
16+ Any custom report or label templates will be forced to reload (without cache).
17+ This ensures that generated PDF reports / labels are always up-to-date.
18+ """
19+
20+ # List of template patterns to skip cache for
21+ skip_cache_dirs = [
22+ os .path .abspath (os .path .join (settings .MEDIA_ROOT , 'report' )),
23+ os .path .abspath (os .path .join (settings .MEDIA_ROOT , 'label' )),
24+ 'snippets/' ,
25+ ]
26+
27+ # Initially load the template using the cached loader
28+ template = CachedLoader .get_template (self , template_name , skip )
29+
30+ template_path = str (template .name )
31+
32+ # If the template matches any of the skip patterns, reload it without cache
33+ if any ([template_path .startswith (d ) for d in skip_cache_dirs ]):
34+ template = BaseLoader .get_template (self , template_name , skip )
35+
36+ return template
You can’t perform that action at this time.
0 commit comments