From 541796d5b3f6002b9be9a3b510d3e18bfca65134 Mon Sep 17 00:00:00 2001 From: Emilie Date: Fri, 23 Dec 2016 20:15:09 +0100 Subject: [PATCH] [Timesheet] : xlsx register id ircam --- .../management/commands/import-figgo-id.py | 2 +- .../commands/import-ircam-matricule.py | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 app/organization/network/management/commands/import-ircam-matricule.py diff --git a/app/organization/network/management/commands/import-figgo-id.py b/app/organization/network/management/commands/import-figgo-id.py index 1ae8efb6..5d07c894 100644 --- a/app/organization/network/management/commands/import-figgo-id.py +++ b/app/organization/network/management/commands/import-figgo-id.py @@ -48,7 +48,7 @@ class Command(BaseCommand): def update_external_id(self, figgo_users): for figgo_user in figgo_users['data']: - slug = slugify(figgo_user['firstName'].lower()+'-'+figgo_user['lastName'].lower()) #).replace( ' ', '-') + slug = slugify(figgo_user['firstName']+'-'+figgo_user['lastName']) person = Person.objects.filter(slug__contains=slug) if person: self.number_of_person += 1 diff --git a/app/organization/network/management/commands/import-ircam-matricule.py b/app/organization/network/management/commands/import-ircam-matricule.py new file mode 100644 index 00000000..be38a45f --- /dev/null +++ b/app/organization/network/management/commands/import-ircam-matricule.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2016-2017 Ircam +# Copyright (c) 2016-2017 Guillaume Pellerin +# Copyright (c) 2016-2017 Emilie Zawadzki + +# This file is part of mezzanine-organization. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import requests +import os +import unicodedata +import xlrd +from optparse import make_option +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError +from organization.network.models import Person +from django.utils.text import slugify + + +class Command(BaseCommand): + help = """Import register id from xlsx file + python manage.py import-ircam-matricule -s /srv/backup/MatriculesIrcamR\&D_2015-2016.xlsx + """ + option_list = BaseCommand.option_list + ( + make_option('-s', '--source', + dest='source_file', + help='define the XLS source file'), + ) + number_of_person = 0 + + def handle(self, *args, **kwargs): + + self.source_file = os.path.abspath(kwargs.get('source_file')) + self.book = xlrd.open_workbook(self.source_file) + self.sheet = self.book.sheet_by_index(0) + self.first_row = self.sheet.row(0) + num_cols = self.sheet.ncols + for row_idx in range(0, self.sheet.nrows): # Iterate through rows + cell_id = self.sheet.cell(row_idx, 0).value + cell_last_name = self.sheet.cell(row_idx, 1).value + cell_first_name = self.sheet.cell(row_idx, 2).value + self.update_register_id(cell_id, cell_last_name, cell_first_name) + + print('***************************************************') + print("Number of person processed : "+str(self.number_of_person)) + print('***************************************************') + + def update_register_id(self, id, last_name, first_name): + slug = slugify(first_name+'-'+last_name) + person = Person.objects.filter(slug__contains=slug) + if person: + self.number_of_person += 1 + # persons have sometimes two ids + for p in person: + p.register_id = id + p.save() + else : + print("Person not found: "+last_name+' '+first_name+' | manual slug : '+ slug) -- 2.39.5