Skip to content

Commit a93166c

Browse files
inline prefix settings check
1 parent 971e8bd commit a93166c

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/django_bird/conf.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
@dataclass
1919
class AppSettings:
20+
ADD_ASSET_PREFIX: bool | None = None
2021
COMPONENT_DIRS: list[Path | str] = field(default_factory=list)
2122
ENABLE_BIRD_ATTRS: bool = True
22-
ADD_ASSET_PREFIX: bool | None = None
2323

2424
@override
2525
def __getattribute__(self, __name: str) -> object:
@@ -29,13 +29,5 @@ def __getattribute__(self, __name: str) -> object:
2929
def get_component_directory_names(self):
3030
return unique_ordered([*self.COMPONENT_DIRS, "bird"])
3131

32-
def should_add_asset_prefix(self) -> bool:
33-
"""Determine if the app label prefix should be added to asset URLs."""
34-
if self.ADD_ASSET_PREFIX is not None:
35-
return self.ADD_ASSET_PREFIX
36-
37-
# Fall back to the DEBUG setting (add prefix in production)
38-
return not settings.DEBUG
39-
4032

4133
app_settings = AppSettings()

src/django_bird/staticfiles.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from typing import final
1313
from typing import overload
1414

15+
from django.conf import settings
1516
from django.contrib.staticfiles import finders
1617
from django.contrib.staticfiles.finders import BaseFinder
1718
from django.contrib.staticfiles.storage import StaticFilesStorage
@@ -178,16 +179,16 @@ def __init__(self, *args: Any, prefix: str, **kwargs: Any):
178179
def url(self, name: str | None) -> str:
179180
if name is None:
180181
return super().url(name)
181-
# Determine if we should add the prefix based on the app settings
182-
from .conf import app_settings
183-
184182
# Add prefix based on app settings configuration
185183
# In development, asset paths don't include the app label prefix
186184
# because they come directly from source directories
187185
# In production, assets are collected to STATIC_ROOT/django_bird/
188-
if app_settings.should_add_asset_prefix() and not name.startswith(
189-
f"{self.prefix}/"
190-
):
186+
add_prefix = (
187+
app_settings.ADD_ASSET_PREFIX
188+
if app_settings.ADD_ASSET_PREFIX is not None
189+
else not settings.DEBUG
190+
)
191+
if add_prefix and not name.startswith(f"{self.prefix}/"):
191192
name = f"{self.prefix}/{name}"
192193
return super().url(name)
193194

0 commit comments

Comments
 (0)