You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
858 B
Python
30 lines
858 B
Python
4 years ago
|
from django import forms
|
||
|
from django.contrib.auth.forms import UsernameField
|
||
3 years ago
|
from etebase_server.myauth.models import get_typed_user_model
|
||
4 years ago
|
|
||
4 years ago
|
User = get_typed_user_model()
|
||
4 years ago
|
|
||
|
|
||
|
class AdminUserCreationForm(forms.ModelForm):
|
||
|
"""
|
||
|
A form that creates a user, with no privileges, from the given username and
|
||
|
password.
|
||
|
"""
|
||
|
|
||
|
class Meta:
|
||
|
model = User
|
||
|
fields = ("username",)
|
||
4 years ago
|
field_classes = {"username": UsernameField}
|
||
4 years ago
|
|
||
|
def __init__(self, *args, **kwargs):
|
||
|
super().__init__(*args, **kwargs)
|
||
|
if self._meta.model.USERNAME_FIELD in self.fields:
|
||
4 years ago
|
self.fields[self._meta.model.USERNAME_FIELD].widget.attrs["autofocus"] = True
|
||
4 years ago
|
|
||
|
def save(self, commit=True):
|
||
|
user = super().save(commit=False)
|
||
|
user.set_unusable_password()
|
||
|
if commit:
|
||
|
user.save()
|
||
|
return user
|