[TASK] Little model workover, introducing Mapper package with PersonMapper.
This commit is contained in:
parent
0952922757
commit
25e97c94b5
|
@ -28,10 +28,10 @@ class PersonGlobalIdentity(models.Model):
|
||||||
|
|
||||||
class CitaviProjectIdentity(models.Model):
|
class CitaviProjectIdentity(models.Model):
|
||||||
global_identity = models.ForeignKey(PersonGlobalIdentity, blank=True, null=True)
|
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)
|
citavi_uuid = models.CharField(max_length=255, blank=False, null=False)
|
||||||
preferred_id = models.BooleanField()
|
preferred = models.BooleanField()
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
repr = "<CitaviProjectIdentity project_id=" + str(self.project_id) + ", citavi_uuid=" + self.citavi_uuid + ", global_identity=" + str(self.global_identity) + ", preferred=" + str(self.preferred_id) + ">"
|
repr = "<CitaviProjectIdentity project=" + str(self.project) + ", citavi_uuid=" + self.citavi_uuid + ", global_identity=" + str(self.global_identity) + ", preferred=" + str(self.preferred) + ">"
|
||||||
return repr
|
return repr
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue