2017-11-11 22:27:42 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from django import forms
|
2017-12-11 02:36:25 +00:00
|
|
|
from django.contrib.auth.forms import PasswordChangeForm, UserCreationForm
|
2017-11-11 22:27:42 +00:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
|
|
|
|
from .models import Settings
|
|
|
|
|
|
|
|
|
2017-12-11 02:36:25 +00:00
|
|
|
class UserAddForm(UserCreationForm):
|
|
|
|
class Meta:
|
|
|
|
model = User
|
2022-02-10 00:00:30 +00:00
|
|
|
fields = [
|
|
|
|
"username",
|
|
|
|
"first_name",
|
|
|
|
"last_name",
|
|
|
|
"email",
|
|
|
|
"is_staff",
|
|
|
|
"is_active",
|
|
|
|
]
|
2017-12-11 02:36:25 +00:00
|
|
|
|
2017-12-13 18:25:36 +00:00
|
|
|
def save(self, commit=True):
|
|
|
|
user = super(UserAddForm, self).save(commit=False)
|
2022-10-15 21:02:55 +00:00
|
|
|
# All Baby Buddy users are superusers.
|
2017-12-13 18:25:36 +00:00
|
|
|
user.is_superuser = True
|
|
|
|
if commit:
|
|
|
|
user.save()
|
|
|
|
return user
|
|
|
|
|
2017-12-11 02:36:25 +00:00
|
|
|
|
|
|
|
class UserUpdateForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = User
|
2022-02-10 00:00:30 +00:00
|
|
|
fields = [
|
|
|
|
"username",
|
|
|
|
"first_name",
|
|
|
|
"last_name",
|
|
|
|
"email",
|
|
|
|
"is_staff",
|
|
|
|
"is_active",
|
|
|
|
]
|
2017-12-11 02:36:25 +00:00
|
|
|
|
|
|
|
|
2017-11-11 22:27:42 +00:00
|
|
|
class UserForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = User
|
2022-02-10 00:00:30 +00:00
|
|
|
fields = ["first_name", "last_name", "email"]
|
2017-11-11 22:27:42 +00:00
|
|
|
|
|
|
|
|
2017-12-02 21:20:15 +00:00
|
|
|
class UserPasswordForm(PasswordChangeForm):
|
|
|
|
class Meta:
|
2022-02-10 00:00:30 +00:00
|
|
|
fields = ["old_password", "new_password1", "new_password2"]
|
2017-12-02 21:20:15 +00:00
|
|
|
|
|
|
|
|
2017-11-11 22:27:42 +00:00
|
|
|
class UserSettingsForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Settings
|
2021-05-14 03:28:39 +00:00
|
|
|
fields = [
|
2022-02-10 00:00:30 +00:00
|
|
|
"dashboard_refresh_rate",
|
|
|
|
"dashboard_hide_empty",
|
|
|
|
"dashboard_hide_age",
|
|
|
|
"language",
|
|
|
|
"timezone",
|
2021-05-14 03:28:39 +00:00
|
|
|
]
|