From d5ce61641195dbbfcb9920461f3179aa0cd53702 Mon Sep 17 00:00:00 2001 From: monodo Date: Thu, 7 Sep 2023 16:27:44 +0200 Subject: [PATCH 1/6] install dep --- requirements.in | 1 + requirements.txt | 8 +++++++- requirements_dev.txt | 10 +++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/requirements.in b/requirements.in index 727c7d6c4..ea519275d 100644 --- a/requirements.in +++ b/requirements.in @@ -51,3 +51,4 @@ postfinancecheckout tzdata pandas Unidecode +django-select2 diff --git a/requirements.txt b/requirements.txt index 982478c8b..88b158d25 100644 --- a/requirements.txt +++ b/requirements.txt @@ -32,6 +32,7 @@ django==4.2.4 # -r requirements.in # django-admin-sortable2 # django-allauth + # django-appconf # django-axes # django-bootstrap-datepicker-plus # django-bootstrap4 @@ -50,6 +51,7 @@ django==4.2.4 # django-polymorphic # django-ranged-response # django-rest-knox + # django-select2 # django-simple-captcha # django-tables2 # django-tables2-column-shifter @@ -60,6 +62,8 @@ django-admin-sortable2==2.1.9 # via -r requirements.in django-allauth==0.55.0 # via -r requirements.in +django-appconf==1.0.5 + # via django-select2 django-axes==5.41.1 # via -r requirements.in django-bootstrap-datepicker-plus==4.0.0 @@ -68,7 +72,7 @@ django-bootstrap4==21.2 # via -r requirements.in django-ckeditor==6.7.0 # via -r requirements.in -django-constance[database]==3.1.0 +django-constance==3.1.0 # via -r requirements.in django-cors-headers==4.2.0 # via -r requirements.in @@ -104,6 +108,8 @@ django-ranged-response==0.2.0 # via django-simple-captcha django-rest-knox==4.2.0 # via -r requirements.in +django-select2==8.1.2 + # via -r requirements.in django-simple-captcha==0.5.18 # via -r requirements.in django-simple-history==3.3.0 diff --git a/requirements_dev.txt b/requirements_dev.txt index 1295905a8..648d59682 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -64,6 +64,7 @@ django==4.2.4 # -r requirements.txt # django-admin-sortable2 # django-allauth + # django-appconf # django-axes # django-bootstrap-datepicker-plus # django-bootstrap4 @@ -84,6 +85,7 @@ django==4.2.4 # django-polymorphic # django-ranged-response # django-rest-knox + # django-select2 # django-simple-captcha # django-tables2 # django-tables2-column-shifter @@ -94,6 +96,10 @@ django-admin-sortable2==2.1.9 # via -r requirements.txt django-allauth==0.55.0 # via -r requirements.txt +django-appconf==1.0.5 + # via + # -r requirements.txt + # django-select2 django-axes==5.41.1 # via -r requirements.txt django-bootstrap-datepicker-plus==4.0.0 @@ -102,7 +108,7 @@ django-bootstrap4==21.2 # via -r requirements.txt django-ckeditor==6.7.0 # via -r requirements.txt -django-constance[database]==3.1.0 +django-constance==3.1.0 # via -r requirements.txt django-cors-headers==4.2.0 # via -r requirements.txt @@ -156,6 +162,8 @@ django-ranged-response==0.2.0 # django-simple-captcha django-rest-knox==4.2.0 # via -r requirements.txt +django-select2==8.1.2 + # via -r requirements.txt django-simple-captcha==0.5.18 # via -r requirements.txt django-simple-history==3.3.0 From 47f4b703839371f45409d6708411addcb076c27e Mon Sep 17 00:00:00 2001 From: monodo Date: Thu, 7 Sep 2023 16:30:11 +0200 Subject: [PATCH 2/6] install select 2 --- geocity/settings.py | 1 + geocity/urls.py | 1 + 2 files changed, 2 insertions(+) diff --git a/geocity/settings.py b/geocity/settings.py index 881827b2b..7edc6bd6f 100644 --- a/geocity/settings.py +++ b/geocity/settings.py @@ -165,6 +165,7 @@ "jazzmin", "jsoneditor", "django_jsonform", + 'django_select2', # django contrib apps "django.contrib.admin", "django.contrib.auth", diff --git a/geocity/urls.py b/geocity/urls.py index 4a1e9114e..5ff193985 100644 --- a/geocity/urls.py +++ b/geocity/urls.py @@ -47,6 +47,7 @@ path("oauth/", include("oauth2_provider.urls", namespace="oauth2_provider")), path("admin/", admin.site.urls), path("accounts/social/", include("allauth.socialaccount.urls")), + path("select2/", include("django_select2.urls")), ] if settings.ENABLE_2FA: From 128e232d58063cfb2553b20203b2e039c70094aa Mon Sep 17 00:00:00 2001 From: monodo Date: Mon, 11 Sep 2023 09:14:34 +0200 Subject: [PATCH 3/6] use light django-select2 widget for single and multi-select fields --- geocity/apps/submissions/filters.py | 9 +++++++++ geocity/apps/submissions/forms.py | 4 +++- geocity/settings.py | 2 +- geocity/urls.py | 1 - 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/geocity/apps/submissions/filters.py b/geocity/apps/submissions/filters.py index 04912b8aa..68fd06f04 100644 --- a/geocity/apps/submissions/filters.py +++ b/geocity/apps/submissions/filters.py @@ -2,6 +2,7 @@ from bootstrap_datepicker_plus.widgets import DatePickerInput from django.db.models import Max, Min from django.utils.translation import gettext_lazy as _ +from django_select2.forms import Select2Widget from geocity.apps.accounts.models import AdministrativeEntity from geocity.apps.forms.models import Form, FormCategory @@ -47,14 +48,17 @@ class BaseSubmissionFilterSet(django_filters.FilterSet): forms__administrative_entities = django_filters.filters.ModelChoiceFilter( queryset=_get_administrative_entities_queryset_for_current_user, label=_("Entité administrative"), + widget=Select2Widget(), ) forms__category = django_filters.filters.ModelChoiceFilter( queryset=_get_form_categories_queryset_for_current_user, label=_("Type de demande"), + widget=Select2Widget(), ) forms = django_filters.filters.ModelChoiceFilter( queryset=_get_forms_queryset_for_current_user, label=_("Objet de la demande"), + widget=Select2Widget(), ) created_at = django_filters.DateFilter( field_name="created_at", @@ -120,6 +124,11 @@ class DepartmentSubmissionFilterSet(BaseSubmissionFilterSet): lookup_expr="icontains", label=_("Nom court"), ) + status = django_filters.filters.ChoiceFilter( + choices=models.Submission.STATUS_CHOICES, + label=_("État"), + widget=Select2Widget(), + ) class Meta: model = models.Submission diff --git a/geocity/apps/submissions/forms.py b/geocity/apps/submissions/forms.py index 774a69a30..31c2ebcb6 100644 --- a/geocity/apps/submissions/forms.py +++ b/geocity/apps/submissions/forms.py @@ -26,6 +26,7 @@ from django.utils.safestring import mark_safe from django.utils.text import slugify from django.utils.translation import gettext_lazy as _ +from django_select2.forms import Select2MultipleWidget, Select2Widget from geocity.apps.accounts.models import ( PUBLIC_TYPE_CHOICES, @@ -675,13 +676,14 @@ def get_list_single_field_kwargs(self, field, default_kwargs): return { **default_kwargs, "choices": choices, + "widget": Select2Widget(), } def get_list_multiple_field_kwargs(self, field, default_kwargs): return { **default_kwargs, "choices": [(value, value) for value in field.choices.splitlines()], - "widget": forms.CheckboxSelectMultiple(), + "widget": Select2MultipleWidget(), } def save(self): diff --git a/geocity/settings.py b/geocity/settings.py index 7edc6bd6f..91a9f1924 100644 --- a/geocity/settings.py +++ b/geocity/settings.py @@ -165,7 +165,7 @@ "jazzmin", "jsoneditor", "django_jsonform", - 'django_select2', + "django_select2", # django contrib apps "django.contrib.admin", "django.contrib.auth", diff --git a/geocity/urls.py b/geocity/urls.py index 5ff193985..4a1e9114e 100644 --- a/geocity/urls.py +++ b/geocity/urls.py @@ -47,7 +47,6 @@ path("oauth/", include("oauth2_provider.urls", namespace="oauth2_provider")), path("admin/", admin.site.urls), path("accounts/social/", include("allauth.socialaccount.urls")), - path("select2/", include("django_select2.urls")), ] if settings.ENABLE_2FA: From e2054e00e13291fd73cb143b2e05ca7a1f17b60b Mon Sep 17 00:00:00 2001 From: monodo Date: Mon, 11 Sep 2023 10:47:55 +0200 Subject: [PATCH 4/6] fix django-select2 item with issue --- geocity/apps/core/static/css/main.css | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/geocity/apps/core/static/css/main.css b/geocity/apps/core/static/css/main.css index 5a05c5a7e..64bd70241 100644 --- a/geocity/apps/core/static/css/main.css +++ b/geocity/apps/core/static/css/main.css @@ -905,3 +905,10 @@ img.captcha { bottom: 0; margin-top: 20px; } + + +/* Django-Select2 tuning */ + +.select2-container { + width: 100% !important; +} \ No newline at end of file From b782cc1a2ca5f357e60b949a47c6e196e7a13df9 Mon Sep 17 00:00:00 2001 From: monodo Date: Mon, 11 Sep 2023 12:16:05 +0200 Subject: [PATCH 5/6] adapt select2 styles --- geocity/apps/core/static/css/main.css | 14 ++++++++++++-- geocity/apps/submissions/filters.py | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/geocity/apps/core/static/css/main.css b/geocity/apps/core/static/css/main.css index 64bd70241..f4d7daa77 100644 --- a/geocity/apps/core/static/css/main.css +++ b/geocity/apps/core/static/css/main.css @@ -907,8 +907,18 @@ img.captcha { } -/* Django-Select2 tuning */ +/* START Django-Select2 tuning */ .select2-container { width: 100% !important; -} \ No newline at end of file +} + +.select2-container--default .select2-selection--single { + border: 1px solid #ced4da !important; +} + +.select2-container .select2-selection--single { + height: calc(1.5em + .75rem + 2px) !important; +} + +/* END Django-Select2 tuning */ diff --git a/geocity/apps/submissions/filters.py b/geocity/apps/submissions/filters.py index 68fd06f04..9cff1182e 100644 --- a/geocity/apps/submissions/filters.py +++ b/geocity/apps/submissions/filters.py @@ -48,7 +48,7 @@ class BaseSubmissionFilterSet(django_filters.FilterSet): forms__administrative_entities = django_filters.filters.ModelChoiceFilter( queryset=_get_administrative_entities_queryset_for_current_user, label=_("Entité administrative"), - widget=Select2Widget(), + widget=Select2Widget(attrs={"class": "form-select"}), ) forms__category = django_filters.filters.ModelChoiceFilter( queryset=_get_form_categories_queryset_for_current_user, From 16cab9cf1d87609e2f96dc709f56b665695b15e7 Mon Sep 17 00:00:00 2001 From: monodo Date: Mon, 11 Sep 2023 13:55:22 +0200 Subject: [PATCH 6/6] adress review comments --- geocity/apps/submissions/filters.py | 2 +- geocity/apps/submissions/forms.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/geocity/apps/submissions/filters.py b/geocity/apps/submissions/filters.py index 9cff1182e..68fd06f04 100644 --- a/geocity/apps/submissions/filters.py +++ b/geocity/apps/submissions/filters.py @@ -48,7 +48,7 @@ class BaseSubmissionFilterSet(django_filters.FilterSet): forms__administrative_entities = django_filters.filters.ModelChoiceFilter( queryset=_get_administrative_entities_queryset_for_current_user, label=_("Entité administrative"), - widget=Select2Widget(attrs={"class": "form-select"}), + widget=Select2Widget(), ) forms__category = django_filters.filters.ModelChoiceFilter( queryset=_get_form_categories_queryset_for_current_user, diff --git a/geocity/apps/submissions/forms.py b/geocity/apps/submissions/forms.py index 31c2ebcb6..d34ebeb80 100644 --- a/geocity/apps/submissions/forms.py +++ b/geocity/apps/submissions/forms.py @@ -676,14 +676,16 @@ def get_list_single_field_kwargs(self, field, default_kwargs): return { **default_kwargs, "choices": choices, - "widget": Select2Widget(), + "widget": Select2Widget() if len(choices) > 5 else forms.Select(), } def get_list_multiple_field_kwargs(self, field, default_kwargs): return { **default_kwargs, "choices": [(value, value) for value in field.choices.splitlines()], - "widget": Select2MultipleWidget(), + "widget": Select2MultipleWidget() + if len(field.choices) > 5 + else forms.CheckboxSelectMultiple(), } def save(self):