1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 15:45:23 +00:00
webvirtcloud/accounts/forms.py
Jan Krcmar 71c6161291 accounts/edit added is_staff and is_superuser checkboxes
list all users (previously staff and admins were not displayed)
2016-02-09 11:16:36 +01:00

26 lines
1.1 KiB
Python

import re
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
class UserAddForm(forms.Form):
name = forms.CharField(label="Name",
error_messages={'required': _('No User name has been entered')},
max_length=20)
password = forms.CharField(required=True, error_messages={'required': _('No password has been entered')},)
is_staff = forms.BooleanField(required=True)
is_superuser = forms.BooleanField(required=True)
def clean_name(self):
name = self.cleaned_data['name']
have_symbol = re.match('^[a-z0-9]+$', name)
if not have_symbol:
raise forms.ValidationError(_('The flavor name must not contain any special characters'))
elif len(name) > 20:
raise forms.ValidationError(_('The flavor name must not exceed 20 characters'))
try:
User.objects.get(username=name)
except User.DoesNotExist:
return name
raise forms.ValidationError(_('Flavor name is already use'))