mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-07-02 05:48:33 +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.contrib.auth.models import User
|
||||
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 note.models import NoteSpecial, NoteUser
|
||||
from note_kfet.inputs import AmountInput, Autocomplete, ColorWidget
|
||||
@ -140,6 +140,19 @@ class WEIMembershipForm(forms.ModelForm):
|
||||
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):
|
||||
cleaned_data = super().clean()
|
||||
if 'team' in cleaned_data and cleaned_data["team"] is not None \
|
||||
@ -151,21 +164,8 @@ class WEIMembershipForm(forms.ModelForm):
|
||||
model = WEIMembership
|
||||
fields = ('roles', 'bus', 'team',)
|
||||
widgets = {
|
||||
"bus": Autocomplete(
|
||||
Bus,
|
||||
attrs={
|
||||
'api_url': '/api/wei/bus/',
|
||||
'placeholder': 'Bus ...',
|
||||
}
|
||||
),
|
||||
"team": Autocomplete(
|
||||
BusTeam,
|
||||
attrs={
|
||||
'api_url': '/api/wei/team/',
|
||||
'placeholder': 'Équipe ...',
|
||||
},
|
||||
resetable=True,
|
||||
),
|
||||
"bus": RadioSelect(),
|
||||
"team": RadioSelect(),
|
||||
}
|
||||
|
||||
|
||||
|
@ -210,4 +210,27 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
}
|
||||
}
|
||||
</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 %}
|
||||
|
@ -788,7 +788,8 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
|
||||
return form
|
||||
|
||||
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_amount"]
|
||||
del membership_form.fields["first_name"]
|
||||
@ -969,6 +970,13 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
return WEIMembership1AForm
|
||||
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):
|
||||
form = super().get_form(form_class)
|
||||
registration = WEIRegistration.objects.get(pk=self.kwargs["pk"])
|
||||
|
Reference in New Issue
Block a user