citavi_mapper/service/Django.py

29 lines
1.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from frontend.models import PersonGlobalIdentity, CitaviProjectIdentity
class PersonIdentityManager():
""" Class wrapping the django model layer to manage identities. """
def create_identity(self, project, uuid):
""" Creates a new identity and connects it to the given citavi project uuid. """
pgi = PersonGlobalIdentity(type='citavi')
pgi.save()
cpi = CitaviProjectIdentity(global_identity=pgi, project=project, citavi_uuid=uuid, preferred=True)
cpi.save()
return cpi
def add_identity_to_global_identity(self, global_identity, project, uuid, preferred):
""" Maps given citavi project identity to existing global identity. """
cpi = CitaviProjectIdentity(global_identity=global_identity, project=project, citavi_uuid=uuid, preferred=True)
cpi.save()
return cpi
def get_global_identities(self):
""" Returns all global identities. """
return PersonGlobalIdentity.objects.all()
def get_mapped_identities_for_project(self, project_instance):
""" Returns all existing (mapped) identies for a given project. """
return CitaviProjectIdentity.objects.filter(project=project_instance).all()