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

Feature/django select2 #868

Merged
merged 6 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions geocity/apps/core/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -905,3 +905,20 @@ img.captcha {
bottom: 0;
margin-top: 20px;
}


/* START Django-Select2 tuning */

.select2-container {
width: 100% !important;
}

.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 */
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
6 changes: 5 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,16 @@ def get_list_single_field_kwargs(self, field, default_kwargs):
return {
**default_kwargs,
"choices": choices,
"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": forms.CheckboxSelectMultiple(),
"widget": Select2MultipleWidget()
if len(field.choices) > 5
else forms.CheckboxSelectMultiple(),
}

def save(self):
Expand Down
1 change: 1 addition & 0 deletions geocity/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"jazzmin",
"jsoneditor",
"django_jsonform",
"django_select2",
# django contrib apps
"django.contrib.admin",
"django.contrib.auth",
Expand Down
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ postfinancecheckout
tzdata
pandas
Unidecode
django-select2
8 changes: 7 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down