[TASK] Perform validation in mapping wizard, polish model representations.

This commit is contained in:
JPT committed 2014-10-01 11:26:11 +02:00
1 parent 2270dd23a8
commit 5df3f3f39a
5 files changed
+31 -8

No files matched your search

+12
View File
@@ -51,6 +51,7 @@ class FileUploadForm(forms.Form):
class PersonMapForm(forms.Form):
""" Form containing the person mapping 'wizard'. """
def __init__(self, *args, **kwargs):
super(PersonMapForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
@@ -66,6 +67,17 @@ class PersonMapForm(forms.Form):
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())
global_identity = forms.ModelChoiceField(queryset=PersonGlobalIdentity.objects.all(), required=False)
preferred_identity = forms.BooleanField(initial=False, required=False)
+7 -3
View File
@@ -13,7 +13,7 @@ class Project(models.Model):
if self.associated_filename:
temp += u" (" + unicode(self.associated_filename) + u")"
else:
temp += u" (empty)"
temp += u" (No project file)"
return temp
@@ -24,7 +24,7 @@ class PersonGlobalIdentity(models.Model):
def __unicode__(self):
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):
@@ -35,4 +35,8 @@ class CitaviProjectIdentity(models.Model):
preferred = models.BooleanField()
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
+3 -3
View File
@@ -12,6 +12,7 @@ from django.views.generic.detail import SingleObjectMixin
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.contrib.auth.views import login, logout
from django.forms import ValidationError
from frontend.forms import NewProjectForm, FileUploadForm, PersonMapForm
@@ -245,8 +246,7 @@ class ProjectMapPersonView(ProtectedFormView, SingleObjectMixin):
if form.cleaned_data[u'action'] == u'new':
person_mapper.create_new_identity(self.object, person)
elif form.cleaned_data[u'action'] == u'existing':
# TODO preferred = FALSE is not desired.
print form.cleaned_data
person_mapper.map_identity_to_existing(form.cleaned_data[u'global_identity'], self.object, person.ID, form.cleaned_data[u'preferred_identity'])
global_identity = form.cleaned_data[u'global_identity']
person_mapper.map_identity_to_existing(global_identity, self.object, person.ID, form.cleaned_data[u'preferred_identity'])
return super(ProjectMapPersonView, self).form_valid(form)