Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
use light django-select2 widget for single and multi-select fields
Browse files Browse the repository at this point in the history
  • Loading branch information
monodo committed Sep 11, 2023
1 parent 47f4b70 commit 128e232
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions geocity/apps/submissions/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion geocity/apps/submissions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion geocity/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
"jazzmin",
"jsoneditor",
"django_jsonform",
'django_select2',
"django_select2",
# django contrib apps
"django.contrib.admin",
"django.contrib.auth",
Expand Down
1 change: 0 additions & 1 deletion geocity/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 128e232

Please sign in to comment.