Skip to content

Commit

Permalink
Move some default settings into appsettings, so they don't have to be…
Browse files Browse the repository at this point in the history
… set by every project that uses django-cast
  • Loading branch information
ephes committed Mar 23, 2023
1 parent 77a3725 commit 899840b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
20 changes: 19 additions & 1 deletion cast/appsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,28 @@
POST_LIST_PAGINATION: int = getattr(settings, "POST_LIST_PAGINATION", 5)
DELETE_WAGTAIL_IMAGES: bool = getattr(settings, "DELETE_WAGTAIL_IMAGES", True)

SettingValue = str | bool | int

def init_cast_settings():

def set_default_if_not_set(setting_name: str, default_value: SettingValue) -> None:
if getattr(settings, setting_name, None) is None:
setattr(settings, setting_name, default_value)


DEFAULT_VALUES: list[tuple[str, SettingValue]] = [
("SITE_ID", 1),
("WAGTAIL_SITE_NAME", "Cast"),
("CRISPY_TEMPLATE_PACK", "bootstrap4"),
("CRISPY_ALLOWED_TEMPLATE_PACKS", "bootstrap4"),
]


def init_cast_settings() -> None:
if not DELETE_WAGTAIL_IMAGES:
# Have a way to deactivate wagtails post_delete_file_cleanup
# which deletes the file physically when developing against S3
# cast has to be after wagtail in INSTALLED_APPS for this to work
post_delete.disconnect(post_delete_file_cleanup, sender=get_image_model())

for setting_name, default_value in DEFAULT_VALUES:
set_default_if_not_set(setting_name, default_value)
4 changes: 0 additions & 4 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ Add some required configuration settings to your ``settings.py``:
.. code-block:: python
COMMENTS_APP = "fluent_comments"
SITE_ID = 1
WAGTAIL_SITE_NAME = "foobar"
CRISPY_TEMPLATE_PACK = "bootstrap4"
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap4"
Modify your url-config to include the urls for django-cast and Wagtail:
Expand Down
2 changes: 2 additions & 0 deletions docs/releases/0.2.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Filter fixes + htmx.

* #88 Fixed date facet is removed from form submit
* Moved app settings init into `appsettings.py`
* Provided some default values for settings which don't have
to be in the settings file

0 comments on commit 899840b

Please sign in to comment.