[TASK] Perform validation in mapping wizard, polish model representations.
This commit is contained in:
parent
2270dd23a8
commit
5df3f3f39a
@ -51,6 +51,7 @@ class FileUploadForm(forms.Form):
|
|||||||
|
|
||||||
|
|
||||||
class PersonMapForm(forms.Form):
|
class PersonMapForm(forms.Form):
|
||||||
|
""" Form containing the person mapping 'wizard'. """
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(PersonMapForm, self).__init__(*args, **kwargs)
|
super(PersonMapForm, self).__init__(*args, **kwargs)
|
||||||
self.helper = FormHelper()
|
self.helper = FormHelper()
|
||||||
@ -66,6 +67,17 @@ class PersonMapForm(forms.Form):
|
|||||||
Submit(u'save-continue', u'Save and continue', css_class=u'btn-default'),
|
Submit(u'save-continue', u'Save and continue', css_class=u'btn-default'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
""" Make sure the submitted data is okay. """
|
||||||
|
cleaned_data = super(PersonMapForm, self).clean()
|
||||||
|
action = cleaned_data.get(u'action')
|
||||||
|
global_identity = cleaned_data.get(u'global_identity')
|
||||||
|
if action == u'existing' and not global_identity:
|
||||||
|
msg = u"Cannot map to non-existing global identity!"
|
||||||
|
self._errors["global_identity"] = self.error_class([msg])
|
||||||
|
return cleaned_data
|
||||||
|
|
||||||
action = forms.ChoiceField(choices=[(u'new', u'Create new global Identity'), (u'existing', u'Map to existing identity')], initial=u'new', widget=forms.RadioSelect())
|
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)
|
global_identity = forms.ModelChoiceField(queryset=PersonGlobalIdentity.objects.all(), required=False)
|
||||||
preferred_identity = forms.BooleanField(initial=False, required=False)
|
preferred_identity = forms.BooleanField(initial=False, required=False)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ class Project(models.Model):
|
|||||||
if self.associated_filename:
|
if self.associated_filename:
|
||||||
temp += u" (" + unicode(self.associated_filename) + u")"
|
temp += u" (" + unicode(self.associated_filename) + u")"
|
||||||
else:
|
else:
|
||||||
temp += u" (empty)"
|
temp += u" (No project file)"
|
||||||
return temp
|
return temp
|
||||||
|
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ class PersonGlobalIdentity(models.Model):
|
|||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
from service.Mapper import person_mapper
|
from service.Mapper import person_mapper
|
||||||
return u"<PersonGlobalIdentity repr='" + person_mapper.get_representation_for_global_identity(self) + u"', ID=" + unicode(self.id) + u", type=" + unicode(self.type) + u">"
|
return person_mapper.get_representation_for_global_identity(self) + u" [" u"ID=" + unicode(self.id) + u", Type=" + unicode(self.type) + u"]"
|
||||||
|
|
||||||
|
|
||||||
class CitaviProjectIdentity(models.Model):
|
class CitaviProjectIdentity(models.Model):
|
||||||
@ -35,4 +35,8 @@ class CitaviProjectIdentity(models.Model):
|
|||||||
preferred = models.BooleanField()
|
preferred = models.BooleanField()
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return u"<CitaviProjectIdentity project=" + unicode(self.project) + u", citavi_uuid=" + unicode(self.citavi_uuid) + u", global_identity=" + unicode(self.global_identity) + u", preferred=" + unicode(self.preferred) + u">"
|
from service.Mapper import person_mapper
|
||||||
|
citavi_repr = person_mapper.get_representation_for_citavi_identity(self)
|
||||||
|
if self.preferred == True:
|
||||||
|
citavi_repr = citavi_repr + u" <preferred>"
|
||||||
|
return citavi_repr
|
@ -12,6 +12,7 @@ from django.views.generic.detail import SingleObjectMixin
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.contrib.auth.views import login, logout
|
from django.contrib.auth.views import login, logout
|
||||||
|
from django.forms import ValidationError
|
||||||
|
|
||||||
from frontend.forms import NewProjectForm, FileUploadForm, PersonMapForm
|
from frontend.forms import NewProjectForm, FileUploadForm, PersonMapForm
|
||||||
|
|
||||||
@ -245,8 +246,7 @@ class ProjectMapPersonView(ProtectedFormView, SingleObjectMixin):
|
|||||||
if form.cleaned_data[u'action'] == u'new':
|
if form.cleaned_data[u'action'] == u'new':
|
||||||
person_mapper.create_new_identity(self.object, person)
|
person_mapper.create_new_identity(self.object, person)
|
||||||
elif form.cleaned_data[u'action'] == u'existing':
|
elif form.cleaned_data[u'action'] == u'existing':
|
||||||
# TODO preferred = FALSE is not desired.
|
global_identity = form.cleaned_data[u'global_identity']
|
||||||
print form.cleaned_data
|
person_mapper.map_identity_to_existing(global_identity, self.object, person.ID, form.cleaned_data[u'preferred_identity'])
|
||||||
person_mapper.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)
|
return super(ProjectMapPersonView, self).form_valid(form)
|
||||||
|
|
||||||
|
@ -15,6 +15,9 @@ class PersonIdentityManager():
|
|||||||
|
|
||||||
def add_identity_to_global_identity(self, global_identity, project, uuid, preferred):
|
def add_identity_to_global_identity(self, global_identity, project, uuid, preferred):
|
||||||
""" Maps given citavi project identity to existing global identity. """
|
""" Maps given citavi project identity to existing global identity. """
|
||||||
|
# First, fetch all involved CitaviProjectIdentities and set them to preferred=False
|
||||||
|
CitaviProjectIdentity.objects.filter(global_identity=global_identity).update(preferred=False)
|
||||||
|
# Then add the new primary ProjectIdentity.
|
||||||
cpi = CitaviProjectIdentity(global_identity=global_identity, project=project, citavi_uuid=uuid, preferred=preferred)
|
cpi = CitaviProjectIdentity(global_identity=global_identity, project=project, citavi_uuid=uuid, preferred=preferred)
|
||||||
cpi.save()
|
cpi.save()
|
||||||
return cpi
|
return cpi
|
||||||
|
@ -60,14 +60,18 @@ class PersonMapper():
|
|||||||
if global_identity.type == 'citavi':
|
if global_identity.type == 'citavi':
|
||||||
citavi_identity = self._person_identity_manager.get_citavi_identity_by_global_identity(global_identity)
|
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)
|
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)
|
return self._representation_for_citavi_person(citavi_person)
|
||||||
else:
|
else:
|
||||||
return u'Not implemented yet!'
|
return u'Not implemented yet!'
|
||||||
|
|
||||||
def get_representation_for_citavi_identity(self, citavi_identity):
|
def get_representation_for_citavi_identity(self, citavi_identity):
|
||||||
""" Returns a unicode representation for a citavi project identiy. """
|
""" 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)
|
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)
|
return self._representation_for_citavi_person(citavi_person)
|
||||||
|
|
||||||
|
def _representation_for_citavi_person(self, citavi_person):
|
||||||
|
p = citavi_person
|
||||||
|
return u"<" + unicode(p.FirstName) + u" " + unicode(p.LastName) + u">"
|
||||||
|
|
||||||
|
|
||||||
# Create a PersonMapper instance for public use, so ressources are not wasted.
|
# Create a PersonMapper instance for public use, so ressources are not wasted.
|
||||||
|
Loading…
Reference in New Issue
Block a user