]> git.parisson.com Git - mezzo.git/commitdiff
[Timesheet] : xlsx register id ircam
authorEmilie <zawadzki@ircam.fr>
Fri, 23 Dec 2016 19:15:09 +0000 (20:15 +0100)
committerEmilie <zawadzki@ircam.fr>
Fri, 23 Dec 2016 19:15:09 +0000 (20:15 +0100)
app/organization/network/management/commands/import-figgo-id.py
app/organization/network/management/commands/import-ircam-matricule.py [new file with mode: 0644]

index 1ae8efb608e3b5f28d54cf562c1fbd6da44ec468..5d07c894fa2faa2f66d78399050d5fca7ace877d 100644 (file)
@@ -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 (file)
index 0000000..be38a45
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+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)