Merge pull request #667 from emanuelschuetze/NoEmptyFirstAndLastName

No empty first and last name
This commit is contained in:
Emanuel Schütze 2013-05-16 15:08:39 -07:00
commit 3ccb8755e3
2 changed files with 19 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

@ -1,3 +1,12 @@
{% if form.non_field_errors %}
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{% for msg in form.non_field_errors %}
{{ msg }}
{% if not forloop.last %}<br />{% endif %}
{% endfor %}
</div>
{% endif %}
{% for field in form %}
<div class="control-group {% if field.errors %}error{% endif%}">
<label for="id_{{ field.name }}">{{ field.label }}{% if field.field.required %}<span class="required">*</span>{% endif %}:</label>