|
1 | 1 | import logging |
| 2 | +from warnings import warn |
2 | 3 |
|
3 | 4 | from django.conf import settings |
4 | 5 |
|
|
8 | 9 | SETTINGS_KEY = "UNICORN" |
9 | 10 | LEGACY_SETTINGS_KEY = f"DJANGO_{SETTINGS_KEY}" |
10 | 11 |
|
| 12 | +DEFAULT_MORPHER_NAME = "morphdom" |
| 13 | +MORPHER_NAMES = ( |
| 14 | + "morphdom", |
| 15 | + "alpine", |
| 16 | +) |
| 17 | + |
11 | 18 |
|
12 | 19 | def get_settings(): |
13 | 20 | unicorn_settings = {} |
@@ -35,18 +42,26 @@ def get_cache_alias(): |
35 | 42 | return get_setting("CACHE_ALIAS", "default") |
36 | 43 |
|
37 | 44 |
|
38 | | -def get_morpher(): |
39 | | - return get_setting("MORPHER", "morphdom") |
40 | | - |
| 45 | +def get_morpher_settings(): |
| 46 | + options = get_setting("MORPHER", {"NAME": DEFAULT_MORPHER_NAME}) |
41 | 47 |
|
42 | | -def get_morpher_options(): |
43 | | - options = get_setting("MORPHER_OPTIONS", {}) |
| 48 | + # Legacy `RELOAD_SCRIPT_ELEMENTS` setting that needs to go to `MORPHER.RELOAD_SCRIPT_ELEMENTS` |
| 49 | + reload_script_elements = get_setting("RELOAD_SCRIPT_ELEMENTS") |
44 | 50 |
|
45 | | - # Legacy "RELOAD_SCRIPT_ELEMENTS" setting that needs to go to |
46 | | - # MORPHER_OPTIONS["RELOAD_SCRIPT_ELEMENTS"]. |
47 | | - reload_script_elements = get_setting("RELOAD_SCRIPT_ELEMENTS", False) |
48 | 51 | if reload_script_elements: |
49 | | - options["RELOAD_SCRIPT_ELEMENTS"] = True |
| 52 | + msg = 'The `RELOAD_SCRIPT_ELEMENTS` setting is deprecated. Use \ |
| 53 | +`MORPHER["RELOAD_SCRIPT_ELEMENTS"]` instead.' |
| 54 | + warn(msg, DeprecationWarning, stacklevel=1) |
| 55 | + |
| 56 | + options["RELOAD_SCRIPT_ELEMENTS"] = reload_script_elements |
| 57 | + |
| 58 | + if not options.get("NAME"): |
| 59 | + options["NAME"] = DEFAULT_MORPHER_NAME |
| 60 | + |
| 61 | + morpher_name = options["NAME"] |
| 62 | + |
| 63 | + if not morpher_name or morpher_name not in MORPHER_NAMES: |
| 64 | + raise AssertionError(f"Unknown morpher name: {morpher_name}") |
50 | 65 |
|
51 | 66 | return options |
52 | 67 |
|
|
0 commit comments