Adapted student import to new file format

This commit is contained in:
Claude Paroz 2017-07-12 09:53:25 +02:00
parent 673f88e232
commit 8d30c7f76b
5 changed files with 111 additions and 24 deletions

View file

@ -132,19 +132,42 @@ class Student(models.Model):
return '%d ans%s' % (age_y, ' %d m.' % age_m if age_m > 0 else '')
@classmethod
def prepare_import(cls, values):
def prepare_import(cls, student_values, corp_values, inst_values):
''' Hook for tabimport, before new object get created '''
if 'klass' in values:
if 'klass' in student_values:
try:
k = Klass.objects.get(name=values['klass'])
k = Klass.objects.get(name=student_values['klass'])
except Klass.DoesNotExist:
raise Exception("La classe '%s' n'existe pas encore" % values['klass'])
values['klass'] = k
raise Exception("La classe '%s' n'existe pas encore" % student_values['klass'])
student_values['klass'] = k
if 'corporation' in student_values:
if 'city' in corp_values and is_int(corp_values['city'][:4]):
corp_values['pcode'], _, corp_values['city'] = corp_values['city'].partition(' ')
if student_values['corporation'] != '':
obj, created = Corporation.objects.get_or_create(
ext_id=student_values['corporation'],
defaults = corp_values
)
inst_values['corporation'] = obj
student_values['corporation'] = obj
else:
student_values['corporation'] = None
if 'instructor' in student_values:
if student_values['instructor'] != '':
obj, created = CorpContact.objects.get_or_create(
ext_id=student_values['instructor'],
defaults = inst_values
)
student_values['instructor'] = obj
else:
student_values['instructor'] = None
# See if postal code included in city, and split them
if 'city' in values and is_int(values['city'][:4]):
values['pcode'], _, values['city'] = values['city'].partition(' ')
values['archived'] = False
return values
if 'city' in student_values and is_int(student_values['city'][:4]):
student_values['pcode'], _, student_values['city'] = student_values['city'].partition(' ')
student_values['archived'] = False
return student_values
class Referent(models.Model):