From: Guillaume Pellerin Date: Tue, 16 Mar 2021 21:42:29 +0000 (+0100) Subject: add period to XLS read command X-Git-Tag: 1.4.3~18 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=6ee6dacb0d23fc4dfa4ecc264fba77760b468536;p=teleforma.git add period to XLS read command --- diff --git a/teleforma/management/commands/teleforma-import-students-from-xls.py b/teleforma/management/commands/teleforma-import-students-from-xls.py index 30e1d7f5..16fe6141 100644 --- a/teleforma/management/commands/teleforma-import-students-from-xls.py +++ b/teleforma/management/commands/teleforma-import-students-from-xls.py @@ -16,8 +16,9 @@ class Command(BaseCommand): def handle(self, *args, **options): file = args[0] + period = args[1] xls = UserXLSBook() - xls.read(file) + xls.read(file, period) diff --git a/teleforma/views/crfpa.py b/teleforma/views/crfpa.py index 2a8a824c..4616297f 100644 --- a/teleforma/views/crfpa.py +++ b/teleforma/views/crfpa.py @@ -397,7 +397,7 @@ class UserXLSBook(object): pydate = datetime.datetime(day=int(date_split[0]), month=int(date_split[1]), year=int(date_split[2])) return pydate - def import_user(self, row): + def import_user(self, row, period): last_name = row[0] first_name = row[1] iej = row[2] @@ -423,6 +423,7 @@ class UserXLSBook(object): subscription_fees = row[22] fascicule_sent = row[23] + period = Period.objects.get(name=period) users = User.objects.filter(first_name=first_name, last_name=last_name, email=email) if not users: @@ -443,6 +444,7 @@ class UserXLSBook(object): student = Student(user=user) student.user = user + studnet.period = period student.iej = IEJ.objects.get(name=iej) student.save() student.trainings.add(Training.objects.get(code=training)) @@ -475,7 +477,7 @@ class UserXLSBook(object): i += 2 - def read(self, path): + def read(self, path, period): cols = [{'name':'NOM', 'width':5000}, {'name':'PRENOM', 'width':5000}, @@ -506,8 +508,8 @@ class UserXLSBook(object): book = xlrd.open_workbook(path) sheet = book.sheet_by_index(0) - for rx in range(sheet.nrows): - self.import_user(sheet.row_values(rx)) + for rx in range(1, sheet.nrows): + self.import_user(sheet.row_values(rx), period) class UsersExportView(UsersView):