aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/users/forms.py
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-01-19 15:57:06 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2020-01-19 15:57:06 +0000
commit9d76a3c52b8310726ec09e0262813f0438c21df6 (patch)
tree4acf47dce6c3aa75f8ad7c5cb56fe6486c2d64a7 /ctrack/users/forms.py
init commit - from cookiecutter
Diffstat (limited to 'ctrack/users/forms.py')
-rw-r--r--ctrack/users/forms.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/ctrack/users/forms.py b/ctrack/users/forms.py
new file mode 100644
index 0000000..250cc90
--- /dev/null
+++ b/ctrack/users/forms.py
@@ -0,0 +1,30 @@
+from django.contrib.auth import get_user_model, forms
+from django.core.exceptions import ValidationError
+from django.utils.translation import ugettext_lazy as _
+
+User = get_user_model()
+
+
+class UserChangeForm(forms.UserChangeForm):
+ class Meta(forms.UserChangeForm.Meta):
+ model = User
+
+
+class UserCreationForm(forms.UserCreationForm):
+
+ error_message = forms.UserCreationForm.error_messages.update(
+ {"duplicate_username": _("This username has already been taken.")}
+ )
+
+ class Meta(forms.UserCreationForm.Meta):
+ model = User
+
+ def clean_username(self):
+ username = self.cleaned_data["username"]
+
+ try:
+ User.objects.get(username=username)
+ except User.DoesNotExist:
+ return username
+
+ raise ValidationError(self.error_messages["duplicate_username"])