Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#275) Allow users to change username when editing profile #279

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -290,5 +290,5 @@ class UserAdminForm(CaseInsensitiveUsernameMixin, ContribUserChangeForm):
expo_notif_tokens = forms.JSONField(required=False)


class UserCreationForm(CaseInsensitiveUsernameMixin, ContribUserCreationForm):
class UserCreationForm(CaseInsensitiveUsernameMixin, ContribAdminUserCreationForm):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry why does this need to be ADMIN user form?

Copy link
Contributor Author

@pinwheeeel pinwheeeel Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core.UserCreationForm requires the same priveleges as django's AdminPasswordChangeForm (specific password-related form mixins) because passwords have to be dealt with when making a new user. I could either manually add the mixins to core.UserCreationForm or use django's AdminUserCreationForm (what I did above) which is almost identical to the normal UserCreationForm except for the fact that it comes with the mixins already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core.UserCreationForm is only ever used in core.UserAdmin anyways

Copy link
Contributor Author

@pinwheeeel pinwheeeel Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be better to rename core.UserCreationForm to core.UserCreationAdminForm in order to stay consistent. If you look inside admin.py:

from .forms import (
    AnnouncementAdminForm,
    AnnouncementSupervisorAdminForm,
    EventAdminForm,
    OrganizationAdminForm,
    TagAdminForm,
    TagSuperuserAdminForm,
    TermAdminForm,
    UserAdminForm,
    UserCreationForm, # Not named as an admin form (?)
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case then yeah, it should be

pass
2 changes: 1 addition & 1 deletion core/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading