From a8f24b65818833e57990bde52e5f21d30aee2ccf Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Mon, 20 Feb 2023 17:23:12 +0100 Subject: [PATCH] Use bootstrap-select selector when it is necessary --- apps/participation/forms.py | 54 ++++++++++--------- .../templates/registration/user_detail.html | 2 +- tfjm/settings.py | 3 -- tfjm/templates/base.html | 1 + 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/apps/participation/forms.py b/apps/participation/forms.py index 4d5d71e..675d2ae 100644 --- a/apps/participation/forms.py +++ b/apps/participation/forms.py @@ -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', + }), } diff --git a/apps/registration/templates/registration/user_detail.html b/apps/registration/templates/registration/user_detail.html index 34c5ebf..9fb7975 100644 --- a/apps/registration/templates/registration/user_detail.html +++ b/apps/registration/templates/registration/user_detail.html @@ -24,7 +24,7 @@ {% if user_object == user %}
{% trans "Password:" %}
- + {% trans "Change password" %}
diff --git a/tfjm/settings.py b/tfjm/settings.py index 1d33b9b..a3f953d 100644 --- a/tfjm/settings.py +++ b/tfjm/settings.py @@ -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 = [ diff --git a/tfjm/templates/base.html b/tfjm/templates/base.html index b7c4306..edc2acc 100644 --- a/tfjm/templates/base.html +++ b/tfjm/templates/base.html @@ -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 } }) }