scripts: undouble some forgotten workers in prgress (#2381).

This commit is contained in:
Mikaël Ates 2013-01-23 21:08:41 +01:00
parent d0f605e5c8
commit 9688cc1f78
2 changed files with 165 additions and 0 deletions

View File

@ -0,0 +1,137 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import csv
import codecs
import string
import random
from datetime import datetime, time
import django.core.management
import calebasse.settings
django.core.management.setup_environ(calebasse.settings)
from django.contrib.auth.models import User
from calebasse.actes.models import EventAct
from calebasse.agenda.models import Event, EventType
from calebasse.dossiers.models import PatientRecord, Status, FileState
from calebasse.ressources.models import Service
from calebasse.personnes.models import Worker, Holiday, UserWorker
from calebasse.ressources.models import WorkerType
f_inter = "./scripts/recup_intervenants.csv"
def _exist(str):
if str and str != "" and str != '0':
return True
return False
def treat_name(name):
res = ''
for p in name.split():
res += p[0].upper()+p[1:].lower()
res += ' '
return res[:-1]
def _to_date(str_date):
if not str_date:
return None
return datetime.strptime(str_date[:-13], "%Y-%m-%d")
def _to_int(str_int):
if not str_int:
return None
return int(str_int)
def _get_dict(cols, line):
""""""
res = {}
for i, data in enumerate(line):
res[cols[i]] = data.decode('utf-8')
return res
from django.db import transaction
@transaction.commit_manually
def main():
print datetime.now()
'''User and worker'''
cmpp = Service.objects.get(name="CMPP")
camsp = Service.objects.get(name="CAMSP")
sessad_ted = Service.objects.get(name="SESSAD TED")
sessad_dys = Service.objects.get(name="SESSAD DYS")
type_stagiaire = WorkerType.objects.get(pk=21)
type_ortho_lib = WorkerType.objects.get(pk=22)
print "--> Chargement des intervenants..."
csvfile = open(f_inter, 'rb')
csvlines = UnicodeReader(csvfile, delimiter=';', quotechar='|',encoding='utf-8')
csvlines.next()
cols = csvlines.next()
intervenants = []
for line in csvlines:
data = _get_dict(pc_cols, line)
intervenants.append(data)
csvfile.close()
print "<-- Terminé"
for intervenant in intervenants:
is_user = False
if intervenant['Pk type'] == '21':
is_user = True
user = None
if is_user:
username = intervenant['prenom'][0].lower() + intervenant['nom'].lower()
digits = rdm_str = ''.join(random.choice(string.digits) for x in range(4))
passwd = intervenant['prenom'][0].lower() + intervenant['nom'][0].lower() + digits
user = User(username=username)
user.set_password(passwd)
user.save()
last_name = intervenant['nom']
first_name = intervenant['prenom']
type = None
if intervenant['Pk type'] == '21':
type = type_stagiaire
else:
type = type_ortho_lib
enabled = True
old_camsp_id = intervenant['old_camsp_id']
old_cmpp_id = intervenant['old_cmpp_id']
old_sessad_dys_id = intervenant['old_sessad_dys_id']
old_sessad_ted_id = intervenant['old_sessad_ted_id']
worker = Worker(last_name=last_name, first_name=first_name,
type=type,
old_camsp_id=old_camsp_id, old_cmpp_id=old_cmpp_id,
old_sessad_dys_id=old_sessad_dys_id, old_sessad_ted_id=old_sessad_ted_id,
enabled=enabled)
worker.save()
if old_camsp_id and old_camsp_id != '':
worker.services.add(camsp)
if old_cmpp_id and old_cmpp_id != '':
worker.services.add(cmpp)
if old_sessad_dys_id and old_sessad_dys_id != '':
worker.services.add(sessad_dys)
if old_sessad_ted_id and old_sessad_ted_id != '':
worker.services.add(sessad_ted)
worker.save()
if is_user:
UserWorker(user=user,worker=worker).save()
clones = []
# Worker.objects.get -> recuperer les anciens importés via le old_id dans chaque service
# Rechercher tous leur events, acts, etc et leur associer au worker cree
# détruire les clones
# Ecrire dans un fichier les logins et password des stagiaires
transaction.commit()
print datetime.now()
if __name__ == "__main__":
main()

View File

@ -0,0 +1,28 @@
|nom|;|prenom|;|Pk type|;|type readable|;|old_cmpp_id|;|old_camsp_id|;|old_sessad_dys_id|;|old_sessad_ted_id|
|Berroukeche|;|Hayat|;21;|Stagiaire|;70;;;
|Blondiau|;|Mathilde|;21;|Stagiaire|;87;;;
|Boichon|;|Annabelle|;22;|Orthophoniste liberal|;;;39;
|Bonnefoy|;|Delphine|;22;|Orthophoniste liberal|;;;38;
|Bordron|;|Amandine|;21;|Stagiaire|;65;;;
|Courbon|;|Jessica|;22;|Orthophoniste liberal|;;;46;
|Daguin|;|Caroline|;21;|Stagiaire|;;22;;
|Djouder|;|Myriam|;21;|Stagiaire|;;18;;
|Dubois|;|Laetitia|;21;|Stagiaire|;71;27;41;
|Ducher-Thollot|;|Geneviève|;22;|Orthophoniste liberal|;;;43;
|Fer|;|Anais|;21;|Stagiaire|;;;40;
|Fijal|;|Aleksandra|;21;|Stagiaire|;92;36;;
|Francois|;|Muriel|;22;|Orthophoniste liberal|;;;18;
|Gerin|;|Fabien|;21;|Stagiaire|;88;;;
|Gouby|;|Françoise|;22;|Orthophoniste liberal|;;;24;
|Grelier|;|Caroline|;21;|Stagiaire|;;21;;
|Grenier|;|Pauline|;22;|Orthophoniste liberal|;;;53;
|Guidicelli|;;22;|Orthophoniste liberal|;;;19;
|Imbert|;|Nelly|;22;|Orthophoniste liberal|;;;47;
|Peyrard|;|Arthur|;21;|Stagiaire|;81;32;;
|Piot|;|Flavie|;21;|Stagiaire|;93;;;
|Robles|;|Maud|;21;|Stagiaire|;69;;;
|Roche|;|Sophie|;21;|Stagiaire|;86;;;
|Ruault|;|Christine|;22;|Orthophoniste liberal|;;;25;
|Souchon|;|Violaine|;22;|Orthophoniste liberal|;;;51;
|Valentin|;|Véronique|;22;|Orthophoniste liberal|;;;32;
|Von Dahlern|;|Claire|;22;|Orthophoniste liberal|;;;31;
1 |nom| |prenom| |Pk type| |type readable| |old_cmpp_id| |old_camsp_id| |old_sessad_dys_id| |old_sessad_ted_id|
2 |Berroukeche| |Hayat| 21 |Stagiaire| 70
3 |Blondiau| |Mathilde| 21 |Stagiaire| 87
4 |Boichon| |Annabelle| 22 |Orthophoniste liberal| 39
5 |Bonnefoy| |Delphine| 22 |Orthophoniste liberal| 38
6 |Bordron| |Amandine| 21 |Stagiaire| 65
7 |Courbon| |Jessica| 22 |Orthophoniste liberal| 46
8 |Daguin| |Caroline| 21 |Stagiaire| 22
9 |Djouder| |Myriam| 21 |Stagiaire| 18
10 |Dubois| |Laetitia| 21 |Stagiaire| 71 27 41
11 |Ducher-Thollot| |Geneviève| 22 |Orthophoniste liberal| 43
12 |Fer| |Anais| 21 |Stagiaire| 40
13 |Fijal| |Aleksandra| 21 |Stagiaire| 92 36
14 |Francois| |Muriel| 22 |Orthophoniste liberal| 18
15 |Gerin| |Fabien| 21 |Stagiaire| 88
16 |Gouby| |Françoise| 22 |Orthophoniste liberal| 24
17 |Grelier| |Caroline| 21 |Stagiaire| 21
18 |Grenier| |Pauline| 22 |Orthophoniste liberal| 53
19 |Guidicelli| 22 |Orthophoniste liberal| 19
20 |Imbert| |Nelly| 22 |Orthophoniste liberal| 47
21 |Peyrard| |Arthur| 21 |Stagiaire| 81 32
22 |Piot| |Flavie| 21 |Stagiaire| 93
23 |Robles| |Maud| 21 |Stagiaire| 69
24 |Roche| |Sophie| 21 |Stagiaire| 86
25 |Ruault| |Christine| 22 |Orthophoniste liberal| 25
26 |Souchon| |Violaine| 22 |Orthophoniste liberal| 51
27 |Valentin| |Véronique| 22 |Orthophoniste liberal| 32
28 |Von Dahlern| |Claire| 22 |Orthophoniste liberal| 31