2014-09-19 11:52:56 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from Citavi import ProjectManager
|
|
|
|
from Django import PersonIdentityManager
|
|
|
|
|
|
|
|
class PersonMapper():
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self._citavi_project_manager = ProjectManager()
|
|
|
|
self._person_identity_manager = PersonIdentityManager()
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
del self._citavi_project_manager
|
|
|
|
del self._person_identity_manager
|
|
|
|
|
|
|
|
def get_unmapped_identities(self, project):
|
|
|
|
citavi_persons = self._citavi_project_manager.get_persons_from_project(project.id)
|
|
|
|
mapped_persons = self._person_identity_manager.get_mapped_identities_for_project(project)
|
|
|
|
|
2014-09-19 16:22:11 +02:00
|
|
|
print "Len citavi persons: " + str(len(citavi_persons))
|
|
|
|
print "Len mapped persons: " + str(len(mapped_persons))
|
|
|
|
|
|
|
|
if len(mapped_persons) == 0:
|
|
|
|
return citavi_persons
|
|
|
|
|
|
|
|
# Prepare citavi_persons into a uuid->person dict, then eliminate mapped ones. This is ugly and a little slow.
|
|
|
|
citavi_uuid_dict = {}
|
2014-09-19 11:52:56 +02:00
|
|
|
for person in citavi_persons:
|
2014-09-19 16:22:11 +02:00
|
|
|
citavi_uuid_dict[person.ID] = person
|
|
|
|
|
|
|
|
print len(citavi_uuid_dict)
|
2014-09-19 11:52:56 +02:00
|
|
|
|
|
|
|
for person in mapped_persons:
|
2014-09-19 16:22:11 +02:00
|
|
|
if person.citavi_uuid in citavi_uuid_dict:
|
|
|
|
# print "Match for: " + str(person.id) + " - uuid: " + str(person.citavi_uuid)
|
|
|
|
del citavi_uuid_dict[person.citavi_uuid]
|
|
|
|
|
|
|
|
print len(citavi_uuid_dict)
|
|
|
|
|
|
|
|
return citavi_uuid_dict
|
|
|
|
|
|
|
|
def create_new_identity(self, project, person):
|
|
|
|
self._person_identity_manager.create_identity(project, person.ID)
|
2014-09-19 11:52:56 +02:00
|
|
|
|
|
|
|
def test():
|
|
|
|
from frontend.models import Project
|
|
|
|
project = Project.objects.get(id=1)
|
|
|
|
p = PersonMapper()
|
2014-09-19 16:22:11 +02:00
|
|
|
unmapped = p.get_unmapped_identities(project)
|
|
|
|
print unmapped
|
|
|
|
# for person in unmapped:
|
|
|
|
# p.create_new_identity(project, person)
|