[TASK] Little model workover, introducing Mapper package with PersonMapper.
This commit is contained in:
1 parent
0952922757
commit
25e97c94b5
3 files changed
+64
-3
No files matched your search
@@ -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()
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user