Simplified student import process

This commit is contained in:
Claude Paroz 2016-01-19 10:27:53 +01:00
parent 7d45cd0047
commit 03f45f0785
5 changed files with 89 additions and 8 deletions

View file

@ -1,8 +1,29 @@
from django import forms
from django.conf import settings
from tabimport import FileFactory, UnsupportedFileFormat
from .models import Section, Period
class StudentImportForm(forms.Form):
upload = forms.FileField(label="Fichier des étudiants")
def clean_upload(self):
f = self.cleaned_data['upload']
try:
imp_file = FileFactory(f)
except UnsupportedFileFormat as e:
raise forms.ValidationError("Erreur: %s" % e)
# Check needed headers are present
headers = imp_file.get_headers()
missing = set(settings.STUDENT_IMPORT_MAPPING.keys()) - set(headers)
if missing:
raise forms.ValidationError("Erreur: il manque les colonnes %s" % (
", ".join(missing)))
return f
class PeriodForm(forms.Form):
section = forms.ModelChoiceField(queryset=Section.objects.all())
period = forms.ModelChoiceField(queryset=None)