Skip to content

Commit 5814476

Browse files
fsecada01claude
andcommitted
fix: set COTTON_DIR (singular) in CfUiConfig — django-cotton never read COTTON_DIRS
django-cotton 2.x reads settings.COTTON_DIR (a single string), not COTTON_DIRS (a list). The previous append-to-COTTON_DIRS path was a no-op at runtime, so every <c-cf.*> raised TemplateDoesNotExist in any consumer template that rendered a cf component unconditionally. The unit test asserted the wrong invariant (membership in COTTON_DIRS) and the E2E settings file masked the bug by pre-setting COTTON_DIR itself, so CI stayed green. ready() now sets COTTON_DIR to "cotton/<theme>" only when the consumer hasn't already set it. django-cotton's loader auto-walks each app's templates/ dir, so <c-cf.notification> resolves to cf_ui/templates/cotton/<theme>/cf/notification.html without any TEMPLATES["DIRS"] coordination. The multi-theme directory layout is preserved. Fixes #3. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 7adc77b commit 5814476

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

src/cf_ui/django.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ def ready(self) -> None:
2121
f"Check CF_UI_THEME in settings."
2222
)
2323

24-
if not hasattr(settings, "COTTON_DIRS"):
25-
settings.COTTON_DIRS = []
26-
27-
if cotton_dir not in [Path(d) for d in settings.COTTON_DIRS]:
28-
settings.COTTON_DIRS.append(cotton_dir)
24+
# django-cotton reads COTTON_DIR (singular). Setting it to
25+
# "cotton/<theme>" makes <c-cf.foo> resolve to
26+
# cotton/<theme>/cf/foo.html, which the cotton loader finds via
27+
# the app-templates walk (cf_ui/templates/cotton/<theme>/cf/foo.html).
28+
# Don't overwrite a value the consumer has already set.
29+
if not getattr(settings, "COTTON_DIR", None):
30+
settings.COTTON_DIR = f"cotton/{theme}"

tests/unit/test_core.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,10 @@ def test_django_appconfig_name():
3232
assert app is not None
3333

3434

35-
def test_django_appconfig_ready_registers_cotton_dirs():
35+
def test_django_appconfig_ready_sets_cotton_dir():
3636
from django.conf import settings
3737

38-
from cf_ui import COTTON_TEMPLATES_DIR
39-
40-
theme_dir = COTTON_TEMPLATES_DIR / "bulma"
41-
assert any(str(d) == str(theme_dir) for d in getattr(settings, "COTTON_DIRS", []))
38+
assert getattr(settings, "COTTON_DIR", None) == "cotton/bulma"
4239

4340

4441
def test_fastapi_install_cf_ui_adds_template_dir():

0 commit comments

Comments
 (0)