From bf58f2a6cca3e744a1d9b43348318201dba6a484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Thu, 16 May 2013 22:36:20 +0200 Subject: [PATCH] Ensure that the user has either a first name or a last name --- openslides/participant/forms.py | 10 ++++++++++ openslides/participant/templates/participant/edit.html | 1 + 2 files changed, 11 insertions(+) diff --git a/openslides/participant/forms.py b/openslides/participant/forms.py index bff479fdd..72710bf3d 100644 --- a/openslides/participant/forms.py +++ b/openslides/participant/forms.py @@ -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): """ diff --git a/openslides/participant/templates/participant/edit.html b/openslides/participant/templates/participant/edit.html index d0dfc143a..6d890dae1 100644 --- a/openslides/participant/templates/participant/edit.html +++ b/openslides/participant/templates/participant/edit.html @@ -24,6 +24,7 @@
{% csrf_token %} + {{ form.non_field_errors }} {% include "form.html" %} {% if edit_user %}