diff --git a/elections/forms.py b/elections/forms.py index a570c41..cc29e64 100644 --- a/elections/forms.py +++ b/elections/forms.py @@ -4,6 +4,7 @@ from django.utils import timezone from django.utils.translation import gettext_lazy as _ from .models import Election, Option, Question +from .utils import check_csv class ElectionForm(forms.ModelForm): @@ -29,6 +30,14 @@ class UploadVotersForm(forms.Form): def clean_csv_file(self): csv_file = self.cleaned_data["csv_file"] + if csv_file.name.lower().endswith(".csv"): + for error in check_csv(csv_file): + self.add_error(None, error) + else: + self.add_error( + None, + _("Extension de fichier invalide, il faut un fichier au format CSV."), + ) return csv_file diff --git a/elections/templates/elections/upload_voters.html b/elections/templates/elections/upload_voters.html index c8b4e97..ac4aaa7 100644 --- a/elections/templates/elections/upload_voters.html +++ b/elections/templates/elections/upload_voters.html @@ -11,7 +11,7 @@ const fileName = document.querySelector('#import-voters .file-name'); fileName.textContent = fileInput.files[0].name; } - } + }; }); @@ -30,6 +30,14 @@