[TASK] Expanding the structure, getting the Mapper mechanisms ready and in place.
This commit is contained in:
parent
59e2543018
commit
b0a04b951e
|
@ -6,12 +6,14 @@ from django.contrib import admin
|
|||
admin.autodiscover()
|
||||
|
||||
from frontend.views import login_wrap, logout_wrap
|
||||
from frontend.views import IndexView, ProjectOverView, UpdateProjectView
|
||||
from frontend.views import IndexView, ProjectView, ProjectUpdateView, ProjectPersonView, ProjectMapPersonView
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^$', IndexView.as_view(), name='frontend-index'),
|
||||
url(r'^projects/$', ProjectOverView.as_view(), name='frontend-projects'),
|
||||
url(r'^projects/(?P<project_id>\d+)/update$', UpdateProjectView.as_view(), name='frontend-project-update'),
|
||||
url(r'^project/$', ProjectView.as_view(), name='frontend-projects'),
|
||||
url(r'^project/(?P<project_id>\d+)/update$', ProjectUpdateView.as_view(), name='frontend-project-update'),
|
||||
url(r'^project/(?P<project_id>\d+)/map/person$', ProjectPersonView.as_view(), name='frontend-project-view-person'),
|
||||
url(r'^project/(?P<project_id>\d+)/map/person/(?P<person_uuid>[\w\d-]+)$', ProjectMapPersonView.as_view(), name='frontend-project-map-person'),
|
||||
url(r'^login/$', login_wrap, name='frontend-login'),
|
||||
url(r'^logout/$', logout_wrap, name='frontend-logout'),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django import forms
|
||||
from frontend.models import Project
|
||||
from frontend.models import Project, PersonGlobalIdentity
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import Submit, Layout
|
||||
|
||||
|
@ -16,18 +16,18 @@ class NewProjectForm(forms.ModelForm):
|
|||
self.helper.layout = Layout(
|
||||
'name',
|
||||
'description',
|
||||
Submit('send', 'Create', css_class = 'btn-default')
|
||||
Submit('send', 'Create', css_class='btn-default')
|
||||
)
|
||||
|
||||
name = forms.CharField(
|
||||
label = "Name",
|
||||
max_length = 255,
|
||||
required = True,
|
||||
label="Name",
|
||||
max_length=255,
|
||||
required=True,
|
||||
)
|
||||
|
||||
description = forms.CharField(
|
||||
label = "Description",
|
||||
required = True,
|
||||
label="Description",
|
||||
required=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
@ -44,7 +44,26 @@ class FileUploadForm(forms.Form):
|
|||
self.helper.form_method = 'post'
|
||||
self.helper.layout = Layout(
|
||||
'file',
|
||||
Submit('send', 'Upload', css_class = 'btn-default')
|
||||
Submit('send', 'Upload', css_class='btn-default')
|
||||
)
|
||||
|
||||
file = forms.FileField()
|
||||
|
||||
file = forms.FileField()
|
||||
|
||||
|
||||
class PersonMapForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(PersonMapForm, self).__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.form_class = 'form-horizontal'
|
||||
self.helper.label_class = 'col-lg-2'
|
||||
self.helper.field_class = 'col-lg-4'
|
||||
self.helper.form_method = 'post'
|
||||
self.helper.layout = Layout(
|
||||
'action',
|
||||
'global_identity',
|
||||
Submit('continue', 'Continue', css_class='btn-default'),
|
||||
Submit('save-continue', 'Save and continue', css_class='btn-default'),
|
||||
)
|
||||
|
||||
action = forms.ChoiceField(choices=[('new', 'Create new global Identity'), ('existing', 'Map to existing identity')], widget=forms.RadioSelect())
|
||||
global_identity = forms.ModelChoiceField(queryset=PersonGlobalIdentity.objects.all())
|
|
@ -26,7 +26,7 @@ class PersonGlobalIdentity(models.Model):
|
|||
return repr
|
||||
|
||||
|
||||
class CitaviProjectIdentity(models.Model):
|
||||
class CitaviProjectIdentity(models.Model):
|
||||
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)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
{% extends "layout/base.html" %}
|
||||
{% block head%}
|
||||
{% load crispy_forms_tags %}
|
||||
{% endblock %}
|
||||
{% block navbar-header %}
|
||||
<li><a href="{% url 'frontend-projects' %}">Back to projects</a></li>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<h3>Current subject:</h3>
|
||||
{% if not person %}
|
||||
<p><strong>Oops, something went wrong. Perhaps a wrong url?</strong></p>
|
||||
{% else %}
|
||||
<div class="person-card">
|
||||
ID: {{person.ID}}<br>
|
||||
Prefix: {{person.Prefix}}<br>
|
||||
Title: {{person.Title}}<br>
|
||||
FirstName: {{person.FirstName}}<br>
|
||||
MiddleName: {{person.MiddleName}}<br>
|
||||
LastName: {{person.LastName}}<br>
|
||||
Suffix: {{person.Suffix}}<br>
|
||||
Sex: {{person.Sex}}<br>
|
||||
Abv.: {{person.Abbreviation}}<br>
|
||||
</div>
|
||||
{% endif %}
|
||||
<h3>Wizard</h3>
|
||||
<p>{% crispy form %}</p>
|
||||
{% endblock %}
|
|
@ -0,0 +1,97 @@
|
|||
{% extends "layout/base.html" %}
|
||||
{% block head%}
|
||||
{% load crispy_forms_tags %}
|
||||
{% endblock %}
|
||||
{% block navbar-header %}
|
||||
<li><a href="{% url 'frontend-projects' %}">Back to projects</a></li>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<p><strong>Name:</strong> {{project.name}}</h3>
|
||||
<p><strong>Description:</strong> {{project.description}}</h3>
|
||||
<p><strong>Current uploaded database filename:</strong> {{project.associated_filename}}</p>
|
||||
|
||||
<!--
|
||||
<h3>Upload the new database version</h3>
|
||||
<p>{% crispy form %}</p>
|
||||
-->
|
||||
|
||||
<h3>List of unmapped citavi persons in project:</h3>
|
||||
{% if not unmapped_persons %}
|
||||
<p><strong>No unmapped persons in this project. Congratulations!</strong></p>
|
||||
{% else %}
|
||||
<table class="table table-hover table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Prefix</th>
|
||||
<th>Title</th>
|
||||
<th>First Name</th>
|
||||
<th>Middle Name</th>
|
||||
<th>Last Name</th>
|
||||
<th>Suffix</th>
|
||||
<th>Sex</th>
|
||||
<th>Abv.</th>
|
||||
<th>Features</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for person_uuid, person in unmapped_persons.items %}
|
||||
<tr>
|
||||
<td>{{person.ID}}</td>
|
||||
<td>{{person.Prefix}}</td>
|
||||
<td>{{person.Title}}</td>
|
||||
<td>{{person.FirstName}}</td>
|
||||
<td>{{person.MiddleName}}</td>
|
||||
<td>{{person.LastName}}</td>
|
||||
<td>{{person.Suffix}}</td>
|
||||
<td>{{person.Sex}}</td>
|
||||
<td>{{person.Abbreviation}}</td>
|
||||
<td>
|
||||
<a href="{% url 'frontend-project-map-person' project.id person.ID %}" title="Enter mapping wizard starting here.">Map</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
<hr>
|
||||
<h3>List of mapped citavi persons in project:</h3>
|
||||
{% if not mapped_persons %}
|
||||
<p><strong>No mapped persons in this project. Work harder!</strong></p>
|
||||
{% else %}
|
||||
<table class="table table-hover table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Prefix</th>
|
||||
<th>Title</th>
|
||||
<th>First Name</th>
|
||||
<th>Middle Name</th>
|
||||
<th>Last Name</th>
|
||||
<th>Suffix</th>
|
||||
<th>Sex</th>
|
||||
<th>Abv.</th>
|
||||
<th>Features</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for person in mapped_persons.items %}
|
||||
<tr>
|
||||
<td>{{person.ID}}</td>
|
||||
<td>{{person.Prefix}}</td>
|
||||
<td>{{person.Title}}</td>
|
||||
<td>{{person.FirstName}}</td>
|
||||
<td>{{person.MiddleName}}</td>
|
||||
<td>{{person.LastName}}</td>
|
||||
<td>{{person.Suffix}}</td>
|
||||
<td>{{person.Sex}}</td>
|
||||
<td>{{person.Abbreviation}}</td>
|
||||
<td>
|
||||
<a href="{% url 'frontend-project-map-person' project.id person.ID %}" title="Enter mapping wizard starting here.">Map</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -26,7 +26,10 @@
|
|||
<td>{{project.name}}</td>
|
||||
<td>{{project.description}}</td>
|
||||
<td>{{project.associated_filename}}</td>
|
||||
<td><a href="{% url 'frontend-project-update' project.id %}">Update project</a></td>
|
||||
<td>
|
||||
<a href="{% url 'frontend-project-update' project.id %}">Update project</a>
|
||||
<a href="{% url 'frontend-project-map-person' project.id %}">Persons</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
@ -13,7 +13,7 @@ from django.contrib.auth.decorators import login_required
|
|||
from django.utils.decorators import method_decorator
|
||||
from django.contrib.auth.views import login, logout
|
||||
|
||||
from frontend.forms import NewProjectForm, FileUploadForm
|
||||
from frontend.forms import NewProjectForm, FileUploadForm, PersonMapForm
|
||||
|
||||
from frontend.models import Project
|
||||
|
||||
|
@ -94,36 +94,36 @@ class IndexView(ProtectedTemplateView):
|
|||
template_name = 'index.html'
|
||||
page_title = 'Index'
|
||||
|
||||
class ProjectOverView(ProtectedFormView):
|
||||
class ProjectView(ProtectedFormView):
|
||||
template_name = 'projects.html'
|
||||
page_title = 'Projects'
|
||||
form_class = NewProjectForm
|
||||
success_url = '/projects'
|
||||
success_url = '/project'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs[u'projects'] = Project.objects.order_by('id')
|
||||
return super(ProjectOverView, self).get_context_data(**kwargs)
|
||||
return super(ProjectView, self).get_context_data(**kwargs)
|
||||
|
||||
def form_valid(self, form):
|
||||
form.save()
|
||||
return super(ProjectOverView, self).form_valid(form)
|
||||
return super(ProjectView, self).form_valid(form)
|
||||
|
||||
class UpdateProjectView(ProtectedFormView, SingleObjectMixin):
|
||||
template_name = 'project.html'
|
||||
class ProjectUpdateView(ProtectedFormView, SingleObjectMixin):
|
||||
template_name = 'project/update.html'
|
||||
page_title = 'Update project'
|
||||
form_class = FileUploadForm
|
||||
|
||||
success_url = '/projects/'
|
||||
success_url = '/project/'
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.project_id = kwargs[u'project_id']
|
||||
self.object = Project.objects.get(pk=self.project_id)
|
||||
return super(UpdateProjectView, self).get(request, *args, **kwargs)
|
||||
return super(ProjectUpdateView, self).get(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.project_id = kwargs[u'project_id']
|
||||
self.success_url = self.success_url + self.project_id + '/update'
|
||||
return super(UpdateProjectView, self).post(request, *args, **kwargs)
|
||||
return super(ProjectUpdateView, self).post(request, *args, **kwargs)
|
||||
|
||||
def form_valid(self, form, *args, **kwargs):
|
||||
""" This form_valid handles the file upload. """
|
||||
|
@ -167,5 +167,65 @@ class UpdateProjectView(ProtectedFormView, SingleObjectMixin):
|
|||
# citavi_project = Citavi.Project(sqlite_path)
|
||||
# citavi_project.open()
|
||||
# del citavi_project
|
||||
return super(UpdateProjectView, self).form_valid(form)
|
||||
return super(ProjectUpdateView, self).form_valid(form)
|
||||
|
||||
|
||||
class ProjectPersonView(ProtectedFormView, SingleObjectMixin):
|
||||
template_name = 'project/view-person.html'
|
||||
page_title = 'Person View'
|
||||
form_class = FileUploadForm
|
||||
|
||||
success_url = '/projects/'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
project = self.object
|
||||
|
||||
from service import Mapper
|
||||
pm = Mapper.PersonMapper()
|
||||
kwargs[u'unmapped_persons'] = pm.get_unmapped_identities(project)
|
||||
return super(ProjectPersonView, self).get_context_data(**kwargs)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.project_id = kwargs[u'project_id']
|
||||
self.object = Project.objects.get(pk=self.project_id)
|
||||
return super(ProjectPersonView, self).get(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.project_id = kwargs[u'project_id']
|
||||
# self.success_url = self.success_url + self.project_id + '/update'
|
||||
return super(ProjectPersonView, self).post(request, *args, **kwargs)
|
||||
|
||||
def form_valid(self, form, *args, **kwargs):
|
||||
return super(ProjectPersonView, self).form_valid(form)
|
||||
|
||||
|
||||
class ProjectMapPersonView(ProtectedFormView, SingleObjectMixin):
|
||||
template_name = 'project/map-person.html'
|
||||
page_title = 'Person Mapping'
|
||||
form_class = PersonMapForm
|
||||
|
||||
success_url = '/projects/'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
project = self.object
|
||||
|
||||
from service import Mapper
|
||||
pm = Mapper.PersonMapper()
|
||||
kwargs[u'person'] = pm.get_person_by_uuid(project, self.person_uuid)
|
||||
return super(ProjectMapPersonView, self).get_context_data(**kwargs)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.project_id = kwargs[u'project_id']
|
||||
self.person_uuid = kwargs[u'person_uuid']
|
||||
self.object = Project.objects.get(pk=self.project_id)
|
||||
return super(ProjectMapPersonView, self).get(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.project_id = kwargs[u'project_id']
|
||||
self.person_uuid = kwargs[u'person_uuid']
|
||||
# self.success_url = self.success_url + self.project_id + '/update'
|
||||
return super(ProjectMapPersonView, self).post(request, *args, **kwargs)
|
||||
|
||||
def form_valid(self, form, *args, **kwargs):
|
||||
return super(ProjectMapPersonView, self).form_valid(form)
|
||||
|
||||
|
|
|
@ -20,5 +20,5 @@ class PersonIdentityManager():
|
|||
def get_global_identities(self):
|
||||
return PersonGlobalIdentity.objects.all()
|
||||
|
||||
def get_mapped_identities_for_project(self, project):
|
||||
return CitaviProjectIdentity.objects.filter(project=project).all()
|
||||
def get_mapped_identities_for_project(self, project_instance):
|
||||
return CitaviProjectIdentity.objects.filter(project=project_instance).all()
|
||||
|
|
|
@ -20,14 +20,14 @@ class PersonMapper():
|
|||
print "Len citavi persons: " + str(len(citavi_persons))
|
||||
print "Len mapped persons: " + str(len(mapped_persons))
|
||||
|
||||
if len(mapped_persons) == 0:
|
||||
return citavi_persons
|
||||
|
||||
# Prepare citavi_persons into a uuid->person dict, then eliminate mapped ones. This is ugly and a little slow.
|
||||
citavi_uuid_dict = {}
|
||||
for person in citavi_persons:
|
||||
citavi_uuid_dict[person.ID] = person
|
||||
|
||||
if len(mapped_persons) == 0:
|
||||
return citavi_uuid_dict
|
||||
|
||||
print len(citavi_uuid_dict)
|
||||
|
||||
for person in mapped_persons:
|
||||
|
@ -42,11 +42,14 @@ class PersonMapper():
|
|||
def create_new_identity(self, project, person):
|
||||
self._person_identity_manager.create_identity(project, person.ID)
|
||||
|
||||
def get_person_by_uuid(self, project, uuid): #
|
||||
return self._citavi_project_manager.get_person_by_uuid(project.id, uuid)
|
||||
|
||||
def test():
|
||||
from frontend.models import Project
|
||||
project = Project.objects.get(id=1)
|
||||
p = PersonMapper()
|
||||
unmapped = p.get_unmapped_identities(project)
|
||||
print unmapped
|
||||
# for person in unmapped:
|
||||
# p.create_new_identity(project, person)
|
||||
for person in unmapped:
|
||||
p.create_new_identity(project, person)
|
||||
|
|
Loading…
Reference in New Issue