nanterre: validate batch federation deletion files (fixes #29619)
This commit is contained in:
parent
b319e939e2
commit
2cc90aa4cd
|
@ -16,6 +16,7 @@
|
|||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from .utils import PersonSearch, get_applications, get_application
|
||||
from . import synchronize_federations
|
||||
|
@ -58,6 +59,20 @@ class SynchronizeFederationsForm(forms.Form):
|
|||
csv_uploaded = forms.FileField(
|
||||
label=_('CSV file'))
|
||||
|
||||
def clean_csv_uploaded(self):
|
||||
csv_uploaded = self.cleaned_data['csv_uploaded']
|
||||
errors = []
|
||||
for i, line in enumerate(csv_uploaded):
|
||||
try:
|
||||
line.encode('ascii')
|
||||
# works with pyhton2 and 3
|
||||
except (UnicodeEncodeError, UnicodeDecodeError) as e:
|
||||
errors.append(_(u'non-ASCII character on line {0} and column {1}').format(
|
||||
i + 1, e.start + 1))
|
||||
if errors:
|
||||
raise ValidationError(errors)
|
||||
return csv_uploaded
|
||||
|
||||
def save(self):
|
||||
synchronize_federations.SynchronizeFederationsAction.synchronize(
|
||||
**self.cleaned_data)
|
||||
|
|
|
@ -68,3 +68,6 @@ msgstr "doublon"
|
|||
#: zoo_nanterre/models.py:77
|
||||
msgid "duplicates"
|
||||
msgstr "doublons"
|
||||
|
||||
msgid "non-ASCII character on line {0} and column {1}"
|
||||
msgstr "caractère non-ASCII à la ligne {0} et colonne {1}"
|
||||
|
|
Loading…
Reference in New Issue