citavi_mapper/service/Mapper.py

53 lines
1.8 KiB
Python
Raw Normal View History

# -*- 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)
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 = {}
for person in citavi_persons:
citavi_uuid_dict[person.ID] = person
print len(citavi_uuid_dict)
for person in mapped_persons:
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)
def test():
from frontend.models import Project
project = Project.objects.get(id=1)
p = PersonMapper()
unmapped = p.get_unmapped_identities(project)
print unmapped
# for person in unmapped:
# p.create_new_identity(project, person)