From 077a2ee00d72199376566be9f9c8af0a10e1b6a2 Mon Sep 17 00:00:00 2001 From: pinwheeeel Date: Wed, 2 Oct 2024 22:02:15 -0400 Subject: [PATCH 1/4] usernames are now editable --- core/views/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/views/user.py b/core/views/user.py index c12a0962..3ceb89d9 100644 --- a/core/views/user.py +++ b/core/views/user.py @@ -43,7 +43,7 @@ def get_context_data(self, **kwargs): class ProfileUpdate(LoginRequiredMixin, UpdateView, mixins.TitleMixin): model = models.User - fields = ["bio", "first_name", "last_name", "graduating_year"] + fields = ["bio", "username", "first_name", "last_name", "graduating_year"] template_name = "core/profile/update.html" success_url = reverse_lazy("profile_redirect") title = "Update Profile" From d8a32836d71e05bd61419e99b3b79587a8c47362 Mon Sep 17 00:00:00 2001 From: pinwheeeel Date: Wed, 2 Oct 2024 22:43:18 -0400 Subject: [PATCH 2/4] fix bug where you can't add users from admin panel --- core/admin.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/admin.py b/core/admin.py index c3164d40..f669e119 100644 --- a/core/admin.py +++ b/core/admin.py @@ -628,6 +628,16 @@ class UserAdmin(DjangoUserAdmin): form = UserAdminForm add_form = UserCreationForm + add_fieldsets = ( + ( + None, + { + "classes": ("wide",), + "fields": ("username", "password1", "password2"), # Removed usable_password field + }, + ), + ) + def get_inline_instances(self, request, obj=None): if obj and StaffMember.objects.filter(user=obj).exists(): # Add StaffMemberInline if the user has a related StaffMember From 6f9b306f774d0d9f78bb8bc70754636643beaef7 Mon Sep 17 00:00:00 2001 From: pinwheeeel Date: Wed, 2 Oct 2024 23:17:07 -0400 Subject: [PATCH 3/4] undo last commit: turns out hiding usable_password didn't make much sense --- core/admin.py | 10 ---------- core/forms.py | 4 ++-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/core/admin.py b/core/admin.py index f669e119..c3164d40 100644 --- a/core/admin.py +++ b/core/admin.py @@ -628,16 +628,6 @@ class UserAdmin(DjangoUserAdmin): form = UserAdminForm add_form = UserCreationForm - add_fieldsets = ( - ( - None, - { - "classes": ("wide",), - "fields": ("username", "password1", "password2"), # Removed usable_password field - }, - ), - ) - def get_inline_instances(self, request, obj=None): if obj and StaffMember.objects.filter(user=obj).exists(): # Add StaffMemberInline if the user has a related StaffMember diff --git a/core/forms.py b/core/forms.py index 1ae7438d..cfcd7a9b 100644 --- a/core/forms.py +++ b/core/forms.py @@ -2,7 +2,7 @@ from django import forms from django.conf import settings from django.contrib.auth.forms import UserChangeForm as ContribUserChangeForm -from django.contrib.auth.forms import UserCreationForm as ContribUserCreationForm +from django.contrib.auth.forms import AdminUserCreationForm as ContribAdminUserCreationForm from django.utils import timezone from django_select2 import forms as s2forms from martor.widgets import AdminMartorWidget @@ -290,5 +290,5 @@ class UserAdminForm(CaseInsensitiveUsernameMixin, ContribUserChangeForm): expo_notif_tokens = forms.JSONField(required=False) -class UserCreationForm(CaseInsensitiveUsernameMixin, ContribUserCreationForm): +class UserCreationForm(CaseInsensitiveUsernameMixin, ContribAdminUserCreationForm): pass From d9f0e779afe410114954d8fd7322080fbad4eb72 Mon Sep 17 00:00:00 2001 From: pinwheeeel Date: Thu, 3 Oct 2024 00:15:29 -0400 Subject: [PATCH 4/4] change bad form name --- core/admin.py | 4 ++-- core/forms.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/admin.py b/core/admin.py index c3164d40..a1753690 100644 --- a/core/admin.py +++ b/core/admin.py @@ -23,7 +23,7 @@ TagSuperuserAdminForm, TermAdminForm, UserAdminForm, - UserCreationForm, + UserCreationAdminForm, ) from .models import Comment, StaffMember from .utils.actions import ( @@ -626,7 +626,7 @@ class UserAdmin(DjangoUserAdmin): ] actions = [send_test_notif, send_notif_singleday] form = UserAdminForm - add_form = UserCreationForm + add_form = UserCreationAdminForm def get_inline_instances(self, request, obj=None): if obj and StaffMember.objects.filter(user=obj).exists(): diff --git a/core/forms.py b/core/forms.py index cfcd7a9b..e10bf8ca 100644 --- a/core/forms.py +++ b/core/forms.py @@ -290,5 +290,5 @@ class UserAdminForm(CaseInsensitiveUsernameMixin, ContribUserChangeForm): expo_notif_tokens = forms.JSONField(required=False) -class UserCreationForm(CaseInsensitiveUsernameMixin, ContribAdminUserCreationForm): +class UserCreationAdminForm(CaseInsensitiveUsernameMixin, ContribAdminUserCreationForm): pass