aa-fleetfinder 2.3.1__py3-none-any.whl → 2.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of aa-fleetfinder might be problematic. Click here for more details.
- {aa_fleetfinder-2.3.1.dist-info → aa_fleetfinder-2.3.3.dist-info}/METADATA +12 -13
- {aa_fleetfinder-2.3.1.dist-info → aa_fleetfinder-2.3.3.dist-info}/RECORD +30 -27
- fleetfinder/__init__.py +1 -1
- fleetfinder/app_settings.py +20 -0
- fleetfinder/constants.py +7 -6
- fleetfinder/helper/static_files.py +7 -4
- fleetfinder/locale/cs_CZ/LC_MESSAGES/django.po +7 -11
- fleetfinder/locale/de/LC_MESSAGES/django.po +10 -11
- fleetfinder/locale/django.pot +8 -12
- fleetfinder/locale/es/LC_MESSAGES/django.po +10 -11
- fleetfinder/locale/fr_FR/LC_MESSAGES/django.po +7 -11
- fleetfinder/locale/it_IT/LC_MESSAGES/django.po +7 -11
- fleetfinder/locale/ja/LC_MESSAGES/django.po +7 -11
- fleetfinder/locale/ko_KR/LC_MESSAGES/django.po +10 -11
- fleetfinder/locale/nl_NL/LC_MESSAGES/django.po +7 -11
- fleetfinder/locale/pl_PL/LC_MESSAGES/django.po +10 -11
- fleetfinder/locale/ru/LC_MESSAGES/django.po +10 -11
- fleetfinder/locale/sk/LC_MESSAGES/django.po +7 -11
- fleetfinder/locale/uk/LC_MESSAGES/django.mo +0 -0
- fleetfinder/locale/uk/LC_MESSAGES/django.po +39 -57
- fleetfinder/locale/zh_Hans/LC_MESSAGES/django.po +10 -11
- fleetfinder/templates/fleetfinder/base.html +9 -4
- fleetfinder/templates/fleetfinder/partials/header/header-nav-left.html +9 -0
- fleetfinder/templates/fleetfinder/partials/header/header-nav-right.html +18 -0
- fleetfinder/templatetags/fleetfinder.py +39 -11
- fleetfinder/tests/test_settings.py +37 -0
- fleetfinder/tests/test_templatetags.py +116 -7
- fleetfinder/views.py +0 -14
- fleetfinder/templates/fleetfinder/partials/header/header-navigation.html +0 -35
- {aa_fleetfinder-2.3.1.dist-info → aa_fleetfinder-2.3.3.dist-info}/WHEEL +0 -0
- {aa_fleetfinder-2.3.1.dist-info → aa_fleetfinder-2.3.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -18,18 +18,22 @@ from app_utils.logging import LoggerAddTag
|
|
|
18
18
|
|
|
19
19
|
# AA Fleet Finder
|
|
20
20
|
from fleetfinder import __title__, __version__
|
|
21
|
+
from fleetfinder.app_settings import debug_enabled
|
|
22
|
+
from fleetfinder.constants import PACKAGE_NAME
|
|
21
23
|
from fleetfinder.helper.static_files import calculate_integrity_hash
|
|
22
24
|
|
|
23
25
|
logger = LoggerAddTag(my_logger=get_extension_logger(__name__), prefix=__title__)
|
|
24
26
|
|
|
25
27
|
|
|
26
28
|
@register.simple_tag
|
|
27
|
-
def fleetfinder_static(relative_file_path: str) -> str | None:
|
|
29
|
+
def fleetfinder_static(relative_file_path: str, script_type: str = None) -> str | None:
|
|
28
30
|
"""
|
|
29
31
|
Versioned static URL
|
|
30
32
|
|
|
31
|
-
:param relative_file_path: The file path relative to the `
|
|
33
|
+
:param relative_file_path: The file path relative to the `{APP_NAME}/{PACKAGE_NAME}/static/{PACKAGE_NAME}` folder
|
|
32
34
|
:type relative_file_path: str
|
|
35
|
+
:param script_type: The script type
|
|
36
|
+
:type script_type: str
|
|
33
37
|
:return: Versioned static URL
|
|
34
38
|
:rtype: str
|
|
35
39
|
"""
|
|
@@ -44,10 +48,16 @@ def fleetfinder_static(relative_file_path: str) -> str | None:
|
|
|
44
48
|
if file_type not in ["css", "js"]:
|
|
45
49
|
raise ValueError(f"Unsupported file type: {file_type}")
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
static_file_path = os.path.join("fleetfinder", relative_file_path)
|
|
51
|
+
static_file_path = os.path.join(PACKAGE_NAME, relative_file_path)
|
|
49
52
|
static_url = static(static_file_path)
|
|
50
53
|
|
|
54
|
+
# Integrity hash calculation only for non-debug mode
|
|
55
|
+
sri_string = (
|
|
56
|
+
f' integrity="{calculate_integrity_hash(relative_file_path)}" crossorigin="anonymous"'
|
|
57
|
+
if not debug_enabled()
|
|
58
|
+
else ""
|
|
59
|
+
)
|
|
60
|
+
|
|
51
61
|
# Versioned URL for CSS and JS files
|
|
52
62
|
# Add version query parameter to break browser caches when changing the app version
|
|
53
63
|
# Do not add version query parameter for libs as they are already versioned through their file path
|
|
@@ -57,18 +67,36 @@ def fleetfinder_static(relative_file_path: str) -> str | None:
|
|
|
57
67
|
else static_url + "?v=" + __version__
|
|
58
68
|
)
|
|
59
69
|
|
|
70
|
+
return_value = None
|
|
71
|
+
|
|
60
72
|
# Return the versioned URL with integrity hash for CSS
|
|
61
73
|
if file_type == "css":
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return mark_safe(
|
|
65
|
-
f'<link rel="stylesheet" href="{versioned_url}" integrity="{integrity_hash}" crossorigin="anonymous">'
|
|
74
|
+
return_value = mark_safe(
|
|
75
|
+
f'<link rel="stylesheet" href="{versioned_url}"{sri_string}>'
|
|
66
76
|
)
|
|
67
77
|
|
|
68
78
|
# Return the versioned URL with integrity hash for JS files
|
|
69
79
|
if file_type == "js":
|
|
70
|
-
|
|
71
|
-
|
|
80
|
+
js_type = f' type="{script_type}"' if script_type else ""
|
|
81
|
+
|
|
82
|
+
return_value = mark_safe(
|
|
83
|
+
f'<script{js_type} src="{versioned_url}"{sri_string}></script>'
|
|
72
84
|
)
|
|
73
85
|
|
|
74
|
-
return
|
|
86
|
+
return return_value
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@register.filter
|
|
90
|
+
def get_item(dictionary: dict | None, key: str) -> str | None:
|
|
91
|
+
"""
|
|
92
|
+
Little helper: get a key from a dictionary
|
|
93
|
+
|
|
94
|
+
:param dictionary:
|
|
95
|
+
:param key:
|
|
96
|
+
:return:
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
if dictionary is None:
|
|
100
|
+
return None
|
|
101
|
+
|
|
102
|
+
return dictionary.get(key, None)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Test the settings
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# Django
|
|
6
|
+
from django.test import TestCase, override_settings
|
|
7
|
+
|
|
8
|
+
# AA Fleet Finder
|
|
9
|
+
from fleetfinder.app_settings import debug_enabled
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TestSettings(TestCase):
|
|
13
|
+
"""
|
|
14
|
+
Test the settings
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
@override_settings(DEBUG=True)
|
|
18
|
+
def test_debug_enabled_with_debug_true(self) -> None:
|
|
19
|
+
"""
|
|
20
|
+
Test debug_enabled with DEBUG = True
|
|
21
|
+
|
|
22
|
+
:return:
|
|
23
|
+
:rtype:
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
self.assertTrue(debug_enabled())
|
|
27
|
+
|
|
28
|
+
@override_settings(DEBUG=False)
|
|
29
|
+
def test_debug_enabled_with_debug_false(self) -> None:
|
|
30
|
+
"""
|
|
31
|
+
Test debug_enabled with DEBUG = False
|
|
32
|
+
|
|
33
|
+
:return:
|
|
34
|
+
:rtype:
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
self.assertFalse(debug_enabled())
|
|
@@ -4,11 +4,13 @@ Test the apps' template tags
|
|
|
4
4
|
|
|
5
5
|
# Django
|
|
6
6
|
from django.template import Context, Template
|
|
7
|
-
from django.test import TestCase
|
|
7
|
+
from django.test import TestCase, override_settings
|
|
8
8
|
|
|
9
9
|
# AA Fleet Finder
|
|
10
10
|
from fleetfinder import __version__
|
|
11
|
+
from fleetfinder.constants import PACKAGE_NAME
|
|
11
12
|
from fleetfinder.helper.static_files import calculate_integrity_hash
|
|
13
|
+
from fleetfinder.templatetags.fleetfinder import get_item
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
class TestVersionedStatic(TestCase):
|
|
@@ -16,6 +18,7 @@ class TestVersionedStatic(TestCase):
|
|
|
16
18
|
Test the `fleetfinder_static` template tag
|
|
17
19
|
"""
|
|
18
20
|
|
|
21
|
+
@override_settings(DEBUG=False)
|
|
19
22
|
def test_versioned_static(self):
|
|
20
23
|
"""
|
|
21
24
|
Test should return the versioned static
|
|
@@ -32,14 +35,120 @@ class TestVersionedStatic(TestCase):
|
|
|
32
35
|
)
|
|
33
36
|
)
|
|
34
37
|
|
|
35
|
-
rendered_template = template_to_render.render(context)
|
|
38
|
+
rendered_template = template_to_render.render(context=context)
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
f'/static/
|
|
40
|
+
expected_static_css_src = (
|
|
41
|
+
f'/static/{PACKAGE_NAME}/css/fleetfinder.min.css?v={context["version"]}'
|
|
39
42
|
)
|
|
40
|
-
|
|
43
|
+
expected_static_css_src_integrity = calculate_integrity_hash(
|
|
41
44
|
"css/fleetfinder.min.css"
|
|
42
45
|
)
|
|
43
46
|
|
|
44
|
-
self.assertIn(member=
|
|
45
|
-
self.assertIn(
|
|
47
|
+
self.assertIn(member=expected_static_css_src, container=rendered_template)
|
|
48
|
+
self.assertIn(
|
|
49
|
+
member=expected_static_css_src_integrity, container=rendered_template
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
@override_settings(DEBUG=True)
|
|
53
|
+
def test_versioned_static_with_debug_enabled(self) -> None:
|
|
54
|
+
"""
|
|
55
|
+
Test versioned static template tag with DEBUG enabled
|
|
56
|
+
|
|
57
|
+
:return:
|
|
58
|
+
:rtype:
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
context = Context({"version": __version__})
|
|
62
|
+
template_to_render = Template(
|
|
63
|
+
template_string=(
|
|
64
|
+
"{% load fleetfinder %}"
|
|
65
|
+
"{% fleetfinder_static 'css/fleetfinder.min.css' %}"
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
rendered_template = template_to_render.render(context=context)
|
|
70
|
+
|
|
71
|
+
expected_static_css_src = (
|
|
72
|
+
f'/static/{PACKAGE_NAME}/css/fleetfinder.min.css?v={context["version"]}'
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
self.assertIn(member=expected_static_css_src, container=rendered_template)
|
|
76
|
+
self.assertNotIn(member="integrity=", container=rendered_template)
|
|
77
|
+
|
|
78
|
+
@override_settings(DEBUG=False)
|
|
79
|
+
def test_invalid_file_type(self) -> None:
|
|
80
|
+
"""
|
|
81
|
+
Test should raise a ValueError for an invalid file type
|
|
82
|
+
|
|
83
|
+
:return:
|
|
84
|
+
:rtype:
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
context = Context({"version": __version__})
|
|
88
|
+
template_to_render = Template(
|
|
89
|
+
template_string=(
|
|
90
|
+
"{% load fleetfinder %}"
|
|
91
|
+
"{% fleetfinder_static 'invalid/invalid.txt' %}"
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
with self.assertRaises(ValueError):
|
|
96
|
+
template_to_render.render(context=context)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class TestGetItem(TestCase):
|
|
100
|
+
"""
|
|
101
|
+
Test the `get_item` template tag
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
def test_returns_value_for_existing_key(self):
|
|
105
|
+
"""
|
|
106
|
+
Test should return the value for an existing key
|
|
107
|
+
|
|
108
|
+
:return:
|
|
109
|
+
:rtype:
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
dictionary = {"key1": "value1", "key2": "value2"}
|
|
113
|
+
result = get_item(dictionary, "key1")
|
|
114
|
+
|
|
115
|
+
self.assertEqual(result, "value1")
|
|
116
|
+
|
|
117
|
+
def test_returns_none_for_non_existing_key(self):
|
|
118
|
+
"""
|
|
119
|
+
Test should return None for a non-existing key
|
|
120
|
+
|
|
121
|
+
:return:
|
|
122
|
+
:rtype:
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
dictionary = {"key1": "value1", "key2": "value2"}
|
|
126
|
+
result = get_item(dictionary, "key3")
|
|
127
|
+
|
|
128
|
+
self.assertIsNone(result)
|
|
129
|
+
|
|
130
|
+
def test_returns_none_for_empty_dictionary(self):
|
|
131
|
+
"""
|
|
132
|
+
Test should return None for an empty dictionary
|
|
133
|
+
|
|
134
|
+
:return:
|
|
135
|
+
:rtype:
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
dictionary = {}
|
|
139
|
+
result = get_item(dictionary, "key1")
|
|
140
|
+
|
|
141
|
+
self.assertIsNone(result)
|
|
142
|
+
|
|
143
|
+
def test_returns_none_for_none_dictionary(self):
|
|
144
|
+
"""
|
|
145
|
+
Test should return None for a None dictionary
|
|
146
|
+
|
|
147
|
+
:return:
|
|
148
|
+
:rtype:
|
|
149
|
+
"""
|
|
150
|
+
|
|
151
|
+
dictionary = None
|
|
152
|
+
result = get_item(dictionary, "key1")
|
|
153
|
+
|
|
154
|
+
self.assertIsNone(result)
|
fleetfinder/views.py
CHANGED
|
@@ -11,7 +11,6 @@ from django.contrib.auth.decorators import login_required, permission_required
|
|
|
11
11
|
from django.db.models import Q
|
|
12
12
|
from django.http import JsonResponse
|
|
13
13
|
from django.shortcuts import redirect, render
|
|
14
|
-
from django.template.defaulttags import register
|
|
15
14
|
from django.urls import reverse
|
|
16
15
|
from django.utils.safestring import mark_safe
|
|
17
16
|
from django.utils.translation import gettext_lazy as _
|
|
@@ -341,16 +340,3 @@ def ajax_fleet_details(
|
|
|
341
340
|
data["fleet_composition"].append({"ship_type_name": ship, "number": number})
|
|
342
341
|
|
|
343
342
|
return JsonResponse(data=data, safe=False)
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
@register.filter
|
|
347
|
-
def get_item(dictionary, key):
|
|
348
|
-
"""
|
|
349
|
-
Little helper: get a key from a dictionary
|
|
350
|
-
|
|
351
|
-
:param dictionary:
|
|
352
|
-
:param key:
|
|
353
|
-
:return:
|
|
354
|
-
"""
|
|
355
|
-
|
|
356
|
-
return dictionary.get(key=key, default=None)
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{% load i18n %}
|
|
2
|
-
|
|
3
|
-
<nav class="navbar navbar-expand-lg bg-primary navbar-dark mb-3 rounded">
|
|
4
|
-
<div class="container-fluid">
|
|
5
|
-
<a class="navbar-brand" href="{% url 'fleetfinder:dashboard' %}">
|
|
6
|
-
{% translate "Available fleets" as navigation_item %}
|
|
7
|
-
{{ navigation_item|title }}
|
|
8
|
-
</a>
|
|
9
|
-
|
|
10
|
-
<button
|
|
11
|
-
class="navbar-toggler collapsed"
|
|
12
|
-
type="button"
|
|
13
|
-
data-bs-toggle="collapse"
|
|
14
|
-
data-bs-target="#fleetfinder-header-navbar"
|
|
15
|
-
aria-controls="fleetfinder-header-navbar"
|
|
16
|
-
aria-expanded="false"
|
|
17
|
-
aria-label="{% translate 'Toggle navigation' %}"
|
|
18
|
-
>
|
|
19
|
-
<span class="navbar-toggler-icon"></span>
|
|
20
|
-
</button>
|
|
21
|
-
|
|
22
|
-
<div class="collapse navbar-collapse" id="fleetfinder-header-navbar">
|
|
23
|
-
<ul class="navbar-nav">
|
|
24
|
-
{% if perms.fleetfinder.manage_fleets %}
|
|
25
|
-
<li class="nav-item">
|
|
26
|
-
<a class="nav-link" href="{% url 'fleetfinder:create_fleet' %}">
|
|
27
|
-
{% translate "Create fleet" as navigation_item %}
|
|
28
|
-
{{ navigation_item|title }}
|
|
29
|
-
</a>
|
|
30
|
-
</li>
|
|
31
|
-
{% endif %}
|
|
32
|
-
</ul>
|
|
33
|
-
</div>
|
|
34
|
-
</div>
|
|
35
|
-
</nav>
|
|
File without changes
|
|
File without changes
|