1
0
mirror of https://github.com/etesync/server synced 2024-11-28 03:38:07 +00:00
etesync-server/etebase_server/myauth/forms.py

31 lines
859 B
Python
Raw Normal View History

from django import forms
from django.contrib.auth.forms import UsernameField
2024-06-08 21:51:44 +00:00
from etebase_server.myauth.models import get_typed_user_model
2020-12-29 11:22:36 +00:00
User = get_typed_user_model()
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",)
field_classes = {"username": UsernameField}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self._meta.model.USERNAME_FIELD in self.fields:
self.fields[self._meta.model.USERNAME_FIELD].widget.attrs["autofocus"] = True
def save(self, commit=True):
user = super().save(commit=False)
user.set_unusable_password()
if commit:
user.save()
return user