6
6
import os
7
7
8
8
# Django
9
- from django .conf import settings
10
9
from django .template .defaulttags import register
11
10
from django .templatetags .static import static
12
11
from django .utils .safestring import mark_safe
19
18
20
19
# AA Intel Tool
21
20
from aa_intel_tool import __title__ , __version__
21
+ from aa_intel_tool .app_settings import debug_enabled
22
+ from aa_intel_tool .constants import PACKAGE_NAME
22
23
from aa_intel_tool .helper .static_files import calculate_integrity_hash
23
24
24
25
logger = LoggerAddTag (my_logger = get_extension_logger (__name__ ), prefix = __title__ )
@@ -31,7 +32,7 @@ def aa_intel_tool_static(
31
32
"""
32
33
Versioned static URL
33
34
34
- :param relative_file_path: The file path relative to the `aa-intel-tool/aa_intel_tool /static/aa_intel_tool folder
35
+ :param relative_file_path: The file path relative to the `{APP_NAME}/{PACKAGE_NAME} /static/{PACKAGE_NAME}` folder
35
36
:type relative_file_path: str
36
37
:param script_type: The script type
37
38
:type script_type: str
@@ -49,13 +50,13 @@ def aa_intel_tool_static(
49
50
if file_type not in ["css" , "js" ]:
50
51
raise ValueError (f"Unsupported file type: { file_type } " )
51
52
52
- static_file_path = os .path .join ("aa_intel_tool" , relative_file_path )
53
+ static_file_path = os .path .join (PACKAGE_NAME , relative_file_path )
53
54
static_url = static (static_file_path )
54
55
55
56
# Integrity hash calculation only for non-debug mode
56
57
sri_string = (
57
58
f' integrity="{ calculate_integrity_hash (relative_file_path )} " crossorigin="anonymous"'
58
- if not settings . DEBUG
59
+ if not debug_enabled ()
59
60
else ""
60
61
)
61
62
@@ -68,16 +69,20 @@ def aa_intel_tool_static(
68
69
else static_url + "?v=" + __version__
69
70
)
70
71
72
+ return_value = None
73
+
71
74
# Return the versioned URL with integrity hash for CSS
72
75
if file_type == "css" :
73
- return mark_safe (f'<link rel="stylesheet" href="{ versioned_url } "{ sri_string } >' )
76
+ return_value = mark_safe (
77
+ f'<link rel="stylesheet" href="{ versioned_url } "{ sri_string } >'
78
+ )
74
79
75
80
# Return the versioned URL with integrity hash for JS files
76
81
if file_type == "js" :
77
82
js_type = f' type="{ script_type } "' if script_type else ""
78
83
79
- return mark_safe (
84
+ return_value = mark_safe (
80
85
f'<script{ js_type } src="{ versioned_url } "{ sri_string } ></script>'
81
86
)
82
87
83
- return None # pragma: no cover
88
+ return return_value
0 commit comments