From 208dc7f865071d11c869c07b7ae623db7d93cad2 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 3 Aug 2020 13:33:25 +0200 Subject: [PATCH] :art: Use multiple checkboxes than multiple select widget --- apps/member/forms.py | 2 ++ apps/wei/forms/registration.py | 11 ++++++++++- apps/wei/views.py | 5 +++-- templates/wei/weiregistration_form.html | 26 +++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/apps/member/forms.py b/apps/member/forms.py index 50fa9c47..58285b79 100644 --- a/apps/member/forms.py +++ b/apps/member/forms.py @@ -4,6 +4,7 @@ from django import forms from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.models import User +from django.forms import CheckboxSelectMultiple from django.utils.translation import gettext_lazy as _ from note.models import NoteSpecial, Alias from note_kfet.inputs import Autocomplete, AmountInput, DatePickerInput @@ -151,6 +152,7 @@ class MembershipRolesForm(forms.ModelForm): roles = forms.ModelMultipleChoiceField( queryset=Role.objects.filter(weirole=None).all(), label=_("Roles"), + widget=CheckboxSelectMultiple(), ) class Meta: diff --git a/apps/wei/forms/registration.py b/apps/wei/forms/registration.py index 9ce3a350..738db4e2 100644 --- a/apps/wei/forms/registration.py +++ b/apps/wei/forms/registration.py @@ -4,6 +4,7 @@ from django import forms from django.contrib.auth.models import User from django.db.models import Q +from django.forms import CheckboxSelectMultiple from django.utils.translation import gettext_lazy as _ from note_kfet.inputs import AmountInput, DatePickerInput, Autocomplete, ColorWidget @@ -47,6 +48,7 @@ class WEIChooseBusForm(forms.Form): label=_("bus"), help_text=_("This choice is not definitive. The WEI organizers are free to attribute for you a bus and a team," + " in particular if you are a free eletron."), + widget=CheckboxSelectMultiple(), ) team = forms.ModelMultipleChoiceField( @@ -54,17 +56,24 @@ class WEIChooseBusForm(forms.Form): label=_("Team"), required=False, help_text=_("Leave this field empty if you won't be in a team (staff, bus chief, free electron)"), + widget=CheckboxSelectMultiple(), ) roles = forms.ModelMultipleChoiceField( queryset=WEIRole.objects.filter(~Q(name="1A")), label=_("WEI Roles"), help_text=_("Select the roles that you are interested in."), + initial=WEIRole.objects.filter(name="Adhérent WEI").all(), + widget=CheckboxSelectMultiple(), ) class WEIMembershipForm(forms.ModelForm): - roles = forms.ModelMultipleChoiceField(queryset=WEIRole.objects, label=_("WEI Roles")) + roles = forms.ModelMultipleChoiceField( + queryset=WEIRole.objects, + label=_("WEI Roles"), + widget=CheckboxSelectMultiple(), + ) def clean(self): cleaned_data = super().clean() diff --git a/apps/wei/views.py b/apps/wei/views.py index fb0f7b32..8a95c72a 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -527,8 +527,9 @@ class WEIRegister2AView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): context["form"].fields["user"].disabled = True choose_bus_form = WEIChooseBusForm() - choose_bus_form.fields["bus"].queryset = Bus.objects.filter(wei=context["club"]) - choose_bus_form.fields["team"].queryset = BusTeam.objects.filter(bus__wei=context["club"]) + choose_bus_form.fields["bus"].queryset = Bus.objects.filter(wei=context["club"]).order_by('name') + choose_bus_form.fields["team"].queryset = BusTeam.objects.filter(bus__wei=context["club"])\ + .order_by('bus__name', 'name') context['membership_form'] = choose_bus_form return context diff --git a/templates/wei/weiregistration_form.html b/templates/wei/weiregistration_form.html index 86aea555..9cf507c8 100644 --- a/templates/wei/weiregistration_form.html +++ b/templates/wei/weiregistration_form.html @@ -14,3 +14,29 @@ {% endblock %} + +{% block extrajavascript %} + +{% endblock %}