jumpserver/apps/users/forms.py

70 lines
1.7 KiB
Python
Raw Normal View History

2016-08-14 11:18:41 +00:00
# ~*~ coding: utf-8 ~*~
2016-08-16 14:13:06 +00:00
from django import forms
from django.contrib.auth.forms import AuthenticationForm
2016-09-03 16:51:36 +00:00
from django.utils.translation import gettext_lazy as _
2016-08-14 11:18:41 +00:00
from captcha.fields import CaptchaField
2016-08-21 14:37:55 +00:00
from .models import User, UserGroup
2016-08-14 11:18:41 +00:00
class UserLoginForm(AuthenticationForm):
2016-09-03 16:51:36 +00:00
username = forms.CharField(label=_('Username'), max_length=100)
password = forms.CharField(
label=_('Password'), widget=forms.PasswordInput, max_length=100,
strip=False)
2016-09-03 06:37:01 +00:00
captcha = CaptchaField()
2016-08-25 11:29:59 +00:00
2016-09-06 07:09:00 +00:00
class UserCreateForm(forms.ModelForm):
2016-08-14 11:18:41 +00:00
class Meta:
model = User
fields = [
2016-08-17 14:17:16 +00:00
'username', 'name', 'email', 'groups', 'wechat',
2016-08-20 17:16:30 +00:00
'phone', 'enable_otp', 'role', 'date_expired', 'comment',
2016-08-14 11:18:41 +00:00
]
2016-08-19 16:42:50 +00:00
help_texts = {
'username': '* required',
'email': '* required',
}
widgets = {
2016-09-05 12:27:44 +00:00
'groups': forms.SelectMultiple(attrs={'class': 'select2', 'data-placeholder': _('Join user groups')}),
2016-08-19 16:42:50 +00:00
}
2016-08-16 14:13:06 +00:00
class UserUpdateForm(forms.ModelForm):
2016-08-17 14:17:16 +00:00
class Meta:
model = User
fields = [
2016-08-22 16:39:07 +00:00
'name', 'email', 'groups', 'wechat',
2016-08-20 17:16:30 +00:00
'phone', 'enable_otp', 'role', 'date_expired', 'comment',
2016-08-17 14:17:16 +00:00
]
2016-08-19 16:42:50 +00:00
help_texts = {
'username': '* required',
'email': '* required',
'groups': '* required'
}
2016-08-21 14:37:55 +00:00
widgets = {
2016-09-06 07:09:00 +00:00
'groups': forms.SelectMultiple(attrs={'class': 'select2', 'data-placeholder': _('Join user groups')}),
2016-08-21 14:37:55 +00:00
}
2016-08-18 17:39:08 +00:00
class UserGroupForm(forms.ModelForm):
2016-08-18 17:39:08 +00:00
class Meta:
model = UserGroup
2016-08-21 14:37:55 +00:00
2016-08-18 17:39:08 +00:00
fields = [
'name', 'comment',
]
2016-08-21 14:37:55 +00:00
2016-08-19 16:42:50 +00:00
help_texts = {
'name': '* required'
}