[TASK] Show more details for mapped identities.

This commit is contained in:
Jan Philipp Timme 2014-09-29 16:51:50 +02:00
parent 13058a41f7
commit fe3d26f905
8 changed files with 54 additions and 22 deletions

View File

@ -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',

View File

@ -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)

View File

@ -25,14 +25,14 @@ class PersonGlobalIdentity(models.Model):
def __unicode__(self):
from service.Mapper import PersonMapper
pm = PersonMapper()
return u"<PersonGlobalIdentity repr=" + pm.get_representation_for_global_identity(self) + u" ID=" + unicode(self.id) + u", type=" + unicode(self.type) + u">"
return u"<PersonGlobalIdentity repr='" + pm.get_representation_for_global_identity(self) + u"', ID=" + unicode(self.id) + u", type=" + unicode(self.type) + 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):

View File

@ -65,15 +65,17 @@
<thead>
<tr>
<th>Citavi_UUID</th>
<th>Features</th>
<th>Name</th>
<th>Global Identity</th>
<th>Features</th>
</tr>
</thead>
<tbody>
{% for person_id, person in mapped_persons.items %}
<tr>
<td>{{person.citavi_uuid}}</td>
<td>{{person.global_identity}}</td>
<td>{{person.0.citavi_uuid}}</td>
<td>{{person.1}}</td>
<td>{{person.0.global_identity}}</td>
<td>
<a href="#TODO" title="Enter mapping wizard starting here.">Delete Mapping</a>
</td>

View File

@ -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)

View File

@ -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):

View File

@ -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

View File

@ -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)
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)