Source code for nlpmed_portal.users.forms

# SPDX-FileCopyrightText: Copyright (C) 2026 Omid Jafari <omidjafari.com>
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from allauth.account.forms import SignupForm
from django.contrib.auth import forms as admin_forms
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _

from nlpmed_portal.users.models import User


[docs] class UserAdminChangeForm(admin_forms.UserChangeForm):
[docs] class Meta(admin_forms.UserChangeForm.Meta): model = User
[docs] class UserAdminCreationForm(admin_forms.UserCreationForm): """ Form for User Creation in the Admin Area. To change user signup, see UserSignupForm and UserSocialSignupForm. """
[docs] class Meta(admin_forms.UserCreationForm.Meta): model = User error_messages = { "username": {"unique": _("This username has already been taken.")}, }
[docs] class UserSignupForm(SignupForm): """ Form that will be rendered on a user sign up section/screen. Default fields will be added automatically. Check UserSocialSignupForm for accounts created from social. """
[docs] class UserUpdateForm(ModelForm):
[docs] class Meta: model = User fields = ["username", "email", "name", "groups"]
[docs] def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) for field_name in self.fields: if field_name != "name": self.fields[field_name].disabled = True