mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-07-04 06:42:13 +02:00
Sélection de bus/équipe plus ergonomique
This commit is contained in:
@ -5,7 +5,7 @@ from bootstrap_datepicker_plus.widgets import DatePickerInput
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.forms import CheckboxSelectMultiple
|
from django.forms import CheckboxSelectMultiple, RadioSelect
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from note.models import NoteSpecial, NoteUser
|
from note.models import NoteSpecial, NoteUser
|
||||||
from note_kfet.inputs import AmountInput, Autocomplete, ColorWidget
|
from note_kfet.inputs import AmountInput, Autocomplete, ColorWidget
|
||||||
@ -140,6 +140,19 @@ class WEIMembershipForm(forms.ModelForm):
|
|||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __init__(self, *args, wei=None, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
if 'bus' in self.fields:
|
||||||
|
if wei is not None:
|
||||||
|
self.fields['bus'].queryset = Bus.objects.filter(wei=wei)
|
||||||
|
else:
|
||||||
|
self.fields['bus'].queryset = Bus.objects.none()
|
||||||
|
if 'team' in self.fields:
|
||||||
|
if wei is not None:
|
||||||
|
self.fields['team'].queryset = BusTeam.objects.filter(bus__wei=wei)
|
||||||
|
else:
|
||||||
|
self.fields['team'].queryset = BusTeam.objects.none()
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
cleaned_data = super().clean()
|
cleaned_data = super().clean()
|
||||||
if 'team' in cleaned_data and cleaned_data["team"] is not None \
|
if 'team' in cleaned_data and cleaned_data["team"] is not None \
|
||||||
@ -151,21 +164,8 @@ class WEIMembershipForm(forms.ModelForm):
|
|||||||
model = WEIMembership
|
model = WEIMembership
|
||||||
fields = ('roles', 'bus', 'team',)
|
fields = ('roles', 'bus', 'team',)
|
||||||
widgets = {
|
widgets = {
|
||||||
"bus": Autocomplete(
|
"bus": RadioSelect(),
|
||||||
Bus,
|
"team": RadioSelect(),
|
||||||
attrs={
|
|
||||||
'api_url': '/api/wei/bus/',
|
|
||||||
'placeholder': 'Bus ...',
|
|
||||||
}
|
|
||||||
),
|
|
||||||
"team": Autocomplete(
|
|
||||||
BusTeam,
|
|
||||||
attrs={
|
|
||||||
'api_url': '/api/wei/team/',
|
|
||||||
'placeholder': 'Équipe ...',
|
|
||||||
},
|
|
||||||
resetable=True,
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,4 +210,27 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
|
function refreshTeams() {
|
||||||
|
let buses = [];
|
||||||
|
$("input[name='bus']:checked").each(function (ignored) {
|
||||||
|
buses.push($(this).parent().text().trim());
|
||||||
|
});
|
||||||
|
console.log(buses);
|
||||||
|
$("input[name='team']").each(function () {
|
||||||
|
let label = $(this).parent();
|
||||||
|
$(this).parent().addClass('d-none');
|
||||||
|
buses.forEach(function (bus) {
|
||||||
|
if (label.text().includes(bus))
|
||||||
|
label.removeClass('d-none');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$("input[name='bus']").change(refreshTeams);
|
||||||
|
|
||||||
|
refreshTeams();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -788,7 +788,8 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
|
|||||||
return form
|
return form
|
||||||
|
|
||||||
def get_membership_form(self, data=None, instance=None):
|
def get_membership_form(self, data=None, instance=None):
|
||||||
membership_form = WEIMembershipForm(data if data else None, instance=instance)
|
registration = self.get_object()
|
||||||
|
membership_form = WEIMembershipForm(data if data else None, instance=instance, wei=registration.wei)
|
||||||
del membership_form.fields["credit_type"]
|
del membership_form.fields["credit_type"]
|
||||||
del membership_form.fields["credit_amount"]
|
del membership_form.fields["credit_amount"]
|
||||||
del membership_form.fields["first_name"]
|
del membership_form.fields["first_name"]
|
||||||
@ -969,6 +970,13 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||||||
return WEIMembership1AForm
|
return WEIMembership1AForm
|
||||||
return WEIMembershipForm
|
return WEIMembershipForm
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
kwargs = super().get_form_kwargs()
|
||||||
|
registration = WEIRegistration.objects.get(pk=self.kwargs["pk"])
|
||||||
|
wei = registration.wei
|
||||||
|
kwargs['wei'] = wei
|
||||||
|
return kwargs
|
||||||
|
|
||||||
def get_form(self, form_class=None):
|
def get_form(self, form_class=None):
|
||||||
form = super().get_form(form_class)
|
form = super().get_form(form_class)
|
||||||
registration = WEIRegistration.objects.get(pk=self.kwargs["pk"])
|
registration = WEIRegistration.objects.get(pk=self.kwargs["pk"])
|
||||||
|
Reference in New Issue
Block a user