|
1 | | -from pathlib import Path |
2 | | - |
3 | 1 | from django.apps import AppConfig |
4 | | -from django.core.exceptions import ImproperlyConfigured |
5 | 2 |
|
6 | 3 |
|
7 | 4 | class CfUiConfig(AppConfig): |
8 | 5 | name = "cf_ui.django" |
9 | 6 | label = "cf_ui" |
10 | 7 | verbose_name = "Component Framework UI" |
11 | 8 |
|
12 | | - def ready(self) -> None: |
13 | | - from django.conf import settings |
14 | | - |
15 | | - theme = getattr(settings, "CF_UI_THEME", "bulma") |
16 | | - cotton_dir = Path(__file__).parent / "templates" / "cotton" / theme |
17 | | - |
18 | | - if not cotton_dir.is_dir(): |
19 | | - raise ImproperlyConfigured( |
20 | | - f"cf-ui: no templates found for theme {theme!r} at {cotton_dir}. " |
21 | | - f"Check CF_UI_THEME in settings." |
22 | | - ) |
23 | | - |
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}" |
| 9 | + # cf-ui Cotton templates live at src/cf_ui/templates/cotton/cf/*.html. |
| 10 | + # Django's app-templates loader (APP_DIRS=True) picks them up directly |
| 11 | + # and django-cotton's default COTTON_DIR ("cotton") resolves |
| 12 | + # <c-cf.foo> -> cotton/cf/foo.html. We deliberately do not touch |
| 13 | + # COTTON_DIR here: doing so would break consumer projects whose own |
| 14 | + # cotton templates live at cotton/<their-app>/*.html. |
0 commit comments