From 162a362b43a90fa51167543502bea135252ee392 Mon Sep 17 00:00:00 2001 From: Emilie Date: Fri, 23 Dec 2016 18:52:03 +0100 Subject: [PATCH] [Timesheet] : command to import figgo id's --- app/organization/network/admin.py | 4 +- .../management/commands/import-figgo-id.py | 63 +++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 app/organization/network/management/commands/import-figgo-id.py diff --git a/app/organization/network/admin.py b/app/organization/network/admin.py index 1170b990..f9a8b6bf 100644 --- a/app/organization/network/admin.py +++ b/app/organization/network/admin.py @@ -191,7 +191,7 @@ class PersonAdmin(BaseTranslationOrderedModelAdmin): list_display = [ 'last_name', 'first_name', 'register_id', 'external_id', 'email', 'gender', 'created'] list_filter = ['person_title', 'activities__date_from', 'activities__date_to', 'activities__is_permanent', 'activities__framework', 'activities__grade', - 'activities__status', 'activities__teams', 'activities__projects',] + 'activities__status', 'activities__teams', 'activities__projects'] class PersonActivityAdmin(BaseTranslationModelAdmin): @@ -203,7 +203,7 @@ class PersonActivityAdmin(BaseTranslationModelAdmin): search_fields = ['person__title',] list_filter = [ 'date_from', 'date_to', 'is_permanent', 'framework', 'grade', - 'status', 'teams', 'projects',] + 'status', 'teams', 'projects'] def get_teams(self, instance): values = [] diff --git a/app/organization/network/management/commands/import-figgo-id.py b/app/organization/network/management/commands/import-figgo-id.py new file mode 100644 index 00000000..c6d637b6 --- /dev/null +++ b/app/organization/network/management/commands/import-figgo-id.py @@ -0,0 +1,63 @@ +# -*- 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 json +import unicodedata +from requests.auth import HTTPBasicAuth +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 figgo id from api + python manage.py import-figo-id + """ + number_of_person = 0 + def handle(self, *args, **options): + # process active person + r_p_active = requests.get('https://ircam.ilucca.net/api/users?fields=id,lastname,firstname', + headers={'Authorization': 'Lucca application=bd6d5481-40eb-414b-9135-434e12749223'}) + self.update_external_id(r_p_active.json()) + + # process INactive person + r_p_inactive = requests.get('https://ircam.ilucca.net/api/users?dtContractEnd=until,2016-12-31,null&fields=id,lastname,firstname', + headers={'Authorization': 'Lucca application=bd6d5481-40eb-414b-9135-434e12749223'}) + self.update_external_id(r_p_inactive.json()) + + print('***************************************************') + print("Number of person processed : "+str(self.number_of_person)) + print('***************************************************') + + 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( ' ', '-') + person = Person.objects.filter(slug__contains=slug) + if person: + self.number_of_person += 1 + # persons have sometimes two ids + for p in person: + p.external_id = figgo_user['id'] + p.save() + else : + print("Person not found: "+figgo_user['lastName']+' '+figgo_user['firstName']+' | manual slug : '+ slug) -- 2.39.5