Skip to content

Commit

Permalink
move profile page from user detail view
Browse files Browse the repository at this point in the history
  • Loading branch information
jchate6 committed Dec 21, 2024
1 parent 820fa5d commit 0ab75b1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
4 changes: 2 additions & 2 deletions tom_common/templates/tom_common/partials/navbar_login.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% if user.is_authenticated %}
<li class="nav-item">
{% if user.first_name or user.last_name %}
<a class="nav-link" href="{% url 'user-profile' user.id %}">{{ user.first_name }} {{ user.last_name }} ({{ user.username }})</a>
<a class="nav-link" href="{% url 'user-profile' %}">{{ user.first_name }} {{ user.last_name }} ({{ user.username }})</a>
{% else %}
<a class="nav-link" href="{% url 'user-profile' user.id %}">{{ user.username }}</a>
<a class="nav-link" href="{% url 'user-profile' %}">{{ user.username }}</a>
{% endif %}
</li>
<li>
Expand Down
4 changes: 2 additions & 2 deletions tom_common/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from tom_base import __version__
from tom_common.api_views import GroupViewSet
from tom_common.views import UserListView, UserPasswordChangeView, UserCreateView, UserDeleteView, UserUpdateView
from tom_common.views import CommentDeleteView, GroupCreateView, GroupUpdateView, GroupDeleteView, UserDetailView
from tom_common.views import CommentDeleteView, GroupCreateView, GroupUpdateView, GroupDeleteView, UserProfileView
from tom_common.views import robots_txt

from .api_router import collect_api_urls, SharedAPIRootRouter # DRF routers are setup in each INSTALL_APPS url.py
Expand All @@ -49,7 +49,7 @@
path('users/create/', UserCreateView.as_view(), name='user-create'),
path('users/<int:pk>/delete/', UserDeleteView.as_view(), name='user-delete'),
path('users/<int:pk>/update/', UserUpdateView.as_view(), name='user-update'),
path('users/<int:pk>/profile/', UserDetailView.as_view(), name='user-profile'),
path('users/profile/', UserProfileView.as_view(), name='user-profile'),
path('groups/create/', GroupCreateView.as_view(), name='group-create'),
path('groups/<int:pk>/update/', GroupUpdateView.as_view(), name='group-update'),
path('groups/<int:pk>/delete/', GroupDeleteView.as_view(), name='group-delete'),
Expand Down
13 changes: 1 addition & 12 deletions tom_common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,11 @@ def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)


class UserDetailView(LoginRequiredMixin, DetailView):
class UserProfileView(LoginRequiredMixin, TemplateView):
"""
View to handle creating a user profile page. Requires a login.
"""
template_name = 'tom_common/user_profile.html'
model = User

def dispatch(self, *args, **kwargs):
"""
Directs the class-based view to the correct method for the HTTP request method. Ensures that non-superusers
are not incorrectly updating the profiles of other users.
"""
if not self.request.user.is_superuser and self.request.user.id != self.kwargs['pk']:
return redirect('user-profile', self.request.user.id)
else:
return super().dispatch(*args, **kwargs)


class UserPasswordChangeView(SuperuserRequiredMixin, FormView):
Expand Down

0 comments on commit 0ab75b1

Please sign in to comment.