2014-09-19 11:52:56 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from frontend.models import PersonGlobalIdentity, CitaviProjectIdentity
|
|
|
|
|
|
|
|
|
|
|
|
class PersonIdentityManager():
|
2014-09-29 13:40:07 +02:00
|
|
|
""" Class wrapping the django model layer to manage identities. """
|
2014-09-19 11:52:56 +02:00
|
|
|
def create_identity(self, project, uuid):
|
2014-09-29 13:40:07 +02:00
|
|
|
""" Creates a new identity and connects it to the given citavi project uuid. """
|
2014-09-19 11:52:56 +02:00
|
|
|
pgi = PersonGlobalIdentity(type='citavi')
|
|
|
|
pgi.save()
|
2014-09-19 16:22:11 +02:00
|
|
|
cpi = CitaviProjectIdentity(global_identity=pgi, project=project, citavi_uuid=uuid, preferred=True)
|
2014-09-19 11:52:56 +02:00
|
|
|
cpi.save()
|
|
|
|
return cpi
|
|
|
|
|
|
|
|
def add_identity_to_global_identity(self, global_identity, project, uuid, preferred):
|
2014-09-29 13:40:07 +02:00
|
|
|
""" Maps given citavi project identity to existing global identity. """
|
2014-10-01 11:26:11 +02:00
|
|
|
# First, fetch all involved CitaviProjectIdentities and set them to preferred=False
|
|
|
|
CitaviProjectIdentity.objects.filter(global_identity=global_identity).update(preferred=False)
|
|
|
|
# Then add the new primary ProjectIdentity.
|
2014-09-29 16:51:50 +02:00
|
|
|
cpi = CitaviProjectIdentity(global_identity=global_identity, project=project, citavi_uuid=uuid, preferred=preferred)
|
2014-09-19 11:52:56 +02:00
|
|
|
cpi.save()
|
|
|
|
return cpi
|
|
|
|
|
|
|
|
def get_global_identities(self):
|
2014-09-29 13:40:07 +02:00
|
|
|
""" Returns all global identities. """
|
2014-09-19 11:52:56 +02:00
|
|
|
return PersonGlobalIdentity.objects.all()
|
|
|
|
|
2014-09-25 17:36:42 +02:00
|
|
|
def get_mapped_identities_for_project(self, project_instance):
|
2014-09-29 13:40:07 +02:00
|
|
|
""" Returns all existing (mapped) identies for a given project. """
|
2014-09-25 17:36:42 +02:00
|
|
|
return CitaviProjectIdentity.objects.filter(project=project_instance).all()
|
2014-09-29 15:01:35 +02:00
|
|
|
|
|
|
|
def get_citavi_identity_by_global_identity(self, global_identity):
|
|
|
|
""" Returns the preferred citavi identity based on their global identity. """
|
|
|
|
return CitaviProjectIdentity.objects.filter(global_identity=global_identity, preferred=True).all()[0]
|