Ensure that the user has either a first name or a last name

This commit is contained in:
Norman Jäckel 2013-05-16 22:36:20 +02:00 committed by Emanuel Schuetze
parent 41abe871dd
commit bf58f2a6cc
2 changed files with 11 additions and 0 deletions

View File

@ -35,6 +35,16 @@ class UserCreateForm(CssClassMixin, forms.ModelForm):
'groups', 'structure_level', 'committee', 'about_me', 'comment',
'is_active', 'default_password')
def clean(self, *args, **kwargs):
"""
Ensures that a user has either a first name or a last name.
"""
cleaned_data = super(UserCreateForm, self).clean(*args, **kwargs)
if not cleaned_data['first_name'] and not cleaned_data['last_name']:
error_msg = _('First name and last name can not both be empty.')
raise forms.ValidationError(error_msg)
return cleaned_data
class UserUpdateForm(UserCreateForm):
"""

View File

@ -24,6 +24,7 @@
</h1>
<form action="" method="post">{% csrf_token %}
{{ form.non_field_errors }}
{% include "form.html" %}
{% if edit_user %}
<p style="margin: -15px 0 25px 0;">