diff options
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r-- | ishtar_common/forms_common.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index edea0cde2..92c4c5797 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -845,6 +845,23 @@ class ProfilePersonForm(forms.Form): (current_profile.profile_type.pk, current_profile.profile_type.name) ] + def clean(self): + data = self.cleaned_data + q = models.UserProfile.objects.filter( + person__ishtaruser=self.user.ishtaruser, + pk=data['current_profile']) + if not q.count(): + return data + profile = q.all()[0] + + name = data.get('name', '') + if models.UserProfile.objects.filter( + person__ishtaruser=self.user.ishtaruser, + name=name).exclude(pk=profile.pk).count(): + raise forms.ValidationError( + _(u"A profile with the same name exists.")) + return data + def save(self, session): q = models.UserProfile.objects.filter( person__ishtaruser=self.user.ishtaruser, |