From 38ce1d62c150df5eb28fcd460f536ab283e51c4f Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Wed, 8 Feb 2023 21:42:30 +0800 Subject: [PATCH] Add list support for static asset settings (#189) Co-authored-by: Johannes Maron --- django_select2/conf.py | 12 ++++++------ django_select2/forms.py | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/django_select2/conf.py b/django_select2/conf.py index 0f34f774..a704eb17 100644 --- a/django_select2/conf.py +++ b/django_select2/conf.py @@ -55,32 +55,32 @@ class Select2Conf(AppConf): It has set `select2_` as a default value, which you can change if needed. """ - JS = "admin/js/vendor/select2/select2.full.min.js" + JS = ["admin/js/vendor/select2/select2.full.min.js"] """ The URI for the Select2 JS file. By default this points to version shipped with Django. If you want to select the version of the JS library used, or want to serve it from the local 'static' resources, add a line to your settings.py like so:: - SELECT2_JS = 'assets/js/select2.min.js' + SELECT2_JS = ['assets/js/select2.min.js'] If you provide your own JS and would not like Django-Select2 to load any, change this setting to a blank string like so:: - SELECT2_JS = '' + SELECT2_JS = [] .. tip:: Change this setting to a local asset in your development environment to develop without an Internet connection. """ - CSS = "admin/css/vendor/select2/select2.min.css" + CSS = ["admin/css/vendor/select2/select2.min.css"] """ The URI for the Select2 CSS file. By default this points to version shipped with Django. If you want to select the version of the library used, or want to serve it from the local 'static' resources, add a line to your settings.py like so:: - SELECT2_CSS = 'assets/css/select2.css' + SELECT2_CSS = ['assets/css/select2.css'] If you want to add more css (usually used in select2 themes), add a line in settings.py like this:: @@ -93,7 +93,7 @@ class Select2Conf(AppConf): If you provide your own CSS and would not like Django-Select2 to load any, change this setting to a blank string like so:: - SELECT2_CSS = '' + SELECT2_CSS = [] .. tip:: Change this setting to a local asset in your development environment to develop without an Internet connection. diff --git a/django_select2/forms.py b/django_select2/forms.py index da7b5e0d..eaea7743 100644 --- a/django_select2/forms.py +++ b/django_select2/forms.py @@ -127,9 +127,11 @@ def media(self): .. Note:: For more information visit https://docs.djangoproject.com/en/stable/topics/forms/media/#media-as-a-dynamic-property """ - select2_js = [settings.SELECT2_JS] if settings.SELECT2_JS else [] + select2_js = settings.SELECT2_JS if settings.SELECT2_JS else [] select2_css = settings.SELECT2_CSS if settings.SELECT2_CSS else [] + if isinstance(select2_js, str): + select2_js = [select2_js] if isinstance(select2_css, str): select2_css = [select2_css]