Import LIB_BRANCHE_OPTION when importing student file

This commit is contained in:
Claude Paroz 2017-08-30 18:46:52 +02:00
parent 68b50514a4
commit e4a4ea46dc
4 changed files with 14 additions and 3 deletions

View file

@ -130,6 +130,7 @@ STUDENT_IMPORT_MAPPING = {
'NAVS13': 'avs',
'SEXE': 'gender',
'CLASSE_ACTUELLE': 'klass',
'LIB_BRANCHE_OPTION': 'option_ase',
}
CORPORATION_IMPORT_MAPPING = {

Binary file not shown.

View file

@ -9,7 +9,7 @@ from django.urls import reverse
from django.utils.html import escape
from .models import (
Level, Domain, Section, Klass, Period, Student, Corporation, Availability,
Level, Domain, Section, Klass, Option, Period, Student, Corporation, Availability,
CorpContact, Teacher, Training, Course,
)
from .utils import school_year
@ -282,7 +282,10 @@ class ImportTests(TestCase):
def setUp(self):
User.objects.create_user('me', 'me@example.org', 'mepassword')
def test_import_gan(self):
def test_import_students(self):
"""
Import of the main students file.
"""
path = os.path.join(os.path.dirname(__file__), 'test_files', 'EXPORT_GAN.xlsx')
self.client.login(username='me', password='mepassword')
with open(path, 'rb') as fh:
@ -301,12 +304,14 @@ class ImportTests(TestCase):
section=Section.objects.create(name='EDE'),
level=lev1,
)
Option.objects.create(name='Accompagnement des enfants')
with open(path, 'rb') as fh: # , override_settings(DEBUG=True):
response = self.client.post(reverse('import-students'), {'upload': fh}, follow=True)
msg = "\n".join(str(m) for m in response.context['messages'])
self.assertIn("Objets créés : 2", msg)
student1 = Student.objects.get(last_name='Fellmann')
self.assertEqual(student1.corporation.name, "Crèche Les Mousaillons")
self.assertEqual(student1.option_ase.name, "Accompagnement des enfants")
# Instructor not set through this import
self.assertIsNone(student1.instructor)

View file

@ -23,7 +23,7 @@ from django.views.generic import DetailView, FormView, TemplateView, ListView
from .forms import PeriodForm, StudentImportForm, UploadHPFileForm
from .models import (
Klass, Section, Student, Teacher, Corporation, CorpContact, Course, Period,
Klass, Section, Option, Student, Teacher, Corporation, CorpContact, Course, Period,
Training, Availability,
)
from .pdf import UpdateDataFormPDF
@ -342,6 +342,11 @@ class StudentImportView(ImportViewBase):
seen_students_ids.add(student_defaults['ext_id'])
if isinstance(student_defaults['birth_date'], str):
student_defaults['birth_date'] = datetime.strptime(student_defaults['birth_date'], '%d.%m.%Y').date()
if student_defaults['option_ase']:
try:
student_defaults['option_ase'] = Option.objects.get(name=student_defaults['option_ase'])
except Option.DoesNotExist:
del student_defaults['option_ase']
corporation_defaults = {
val: strip(line[key]) for key, val in corporation_mapping.items()