From f6cd55efe0638b918e33eea94e4ae3e0fca9f145 Mon Sep 17 00:00:00 2001 From: Pavel Savchenko Date: Sun, 26 Feb 2017 09:25:39 +0100 Subject: [PATCH] fix(forms): ensure select2 is included last Select2 needs to be initialised AFTER jQuery is added to the global namespace. This commit also: - Ensures min-width for the select2 widget, and explicitly initialised the widget for the first field selected. - Add latest django context_processors to TEMPLATES.OPTIONS setting --- .gitignore | 2 ++ README.rst | 2 ++ advanced_filters/forms.py | 2 +- .../static/advanced-filters/advanced-filters.css | 4 ++++ .../static/advanced-filters/advanced-filters.js | 2 ++ tests/test_project/settings.py | 14 ++++++++++++++ 6 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index aee201b..74b4086 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ tests/db.sqlite* /.eggs/ /htmlcov/ /advanced_filters/.coverage + +/tests/local.db diff --git a/README.rst b/README.rst index 2e6959b..130da40 100644 --- a/README.rst +++ b/README.rst @@ -30,6 +30,8 @@ Requirements - django-braces == 1.4.0 - simplejson == 3.6.5 +*NOTE*: While the latest Django 1.5.X is supported, the bundled jQuery it includes is outdated (1.4.2) and as such, most of our admin frontend scripts fail. This means that to use advanced-filters in Django 1.5 admin, you'd have to probably include your own jQuery (1.9 or later) and add it to global namespace prior to other scripts in `AdvancedFilterForm.Meta`. + Installation & Set up ===================== diff --git a/advanced_filters/forms.py b/advanced_filters/forms.py index 1961616..dfe0265 100644 --- a/advanced_filters/forms.py +++ b/advanced_filters/forms.py @@ -252,7 +252,7 @@ class Media: ('' if settings.DEBUG else '.min')), static('magnific-popup/jquery.magnific-popup.js'), static('advanced-filters/advanced-filters.js'), ] - js = [SELECT2_JS] + required_js + js = required_js + [SELECT2_JS] css = {'screen': [static(SELECT2_CSS), static('advanced-filters/advanced-filters.css'), static('magnific-popup/magnific-popup.css')]} diff --git a/advanced_filters/static/advanced-filters/advanced-filters.css b/advanced_filters/static/advanced-filters/advanced-filters.css index d9aab07..121a69e 100644 --- a/advanced_filters/static/advanced-filters/advanced-filters.css +++ b/advanced_filters/static/advanced-filters/advanced-filters.css @@ -66,4 +66,8 @@ } .empty-form { display: none; +} + +.select2-container { + min-width: 166px; } \ No newline at end of file diff --git a/advanced_filters/static/advanced-filters/advanced-filters.js b/advanced_filters/static/advanced-filters/advanced-filters.js index 4dda293..4d140f5 100644 --- a/advanced_filters/static/advanced-filters/advanced-filters.js +++ b/advanced_filters/static/advanced-filters/advanced-filters.js @@ -127,6 +127,8 @@ var OperatorHandlers = function($) { $(this).data('pre_change', $(this).val()); }).change(); }); + self.field_selected($('.form-row select.query-field').first()); + }; self.destroy = function() { diff --git a/tests/test_project/settings.py b/tests/test_project/settings.py index e4affbc..a0fe29a 100644 --- a/tests/test_project/settings.py +++ b/tests/test_project/settings.py @@ -58,6 +58,20 @@ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'APP_DIRS': True, + 'OPTIONS': { + 'debug': True, + 'context_processors': [ + # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this + # list if you haven't customized them: + 'django.contrib.auth.context_processors.auth', + 'django.template.context_processors.debug', + 'django.template.context_processors.i18n', + 'django.template.context_processors.media', + 'django.template.context_processors.static', + 'django.template.context_processors.tz', + 'django.contrib.messages.context_processors.messages', + ], + } }, ]