diff --git a/citavi_mapper/settings.py b/citavi_mapper/settings.py index bdd8a96..55796a0 100644 --- a/citavi_mapper/settings.py +++ b/citavi_mapper/settings.py @@ -21,7 +21,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__)) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -#PIPELINE_ENABLED = False +# PIPELINE_ENABLED = False TEMPLATE_DEBUG = True @@ -74,7 +74,7 @@ STATIC_ROOT = os.path.join(BASE_DIR, "static") STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage' STATICFILES_DIRS = (os.path.join(BASE_DIR, 'contrib'),) -MEDIA_ROOT = os.path.join(BASE_DIR, "media") +MEDIA_ROOT = os.path.join(BASE_DIR, "media") PIPELINE_COMPILERS = ( 'pipeline.compilers.less.LessCompiler', diff --git a/frontend/forms.py b/frontend/forms.py index f2eea1b..8f53271 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -61,10 +61,11 @@ class PersonMapForm(forms.Form): self.helper.layout = Layout( u'action', u'global_identity', + u'preferred_identity', Submit(u'skip', u'Skip', css_class=u'btn-default'), Submit(u'save-continue', u'Save and continue', css_class=u'btn-default'), ) action = forms.ChoiceField(choices=[(u'new', u'Create new global Identity'), (u'existing', u'Map to existing identity')], initial=u'new', widget=forms.RadioSelect()) global_identity = forms.ModelChoiceField(queryset=PersonGlobalIdentity.objects.all(), required=False) - + preferred_identity = forms.BooleanField(initial=False, required=False) diff --git a/frontend/models.py b/frontend/models.py index 59907fb..09174b5 100644 --- a/frontend/models.py +++ b/frontend/models.py @@ -25,14 +25,14 @@ class PersonGlobalIdentity(models.Model): def __unicode__(self): from service.Mapper import PersonMapper pm = PersonMapper() - return u"" + return u"" class CitaviProjectIdentity(models.Model): """ Model representing an identity from a citavi project. """ - global_identity = models.ForeignKey(PersonGlobalIdentity, blank=True, null=True) - project = models.ForeignKey(Project, blank=False, null=False) - citavi_uuid = models.CharField(max_length=255, blank=False, null=False) + global_identity = models.ForeignKey(PersonGlobalIdentity, blank=True, null=True, db_index=True) + project = models.ForeignKey(Project, blank=False, null=False, db_index=True) + citavi_uuid = models.CharField(max_length=255, blank=False, null=False, db_index=True) preferred = models.BooleanField() def __unicode__(self): diff --git a/frontend/templates/project/view-person.html b/frontend/templates/project/view-person.html index 1539ab0..a613f39 100644 --- a/frontend/templates/project/view-person.html +++ b/frontend/templates/project/view-person.html @@ -65,15 +65,17 @@ Citavi_UUID - Features + Name + Global Identity Features {% for person_id, person in mapped_persons.items %} - {{person.citavi_uuid}} - {{person.global_identity}} + {{person.0.citavi_uuid}} + {{person.1}} + {{person.0.global_identity}} Delete Mapping diff --git a/frontend/views.py b/frontend/views.py index 7405c24..bf4b53d 100644 --- a/frontend/views.py +++ b/frontend/views.py @@ -190,7 +190,8 @@ class ProjectPersonView(ProtectedFormView, SingleObjectMixin): from service import Mapper pm = Mapper.PersonMapper() kwargs[u'unmapped_persons'] = pm.get_unmapped_identities(project) - kwargs[u'mapped_persons'] = pm.get_mapped_identities(project) + kwargs[u'mapped_persons'] = pm.get_mapped_identities_with_representation(project) + kwargs[u'mapped_persons'] = pm.get_mapped_identities_with_representation(project) return super(ProjectPersonView, self).get_context_data(**kwargs) def get(self, request, *args, **kwargs): @@ -240,12 +241,16 @@ class ProjectMapPersonView(ProtectedFormView, SingleObjectMixin): pm = Mapper.PersonMapper() person = pm.get_person_by_uuid(self.object, self.person_uuid) - print unicode(form.cleaned_data) - # TODO: do mapping according to parameters, override success_url to point to next person! - if form.cleaned_data[u'action'] == u'new': - pm.create_new_identity(self.object, person) - elif form.cleaned_data[u'action'] == u'skip': + if form.data.get(u'skip', False): + """ Nothing to do here, just go on ... """ pass - + elif form.data.get(u'save-continue', False): + # TODO: do mapping according to parameters, override success_url to point to next person! + if form.cleaned_data[u'action'] == u'new': + pm.create_new_identity(self.object, person) + elif form.cleaned_data[u'action'] == u'existing': + # TODO preferred = FALSE is not desired. + print form.cleaned_data + pm.map_identity_to_existing(form.cleaned_data[u'global_identity'], self.object, person.ID, form.cleaned_data[u'preferred_identity']) return super(ProjectMapPersonView, self).form_valid(form) diff --git a/service/Citavi.py b/service/Citavi.py index cd333b7..27fcac1 100644 --- a/service/Citavi.py +++ b/service/Citavi.py @@ -31,7 +31,7 @@ class Project(): except: self._is_error = True # TODO: better error handling! - print u"An error occured within a get_persons call!" + print str(u"An error occured within a get_persons call!") return False def get_person_by_uuid(self, uuid): @@ -43,7 +43,7 @@ class Project(): except: self._is_error = True # TODO: better error handling! - print u"An error occured within a get_person_by_uuid call!" + print str(u"An error occured within a get_person_by_uuid call!") return False def open(self): diff --git a/service/Django.py b/service/Django.py index a313fd2..1f11458 100644 --- a/service/Django.py +++ b/service/Django.py @@ -15,7 +15,7 @@ class PersonIdentityManager(): 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 = CitaviProjectIdentity(global_identity=global_identity, project=project, citavi_uuid=uuid, preferred=preferred) cpi.save() return cpi diff --git a/service/Mapper.py b/service/Mapper.py index 55eda26..e12f230 100644 --- a/service/Mapper.py +++ b/service/Mapper.py @@ -16,6 +16,10 @@ class PersonMapper(): del self._citavi_project_manager del self._person_identity_manager + def get_citavi_persons_from_project(self, project): + """ Returns all citavi persons from a project. """ + return self._citavi_project_manager.get_persons_from_project(project.id) + def get_unmapped_identities(self, project): """ Returns a uuid->person dict for all unmapped persons within a project. """ citavi_persons = self._citavi_project_manager.get_persons_from_project(project.id) @@ -39,19 +43,39 @@ class PersonMapper(): mapped_uuid_dict[person.citavi_uuid] = person return mapped_uuid_dict + def get_mapped_identities_with_representation(self, project): + """ Returns a uuid->person dict for all mapped persons within a project in a tuple containing a unicode representation. """ + mapped_persons = self._person_identity_manager.get_mapped_identities_for_project(project) + mapped_uuid_dict = {} + for person in mapped_persons: + person_representation = self.get_representation_for_citavi_identity(person) + mapped_uuid_dict[person.citavi_uuid] = (person, person_representation) + return mapped_uuid_dict + def create_new_identity(self, project, person): """ Creates a new identity for a given person. """ return self._person_identity_manager.create_identity(project, person.ID) + def map_identity_to_existing(self, global_identity, project, uuid, preferred): + """ Maps a person person to an existing global identity. """ + return self._person_identity_manager.add_identity_to_global_identity(global_identity, project, uuid, preferred) + def get_person_by_uuid(self, project, uuid): """ Returns a person from a citavi project by uuid. """ return self._citavi_project_manager.get_person_by_uuid(project.id, uuid) def get_representation_for_global_identity(self, global_identity): - """ Returns a unicode string representation for a global identiy. """ + """ Returns a unicode representation for a global identiy. """ if global_identity.type == 'citavi': citavi_identity = self._person_identity_manager.get_citavi_identity_by_global_identity(global_identity) citavi_person = self._citavi_project_manager.get_person_by_uuid(citavi_identity.project_id, citavi_identity.citavi_uuid) return unicode(citavi_person.ID) + u" " + unicode(citavi_person.FirstName) + u" " + unicode(citavi_person.LastName) else: - return unicode(global_identity) \ No newline at end of file + return u'Not implemented yet!' + + def get_representation_for_citavi_identity(self, citavi_identity): + """ Returns a unicode representation for a citavi project identiy. """ + citavi_person = self._citavi_project_manager.get_person_by_uuid(citavi_identity.project_id, citavi_identity.citavi_uuid) + return unicode(citavi_person.ID) + u" " + unicode(citavi_person.FirstName) + u" " + unicode(citavi_person.LastName) + +