django-orchestra/orchestra/apps/accounts/forms.py

22 lines
904 B
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
from django import forms
from django.contrib import auth
from django.utils.translation import ugettext_lazy as _
from orchestra.core.validators import validate_password
2014-10-06 14:57:02 +00:00
from orchestra.forms import UserCreationForm
2014-05-08 16:59:35 +00:00
from orchestra.forms.widgets import ReadOnlyWidget
2014-10-06 14:57:02 +00:00
class AccountCreationForm(UserCreationForm):
2014-05-08 16:59:35 +00:00
def clean_username(self):
# Since model.clean() will check this, this is redundant,
# but it sets a nicer error message than the ORM and avoids conflicts with contrib.auth
2014-05-08 16:59:35 +00:00
username = self.cleaned_data["username"]
2014-09-30 10:20:11 +00:00
account_model = self._meta.model
if hasattr(account_model, 'systemusers'):
systemuser_model = account_model.systemusers.related.model
if systemuser_model.objects.filter(username=username).exists():
raise forms.ValidationError(self.error_messages['duplicate_username'])
return username