Use bootstrap-select selector when it is necessary

This commit is contained in:
Emmy D'Anello 2023-02-20 17:23:12 +01:00
parent e156ed6111
commit a8f24b6581
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
4 changed files with 32 additions and 28 deletions

View File

@ -120,31 +120,28 @@ class ValidateParticipationForm(forms.Form):
class TournamentForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["date_start"].widget = forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d')
self.fields["date_end"].widget = forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d')
self.fields["inscription_limit"].widget = forms.DateTimeInput(attrs={'type': 'datetime-local'},
format='%Y-%m-%d %H:%M')
self.fields["solution_limit"].widget = forms.DateTimeInput(attrs={'type': 'datetime-local'},
format='%Y-%m-%d %H:%M')
self.fields["solutions_draw"].widget = forms.DateTimeInput(attrs={'type': 'datetime-local'},
format='%Y-%m-%d %H:%M')
self.fields["syntheses_first_phase_limit"].widget = forms.DateTimeInput(attrs={'type': 'datetime-local'},
format='%Y-%m-%d %H:%M')
self.fields["solutions_available_second_phase"].widget = forms.DateTimeInput(attrs={'type': 'datetime-local'},
format='%Y-%m-%d %H:%M')
self.fields["syntheses_second_phase_limit"].widget = forms.DateTimeInput(attrs={'type': 'datetime-local'},
format='%Y-%m-%d %H:%M')
self.fields["organizers"].widget.attrs['class'] = 'selectpicker'
self.fields["organizers"].widget.attrs['data-live-search'] = 'true'
self.fields["organizers"].widget.attrs['data-live-search-normalize'] = 'true'
self.fields["organizers"].queryset = VolunteerRegistration.objects.all()
class Meta:
model = Tournament
fields = '__all__'
widgets = {
'date_start': forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'),
'date_end': forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'),
'inscription_limit': forms.DateTimeInput(attrs={'type': 'datetime-local'}, format='%Y-%m-%d %H:%M'),
'solution_limit': forms.DateTimeInput(attrs={'type': 'datetime-local'}, format='%Y-%m-%d %H:%M'),
'solutions_draw': forms.DateTimeInput(attrs={'type': 'datetime-local'}, format='%Y-%m-%d %H:%M'),
'syntheses_first_phase_limit': forms.DateTimeInput(attrs={'type': 'datetime-local'},
format='%Y-%m-%d %H:%M'),
'solutions_available_second_phase': forms.DateTimeInput(attrs={'type': 'datetime-local'},
format='%Y-%m-%d %H:%M'),
'syntheses_second_phase_limit': forms.DateTimeInput(attrs={'type': 'datetime-local'},
format='%Y-%m-%d %H:%M'),
'organizers': forms.SelectMultiple(attrs={
'class': 'selectpicker',
'data-live-search': 'true',
'data-live-search-normalize': 'true',
'data-width': 'fit',
})
}
class SolutionForm(forms.ModelForm):
@ -176,7 +173,11 @@ class PoolForm(forms.ModelForm):
model = Pool
fields = ('tournament', 'round', 'bbb_url', 'results_available', 'juries',)
widgets = {
"juries": forms.CheckboxSelectMultiple,
"juries": forms.SelectMultiple(attrs={
'class': 'selectpicker',
'data-live-search': 'true',
'data-live-search-normalize': 'true',
}),
}
@ -189,7 +190,12 @@ class PoolTeamsForm(forms.ModelForm):
model = Pool
fields = ('participations',)
widgets = {
"participations": forms.CheckboxSelectMultiple,
"participations": forms.SelectMultiple(attrs={
'class': 'selectpicker',
'data-live-search': 'true',
'data-live-search-normalize': 'true',
'data-width': 'fit',
}),
}

View File

@ -24,7 +24,7 @@
{% if user_object == user %}
<dt class="col-sm-6 text-end">{% trans "Password:" %}</dt>
<dd class="col-sm-6">
<a href="{% url 'password_change' %}" class="btn-sm btn-secondary">
<a href="{% url 'password_change' %}" class="btn btn-sm btn-secondary">
<i class="fas fa-edit"></i> {% trans "Change password" %}
</a>
</dd>

View File

@ -229,9 +229,6 @@ PHONENUMBER_DEFAULT_REGION = 'FR'
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
# Use local Jquery
JQUERY_URL = False
# Custom parameters
PROBLEM_COUNT = 8
FORBIDDEN_TRIGRAMS = [

View File

@ -263,6 +263,7 @@
.then(resp => resp.text())
.then(resp => new DOMParser().parseFromString(resp, 'text/html'))
.then(res => modalBody.innerHTML = res.getElementById(content_id).outerHTML)
.then(() => $('.selectpicker').selectpicker()) // TODO Update that when the library will be JQuery-free
}
})
}