[TASK] Make skip button in person map wizard work as expected.
This commit is contained in:
parent
ed20650289
commit
8f87fa05f9
|
@ -4,6 +4,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block navbar-header %}
|
{% block navbar-header %}
|
||||||
<li><a href="{% url 'frontend-projects' %}">Back to projects</a></li>
|
<li><a href="{% url 'frontend-projects' %}">Back to projects</a></li>
|
||||||
|
<li><a href="{% url 'frontend-project-view-person' project.id %}">Back to person list</a></li>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h3>Current subject:</h3>
|
<h3>Current subject:</h3>
|
||||||
|
|
|
@ -190,7 +190,6 @@ class ProjectPersonView(ProtectedFormView, SingleObjectMixin):
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
project = self.object
|
project = self.object
|
||||||
|
|
||||||
kwargs[u'unmapped_persons'] = person_mapper.get_unmapped_identities(project)
|
kwargs[u'unmapped_persons'] = person_mapper.get_unmapped_identities(project)
|
||||||
kwargs[u'mapped_persons'] = person_mapper.get_mapped_identities(project)
|
kwargs[u'mapped_persons'] = person_mapper.get_mapped_identities(project)
|
||||||
return super(ProjectPersonView, self).get_context_data(**kwargs)
|
return super(ProjectPersonView, self).get_context_data(**kwargs)
|
||||||
|
@ -217,18 +216,44 @@ class ProjectMapPersonView(ProtectedFormView, SingleObjectMixin):
|
||||||
|
|
||||||
success_url = u'/project'
|
success_url = u'/project'
|
||||||
|
|
||||||
|
_unmapped_persons = None
|
||||||
|
|
||||||
|
def _refresh_unmapped(self):
|
||||||
|
""" Refresh data about unmapped persons. """
|
||||||
|
self._unmapped_persons = person_mapper.get_unmapped_identities(self.object)
|
||||||
|
|
||||||
|
def _is_unmapped(self, person_uuid):
|
||||||
|
""" Returns True if the given person is not mapped yet. """
|
||||||
|
if not self._unmapped_persons:
|
||||||
|
self._refresh_unmapped()
|
||||||
|
return person_uuid in self._unmapped_persons
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
project = self.object
|
project = self.object
|
||||||
kwargs[u'person'] = person_mapper.get_person_by_uuid(project, self.person_uuid)
|
kwargs[u'person'] = person_mapper.get_person_by_uuid(project, self.person_uuid)
|
||||||
return super(ProjectMapPersonView, self).get_context_data(**kwargs)
|
return super(ProjectMapPersonView, self).get_context_data(**kwargs)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
unmapped_persons = person_mapper.get_unmapped_identities(self.object)
|
""" TODO: Make this work! - Update success uri to next unmapped person. """
|
||||||
project_id = self.object.id
|
last_uuid = unicode(self.person_uuid)
|
||||||
person = unmapped_persons.itervalues().next()
|
self._refresh_unmapped()
|
||||||
|
unmapped = self._unmapped_persons.items()
|
||||||
|
first_person_uuid = unmapped[0][0]
|
||||||
|
next_uuid = first_person_uuid
|
||||||
|
unmapped.reverse()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
current_person = unmapped.pop()
|
||||||
|
if current_person[1].ID == last_uuid:
|
||||||
|
next_uuid = unmapped.pop()[0]
|
||||||
|
break
|
||||||
|
except IndexError:
|
||||||
|
break
|
||||||
|
|
||||||
kwargs = {
|
kwargs = {
|
||||||
u"project_id": project_id,
|
u"project_id": self.object.id,
|
||||||
u"person_uuid": person.ID
|
u"person_uuid": next_uuid
|
||||||
}
|
}
|
||||||
return reverse('frontend-project-map-person', kwargs=kwargs)
|
return reverse('frontend-project-map-person', kwargs=kwargs)
|
||||||
|
|
||||||
|
@ -236,13 +261,18 @@ class ProjectMapPersonView(ProtectedFormView, SingleObjectMixin):
|
||||||
self.project_id = kwargs[u'project_id']
|
self.project_id = kwargs[u'project_id']
|
||||||
self.person_uuid = kwargs[u'person_uuid']
|
self.person_uuid = kwargs[u'person_uuid']
|
||||||
self.object = Project.objects.get(pk=self.project_id)
|
self.object = Project.objects.get(pk=self.project_id)
|
||||||
|
if self._is_unmapped(self.person_uuid) == False:
|
||||||
|
raise Exception("Sorry, this person was already mapped. Try deleting the existing mapping and move on. TODO: Make this more beautiful.")
|
||||||
|
self._refresh_unmapped()
|
||||||
return super(ProjectMapPersonView, self).get(request, *args, **kwargs)
|
return super(ProjectMapPersonView, self).get(request, *args, **kwargs)
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
self.project_id = kwargs[u'project_id']
|
self.project_id = kwargs[u'project_id']
|
||||||
self.person_uuid = kwargs[u'person_uuid']
|
self.person_uuid = kwargs[u'person_uuid']
|
||||||
self.object = Project.objects.get(pk=self.project_id)
|
self.object = Project.objects.get(pk=self.project_id)
|
||||||
# self.success_url = self.success_url + self.project_id + '/update'
|
if self._is_unmapped(self.person_uuid) == False:
|
||||||
|
raise Exception("Sorry, this person was already mapped. Try deleting the existing mapping and move on. TODO: Make this more beautiful.")
|
||||||
|
self._refresh_unmapped()
|
||||||
return super(ProjectMapPersonView, self).post(request, *args, **kwargs)
|
return super(ProjectMapPersonView, self).post(request, *args, **kwargs)
|
||||||
|
|
||||||
def form_valid(self, form, *args, **kwargs):
|
def form_valid(self, form, *args, **kwargs):
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from sqlalchemy import create_engine, MetaData
|
from sqlalchemy import create_engine, MetaData, asc, desc
|
||||||
from sqlalchemy.ext.automap import automap_base
|
from sqlalchemy.ext.automap import automap_base
|
||||||
from sqlalchemy.orm import Session, scoped_session, sessionmaker
|
from sqlalchemy.orm import Session, scoped_session, sessionmaker
|
||||||
|
|
||||||
|
|
||||||
class Project():
|
class Project():
|
||||||
""" A helper class representing a Citavi project. """
|
""" A helper class representing a Citavi project. """
|
||||||
def __init__(self, sqlite_file):
|
def __init__(self, sqlite_file):
|
||||||
|
@ -26,7 +25,7 @@ class Project():
|
||||||
""" Returns all persons from the Citavi project. """
|
""" Returns all persons from the Citavi project. """
|
||||||
try:
|
try:
|
||||||
person_class = self._sa_sqlite_autobase.classes.Person
|
person_class = self._sa_sqlite_autobase.classes.Person
|
||||||
citavi_persons = self._sa_sqlite_session.query(person_class).all()
|
citavi_persons = self._sa_sqlite_session.query(person_class).order_by(asc('ID')).all()
|
||||||
return citavi_persons
|
return citavi_persons
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print e
|
print e
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from Citavi import ProjectManager
|
from Citavi import ProjectManager
|
||||||
from Django import PersonIdentityManager
|
from Django import PersonIdentityManager
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
class PersonMapper():
|
class PersonMapper():
|
||||||
""" This little guy will help you get through your day and map citavi persons against identities. """
|
""" This little guy will help you get through your day and map citavi persons against identities. """
|
||||||
|
@ -25,7 +25,7 @@ class PersonMapper():
|
||||||
citavi_persons = self._citavi_project_manager.get_persons_from_project(project.id)
|
citavi_persons = self._citavi_project_manager.get_persons_from_project(project.id)
|
||||||
mapped_persons = self._person_identity_manager.get_mapped_identities_for_project(project)
|
mapped_persons = self._person_identity_manager.get_mapped_identities_for_project(project)
|
||||||
# Prepare citavi_persons into a uuid->person dict, then eliminate mapped ones. This is ugly and a little slow.
|
# Prepare citavi_persons into a uuid->person dict, then eliminate mapped ones. This is ugly and a little slow.
|
||||||
citavi_uuid_dict = {}
|
citavi_uuid_dict = OrderedDict()
|
||||||
for person in citavi_persons:
|
for person in citavi_persons:
|
||||||
citavi_uuid_dict[person.ID] = person
|
citavi_uuid_dict[person.ID] = person
|
||||||
if len(mapped_persons) == 0:
|
if len(mapped_persons) == 0:
|
||||||
|
@ -38,7 +38,7 @@ class PersonMapper():
|
||||||
def get_mapped_identities(self, project):
|
def get_mapped_identities(self, project):
|
||||||
""" Returns a uuid->person dict for all mapped persons within a project. """
|
""" Returns a uuid->person dict for all mapped persons within a project. """
|
||||||
mapped_persons = self._person_identity_manager.get_mapped_identities_for_project(project)
|
mapped_persons = self._person_identity_manager.get_mapped_identities_for_project(project)
|
||||||
mapped_uuid_dict = {}
|
mapped_uuid_dict = OrderedDict()
|
||||||
for person in mapped_persons:
|
for person in mapped_persons:
|
||||||
mapped_uuid_dict[person.citavi_uuid] = person
|
mapped_uuid_dict[person.citavi_uuid] = person
|
||||||
return mapped_uuid_dict
|
return mapped_uuid_dict
|
||||||
|
|
Loading…
Reference in New Issue