Revision 69e79c82
Added by Jérôme Schneider about 13 years ago
| scripts/import_ev_reunion.py | ||
|---|---|---|
|
Import reunion and
|
||
|
"""
|
||
|
|
||
|
|
||
|
import os
|
||
|
import csv
|
||
|
|
||
|
import logging
|
||
|
from datetime import datetime, timedelta
|
||
|
|
||
|
import calebasse.settings
|
||
| ... | ... | |
|
|
||
|
|
||
|
from calebasse.agenda.models import Event, EventType
|
||
|
from calebasse.personnes.models import Worker
|
||
|
from calebasse.ressources.models import Service
|
||
|
|
||
|
# Configuration
|
||
|
db_path = "./scripts/20121221-192258"
|
||
|
log_file = "./scripts/import_ev_reunion.log"
|
||
|
|
||
|
dbs = ["F_ST_ETIENNE_SESSAD_TED", "F_ST_ETIENNE_CMPP", "F_ST_ETIENNE_CAMSP", "F_ST_ETIENNE_SESSAD"]
|
||
|
tables = ['rs', 'ev', 'details_rs', 'details_ev']
|
||
| ... | ... | |
|
def create_event(line, service, tables_data):
|
||
|
if not Event.objects.filter(old_ev_id=line['id']):
|
||
|
event_type = EventType.objects.get(id=4)
|
||
|
date_debut, heure, duree
|
||
|
start_datetime = datetime.strptime(
|
||
|
line['date_debut'][:-13] + ' ' + line['heure'][11:-4],
|
||
|
line['date_rdv'][:-13] + ' ' + line['heure'][11:-4],
|
||
|
"%Y-%m-%d %H:%M:%S")
|
||
|
end_datetime = start_datetime + timedelta(
|
||
|
hours=int(secondsline['duree'][11:-10]),
|
||
|
minutes=int(secondsline['duree'][14:-7]),
|
||
|
hours=int(line['duree'][11:-10]),
|
||
|
minutes=int(line['duree'][14:-7]),
|
||
|
)
|
||
|
# TODO: add pariticipants
|
||
|
# Find therapists
|
||
|
p_ids = []
|
||
|
for id, detail_rs in tables_data['details_rs'].iteritems():
|
||
|
if detail_rs['rs_id'] == line['id']:
|
||
|
p_ids.append(detail_rs['thera_id'])
|
||
|
participants = []
|
||
|
|
||
|
for p_id in p_ids:
|
||
|
try:
|
||
|
if service.name == "CMPP":
|
||
|
participants.append(Worker.objects.get(old_cmpp_id=int(p_id)))
|
||
|
elif service.name == "CAMSP":
|
||
|
participants.append(Worker.objects.get(old_camsp_id=int(p_id)))
|
||
|
elif service.name == "SESSAD DYS":
|
||
|
participants.append(Worker.objects.get(old_sessad_dys_id=int(p_id)))
|
||
|
elif service.name == "SESSAD TED":
|
||
|
participants.append(Worker.objects.get(old_sessad_ted_id=int(p_id)))
|
||
|
except Worker.DoesNotExist:
|
||
|
logging.warning("rs_id %s thera_id %s" % (line['id'], p_id) + " therapeute non trouve " + service.name)
|
||
|
|
||
|
event = Event.objects.create(
|
||
|
title=line['libelle'],
|
||
|
title=line['libelle'][:60],
|
||
|
description=line['texte'],
|
||
|
event_type=event_type,
|
||
|
start_datetime=start_datetime,
|
||
|
end_datetime=end_datetime,
|
||
|
#participants=,
|
||
|
old_ev_id=line["id"],
|
||
|
old_ev_id=line['id'],
|
||
|
)
|
||
|
event.services = [service]
|
||
|
event.participants = participants
|
||
|
event.save()
|
||
|
|
||
|
def main():
|
||
|
logging.basicConfig(filename=log_file,level=logging.DEBUG)
|
||
|
for db in dbs:
|
||
|
if "F_ST_ETIENNE_CMPP" == db:
|
||
|
service = Service.objects.get(name="CMPP")
|
||
| ... | ... | |
|
|
||
|
for id, line in tables_data['ev'].iteritems():
|
||
|
if line['libelle'].upper() not in ('ARRIVEE', 'DEPART'):
|
||
|
print line
|
||
|
#print line['rythme']
|
||
|
pass
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|
||
Also available in: Unified diff
import ev: manage ev autre simple