Coverage for accounts/views.py: 100.00%
28 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-05 08:37 -0800
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-05 08:37 -0800
1"""Views for djapi-library user accounts."""
3from typing import ClassVar 1a
5from django.contrib.auth import get_user_model 1a
6from django.contrib.auth.mixins import LoginRequiredMixin 1a
7from django.urls import reverse, reverse_lazy 1a
8from django.views.generic import ( 1a
9 CreateView,
10 DetailView,
11 RedirectView,
12 UpdateView,
13)
15from .forms import CustomUserCreationForm 1a
17User = get_user_model() 1a
20class SignupPageView(CreateView): 1a
21 form_class = CustomUserCreationForm 1a
22 success_url = reverse_lazy("account_login") 1a
23 template_name = "account/signup.html" 1a
26class UserDetailView(LoginRequiredMixin, DetailView): 1a
27 """Tell the view to index lookups by username."""
29 model = User 1a
30 slug_field = "username" 1a
31 slug_url_kwarg = "username" 1a
33 template_name = "account/user_detail.html" 1a
36class UserUpdateView(LoginRequiredMixin, UpdateView): 1a
37 fields: ClassVar[list[str]] = [ 1a
38 "name",
39 "bio",
40 "country",
41 "profile_pic",
42 ]
43 model = User 1a
45 def get_success_url(self): 1a
46 """Send the user back to their own page after a successful update."""
47 return reverse( 1a
48 "user_detail",
49 kwargs={"username": self.request.user.username},
50 )
52 def get_object(self): 1a
53 """Only get the user record for the user making the request."""
54 return User.objects.get(username=self.request.user.username) 1a
56 template_name = "account/user_form.html" 1a
59class UserRedirectView(LoginRequiredMixin, RedirectView): 1a
60 permanent = False 1a
62 def get_redirect_url(self): 1a
63 return reverse( 1a
64 "user_detail",
65 kwargs={"username": self.request.user.username},
66 )