diff --git a/frontend/models.py b/frontend/models.py index f57520f..abc2734 100644 --- a/frontend/models.py +++ b/frontend/models.py @@ -28,10 +28,10 @@ class PersonGlobalIdentity(models.Model): class CitaviProjectIdentity(models.Model): global_identity = models.ForeignKey(PersonGlobalIdentity, blank=True, null=True) - project_id = models.ForeignKey(Project, blank=False, null=False) + project = models.ForeignKey(Project, blank=False, null=False) citavi_uuid = models.CharField(max_length=255, blank=False, null=False) - preferred_id = models.BooleanField() + preferred = models.BooleanField() def __unicode__(self): - repr = "" + repr = "" return repr diff --git a/service/Django.py b/service/Django.py new file mode 100644 index 0000000..e80840a --- /dev/null +++ b/service/Django.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +from frontend.models import PersonGlobalIdentity, CitaviProjectIdentity + + +class PersonIdentityManager(): + + def create_identity(self, project, uuid): + pgi = PersonGlobalIdentity(type='citavi') + pgi.save() + cpi = CitaviProjectIdentity(global_identity=pgi, project=project, citavi_uuid=uuid, preferred_id=True) + cpi.save() + return cpi + + def add_identity_to_global_identity(self, global_identity, project, uuid, preferred): + cpi = CitaviProjectIdentity(global_identity=global_identity, project=project, citavi_uuid=uuid, preferred_id=True) + cpi.save() + return cpi + + def get_global_identities(self): + return PersonGlobalIdentity.objects.all() + + def get_mapped_identities_for_project(self, project): + return CitaviProjectIdentity.objects.filter(project=project).all() diff --git a/service/Mapper.py b/service/Mapper.py new file mode 100644 index 0000000..e319fd5 --- /dev/null +++ b/service/Mapper.py @@ -0,0 +1,37 @@ +# -*- 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 "#" + print citavi_persons + print "##" + print mapped_persons + print "###" + + for person in citavi_persons: + print str(person) + print "########################################\n########################################" + + for person in mapped_persons: + # TODO: Actually use this loop to remove persons in citavi_persons, return the rest. + print str(person) + +def test(): + from frontend.models import Project + project = Project.objects.get(id=1) + p = PersonMapper() + p.get_unmapped_identities(project)