We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Refactor function-based view to class-based
### Idea summary

Rewrite function-based view to class-based and add docstring

### Further details

In the accounts app's view, there is a function-based view called user_profile: 
```python
@login_required
@full_profile
def user_profile(request, username=None):
    if request.method == "GET":
        if not username:
            return HttpResponseRedirect(f"/profile/{request.user}")
        else:
            is_owner = username == request.user.username
            try:
                user = get_user_model().objects.get(username=username)
            except get_user_model().DoesNotExist:
                return HttpResponseRedirect("/404")

        form = ProfileEditForm(
            initial={
                "username": user.username,
                "email": user.email,
                "first_name": user.profile.first_name or None,
                "last_name": user.profile.last_name or None,
                "about_me": user.profile.about_me or None,
            },
            readonly=True,
        )
        data = {
            "username": user,
            "profile_image_form": UpdateProfileImage,
            "form": form if is_owner else None,
            "readonly": True,
        }
        return TemplateResponse(request, "account.html", data)
```
All views in this file are created using classes, so I think it will be great to rewrite this view for better sticking to the code style. Moreover, this view has no docstring. I'm new to contributing to Open Source. I want to solve this issue, and I know-how.  

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `project/accounts/urls/urls.py`
Content:
```
1 from django.urls import path
2 from django.contrib.auth import views as auth_views
3 from accounts.views import (
4     RegisterView,
5     SettingsView,
6     ProfileActivationView,
7     PasswordResetView,
8     PasswordResetDoneView,
9     PasswordResetConfirmView,
10     PasswordResetCompleteView,
11     ProfileSetupView,
12     user_profile,
13 )
14 
15 urlpatterns = [
16     path(
17         "login/",
18         auth_views.LoginView.as_view(template_name="accounts/register/login.html"),
19         name="accounts_login",
20     ),
21     path("logout/", auth_views.LogoutView.as_view(), name="accounts_logout"),
22     path("register/", RegisterView.as_view(), name="accounts_register"),
23     path("settings/", SettingsView.as_view(), name="accounts_settings"),
24     path("setup/", ProfileSetupView.as_view(), name="accounts_profile_setup"),
25     path("profile/<str:username>/", user_profile, name="profile"),
26     path(
27         "activate_account/<uidb64>/<token>/",
28         ProfileActivationView.as_view(),
29         name="accounts_activate",
30     ),
31     path(
32         "accounts/password_reset/",
33         PasswordResetView.as_view(),
34         name="accounts_password_reset",
35     ),
36     path(
37         "accounts/password_reset_done/",
38         PasswordResetDoneView.as_view(),
39         name="accounts_password_reset_done",
40     ),
41     path(
42         "accounts/password_reset_confirm/<uidb64>/<token>/",
43         PasswordResetConfirmView.as_view(),
44         name="accounts_password_reset_confirm",
45     ),
46     path(
47         "accounts/password_reset_complete/",
48         PasswordResetCompleteView.as_view(),
49         name="accounts_password_reset_complete",
50     ),
51 ]
52
```

Path: `project/accounts/views.py`
Content:
```
1 """
2 Class based views.
3 
4 This module will include views for the accounts app.
5 """
6 
7 from core.custom_decorators import full_profile, login_required
8 from django.conf import settings
9 from django.contrib.auth import get_user_model, login
10 from django.contrib.auth import views as auth_views
11 from django.contrib.auth.mixins import LoginRequiredMixin
12 from django.contrib.sites.shortcuts import get_current_site
13 from django.http import HttpResponseRedirect
14 from django.template.response import TemplateResponse
15 from django.urls import reverse_lazy
16 from django.utils.encoding import force_str
17 from django.utils.http import urlsafe_base64_decode
18 from django.views import View
19 from django.views.generic.edit import FormView, UpdateView
20 
21 from accounts.authentication import account_activation_token, send_activation_email
22 from accounts.forms import ProfileEditForm, UpdateProfileImage, UserRegistrationForm
23 from accounts.models import Profile
24 
25 
26 class RegisterView(FormView):
27     """
28     A form view that handles user registration.
29     """
30 
31     template_name = "accounts/register/register.html"
32     form_class = UserRegistrationForm
33     success_url = "/"
34 
35     def _create_user(self, form):
36         username = form.cleaned_data["username"]
37         password = form.cleaned_data["password"]
38         email = form.cleaned_data["email"]
39         user = get_user_model().objects.create_user(username, email, password)
40         return user
41 
42     def _send_email(self, user):
43         domain = get_current_site(self.request).domain
44         send_activation_email(user, domain)
45 
46     def _login(self, user):
47         login(self.request, user)
48 
49     def form_valid(self, form):
50         user = self._create_user(form)
51 
52         self._send_email(user)
53         self._login(user)
54 
55         return super(RegisterView, self).form_valid(form)
56 
57 
58 class PasswordResetView(auth_views.PasswordResetView):
59     template_name = "accounts/users/password_reset.html"
60     email_template_name = "accounts/users/password_reset_email.html"
61     subject_template_name = "accounts/users/password_reset_subject.txt"
62     from_email = settings.EMAIL_HOST_USER
63     success_url = reverse_lazy("accounts_password_reset_done")
64 
65 
66 class PasswordResetDoneView(auth_views.PasswordResetDoneView):
67     template_name = "accounts/users/password_reset_done.html"
68 
69 
70 class PasswordResetConfirmView(auth_views.PasswordResetConfirmView):
71     template_name = "accounts/users/password_reset_confirm.html"
72     success_url = reverse_lazy("accounts_password_reset_complete")
73 
74 
75 class PasswordResetCompleteView(auth_views.PasswordResetCompleteView):
76     template_name = "accounts/users/password_reset_complete.html"
77 
78 
79 class SettingsView(LoginRequiredMixin, UpdateView):
80     """A form view to edit Profile"""
81 
82     login_url = "accounts_login"
83     form_class = ProfileEditForm
84     success_url = reverse_lazy("accounts_settings")
85     template_name = "accounts/update_settings.html"
86 
87     def get_object(self, queryset=None):
88         return Profile.objects.get(user=self.request.user)
89 
90     def get_initial(self):
91         profile = Profile.objects.get(user=self.request.user)
92         self.initial.update(
93             {
94                 "username": profile.user.username,
95                 "email": profile.user.email,
96                 "first_name": profile.first_name or None,
97                 "last_name": profile.last_name or None,
98                 "about_me": profile.about_me or None,
99             }
100         )
101         return super(SettingsView, self).get_initial()
102 
103 
104 class ProfileActivationView(View):
105     """
106     This shows different views to the user when they are verifying
107     their account based on whether they are already verified or not.
108     """
109 
110     def get(self, request, uidb64, token):
111 
112         try:
113             uid = force_str(urlsafe_base64_decode(uidb64))
114             user = get_user_model().objects.get(pk=uid)
115 
116         except (TypeError, ValueError, OverflowError, get_user_model().DoesNotExist):
117             user = None
118 
119         if user is not None and account_activation_token.check_token(user, token):
120             profile = user.profile
121             if profile.is_verified:
122                 redirect_link = {"href": "/", "label": "Back to Main"}
123                 template_var = {
124                     "title": "Email Already Verified",
125                     "content": "You have already verified your email",
126                     "link": redirect_link,
127                 }
128             else:
129                 profile.is_verified = True
130                 profile.save()
131 
132                 redirect_link = {"href": "/", "label": "Back to Main"}
133                 template_var = {
134                     "title": "Email Verification Successful",
135                     "content": "Thank you for verifying your email with CiviWiki",
136                     "link": redirect_link,
137                 }
138         else:
139             # invalid link
140             redirect_link = {"href": "/", "label": "Back to Main"}
141             template_var = {
142                 "title": "Email Verification Error",
143                 "content": "Email could not be verified",
144                 "link": redirect_link,
145             }
146 
147         return TemplateResponse(request, "general_message.html", template_var)
148 
149 
150 class ProfileSetupView(LoginRequiredMixin, View):
151     """A view to make the user profile full_profile"""
152 
153     login_url = "accounts_login"
154 
155     def get(self, request):
156         profile = Profile.objects.get(user=request.user)
157         if profile.full_profile:
158             return HttpResponseRedirect("/")
159             # start temp rep rendering TODO: REMOVE THIS
160         else:
161             data = {
162                 "username": request.user.username,
163                 "email": request.user.email,
164             }
165             return TemplateResponse(request, "accounts/user-setup.html", data)
166 
167 
168 @login_required
169 @full_profile
170 def user_profile(request, username=None):
171     if request.method == "GET":
172         if not username:
173             return HttpResponseRedirect(f"/profile/{request.user}")
174         else:
175             is_owner = username == request.user.username
176             try:
177                 user = get_user_model().objects.get(username=username)
178             except get_user_model().DoesNotExist:
179                 return HttpResponseRedirect("/404")
180 
181         form = ProfileEditForm(
182             initial={
183                 "username": user.username,
184                 "email": user.email,
185                 "first_name": user.profile.first_name or None,
186                 "last_name": user.profile.last_name or None,
187                 "about_me": user.profile.about_me or None,
188             },
189             readonly=True,
190         )
191         data = {
192             "username": user,
193             "profile_image_form": UpdateProfileImage,
194             "form": form if is_owner else None,
195             "readonly": True,
196         }
197         return TemplateResponse(request, "account.html", data)
198
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/project/accounts/urls/urls.py b/project/accounts/urls/urls.py
--- a/project/accounts/urls/urls.py
+++ b/project/accounts/urls/urls.py
@@ -9,7 +9,7 @@
     PasswordResetConfirmView,
     PasswordResetCompleteView,
     ProfileSetupView,
-    user_profile,
+    UserProfileView,
 )
 
 urlpatterns = [
@@ -22,7 +22,7 @@
     path("register/", RegisterView.as_view(), name="accounts_register"),
     path("settings/", SettingsView.as_view(), name="accounts_settings"),
     path("setup/", ProfileSetupView.as_view(), name="accounts_profile_setup"),
-    path("profile/<str:username>/", user_profile, name="profile"),
+    path("profile/<str:username>/", UserProfileView.as_view(), name="profile"),
     path(
         "activate_account/<uidb64>/<token>/",
         ProfileActivationView.as_view(),
diff --git a/project/accounts/views.py b/project/accounts/views.py
--- a/project/accounts/views.py
+++ b/project/accounts/views.py
@@ -4,7 +4,7 @@
 This module will include views for the accounts app.
 """
 
-from core.custom_decorators import full_profile, login_required
+from core.custom_decorators import full_profile
 from django.conf import settings
 from django.contrib.auth import get_user_model, login
 from django.contrib.auth import views as auth_views
@@ -15,6 +15,7 @@
 from django.urls import reverse_lazy
 from django.utils.encoding import force_str
 from django.utils.http import urlsafe_base64_decode
+from django.utils.decorators import method_decorator
 from django.views import View
 from django.views.generic.edit import FormView, UpdateView
 
@@ -165,16 +166,18 @@
             return TemplateResponse(request, "accounts/user-setup.html", data)
 
 
-@login_required
-@full_profile
-def user_profile(request, username=None):
-    if request.method == "GET":
+class UserProfileView(LoginRequiredMixin, View):
+    """A view that shows profile for authorized users"""
+
+    @method_decorator(full_profile)
+    def get(self, request, username=None):
         if not username:
             return HttpResponseRedirect(f"/profile/{request.user}")
         else:
             is_owner = username == request.user.username
             try:
                 user = get_user_model().objects.get(username=username)
+
             except get_user_model().DoesNotExist:
                 return HttpResponseRedirect("/404")

{"golden_diff": "diff --git a/project/accounts/urls/urls.py b/project/accounts/urls/urls.py\n--- a/project/accounts/urls/urls.py\n+++ b/project/accounts/urls/urls.py\n@@ -9,7 +9,7 @@\n     PasswordResetConfirmView,\n     PasswordResetCompleteView,\n     ProfileSetupView,\n-    user_profile,\n+    UserProfileView,\n )\n \n urlpatterns = [\n@@ -22,7 +22,7 @@\n     path(\"register/\", RegisterView.as_view(), name=\"accounts_register\"),\n     path(\"settings/\", SettingsView.as_view(), name=\"accounts_settings\"),\n     path(\"setup/\", ProfileSetupView.as_view(), name=\"accounts_profile_setup\"),\n-    path(\"profile/<str:username>/\", user_profile, name=\"profile\"),\n+    path(\"profile/<str:username>/\", UserProfileView.as_view(), name=\"profile\"),\n     path(\n         \"activate_account/<uidb64>/<token>/\",\n         ProfileActivationView.as_view(),\ndiff --git a/project/accounts/views.py b/project/accounts/views.py\n--- a/project/accounts/views.py\n+++ b/project/accounts/views.py\n@@ -4,7 +4,7 @@\n This module will include views for the accounts app.\n \"\"\"\n \n-from core.custom_decorators import full_profile, login_required\n+from core.custom_decorators import full_profile\n from django.conf import settings\n from django.contrib.auth import get_user_model, login\n from django.contrib.auth import views as auth_views\n@@ -15,6 +15,7 @@\n from django.urls import reverse_lazy\n from django.utils.encoding import force_str\n from django.utils.http import urlsafe_base64_decode\n+from django.utils.decorators import method_decorator\n from django.views import View\n from django.views.generic.edit import FormView, UpdateView\n \n@@ -165,16 +166,18 @@\n             return TemplateResponse(request, \"accounts/user-setup.html\", data)\n \n \n-@login_required\n-@full_profile\n-def user_profile(request, username=None):\n-    if request.method == \"GET\":\n+class UserProfileView(LoginRequiredMixin, View):\n+    \"\"\"A view that shows profile for authorized users\"\"\"\n+\n+    @method_decorator(full_profile)\n+    def get(self, request, username=None):\n         if not username:\n             return HttpResponseRedirect(f\"/profile/{request.user}\")\n         else:\n             is_owner = username == request.user.username\n             try:\n                 user = get_user_model().objects.get(username=username)\n+\n             except get_user_model().DoesNotExist:\n                 return HttpResponseRedirect(\"/404\")\n", "issue": "Refactor function-based view to class-based\n### Idea summary\n\nRewrite function-based view to class-based and add docstring\n\n### Further details\n\nIn the accounts app's view, there is a function-based view called user_profile: \r\n```python\r\n@login_required\r\n@full_profile\r\ndef user_profile(request, username=None):\r\n    if request.method == \"GET\":\r\n        if not username:\r\n            return HttpResponseRedirect(f\"/profile/{request.user}\")\r\n        else:\r\n            is_owner = username == request.user.username\r\n            try:\r\n                user = get_user_model().objects.get(username=username)\r\n            except get_user_model().DoesNotExist:\r\n                return HttpResponseRedirect(\"/404\")\r\n\r\n        form = ProfileEditForm(\r\n            initial={\r\n                \"username\": user.username,\r\n                \"email\": user.email,\r\n                \"first_name\": user.profile.first_name or None,\r\n                \"last_name\": user.profile.last_name or None,\r\n                \"about_me\": user.profile.about_me or None,\r\n            },\r\n            readonly=True,\r\n        )\r\n        data = {\r\n            \"username\": user,\r\n            \"profile_image_form\": UpdateProfileImage,\r\n            \"form\": form if is_owner else None,\r\n            \"readonly\": True,\r\n        }\r\n        return TemplateResponse(request, \"account.html\", data)\r\n```\r\nAll views in this file are created using classes, so I think it will be great to rewrite this view for better sticking to the code style. Moreover, this view has no docstring. I'm new to contributing to Open Source. I want to solve this issue, and I know-how.  \n", "before_files": [{"content": "from django.urls import path\nfrom django.contrib.auth import views as auth_views\nfrom accounts.views import (\n    RegisterView,\n    SettingsView,\n    ProfileActivationView,\n    PasswordResetView,\n    PasswordResetDoneView,\n    PasswordResetConfirmView,\n    PasswordResetCompleteView,\n    ProfileSetupView,\n    user_profile,\n)\n\nurlpatterns = [\n    path(\n        \"login/\",\n        auth_views.LoginView.as_view(template_name=\"accounts/register/login.html\"),\n        name=\"accounts_login\",\n    ),\n    path(\"logout/\", auth_views.LogoutView.as_view(), name=\"accounts_logout\"),\n    path(\"register/\", RegisterView.as_view(), name=\"accounts_register\"),\n    path(\"settings/\", SettingsView.as_view(), name=\"accounts_settings\"),\n    path(\"setup/\", ProfileSetupView.as_view(), name=\"accounts_profile_setup\"),\n    path(\"profile/<str:username>/\", user_profile, name=\"profile\"),\n    path(\n        \"activate_account/<uidb64>/<token>/\",\n        ProfileActivationView.as_view(),\n        name=\"accounts_activate\",\n    ),\n    path(\n        \"accounts/password_reset/\",\n        PasswordResetView.as_view(),\n        name=\"accounts_password_reset\",\n    ),\n    path(\n        \"accounts/password_reset_done/\",\n        PasswordResetDoneView.as_view(),\n        name=\"accounts_password_reset_done\",\n    ),\n    path(\n        \"accounts/password_reset_confirm/<uidb64>/<token>/\",\n        PasswordResetConfirmView.as_view(),\n        name=\"accounts_password_reset_confirm\",\n    ),\n    path(\n        \"accounts/password_reset_complete/\",\n        PasswordResetCompleteView.as_view(),\n        name=\"accounts_password_reset_complete\",\n    ),\n]\n", "path": "project/accounts/urls/urls.py"}, {"content": "\"\"\"\nClass based views.\n\nThis module will include views for the accounts app.\n\"\"\"\n\nfrom core.custom_decorators import full_profile, login_required\nfrom django.conf import settings\nfrom django.contrib.auth import get_user_model, login\nfrom django.contrib.auth import views as auth_views\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.contrib.sites.shortcuts import get_current_site\nfrom django.http import HttpResponseRedirect\nfrom django.template.response import TemplateResponse\nfrom django.urls import reverse_lazy\nfrom django.utils.encoding import force_str\nfrom django.utils.http import urlsafe_base64_decode\nfrom django.views import View\nfrom django.views.generic.edit import FormView, UpdateView\n\nfrom accounts.authentication import account_activation_token, send_activation_email\nfrom accounts.forms import ProfileEditForm, UpdateProfileImage, UserRegistrationForm\nfrom accounts.models import Profile\n\n\nclass RegisterView(FormView):\n    \"\"\"\n    A form view that handles user registration.\n    \"\"\"\n\n    template_name = \"accounts/register/register.html\"\n    form_class = UserRegistrationForm\n    success_url = \"/\"\n\n    def _create_user(self, form):\n        username = form.cleaned_data[\"username\"]\n        password = form.cleaned_data[\"password\"]\n        email = form.cleaned_data[\"email\"]\n        user = get_user_model().objects.create_user(username, email, password)\n        return user\n\n    def _send_email(self, user):\n        domain = get_current_site(self.request).domain\n        send_activation_email(user, domain)\n\n    def _login(self, user):\n        login(self.request, user)\n\n    def form_valid(self, form):\n        user = self._create_user(form)\n\n        self._send_email(user)\n        self._login(user)\n\n        return super(RegisterView, self).form_valid(form)\n\n\nclass PasswordResetView(auth_views.PasswordResetView):\n    template_name = \"accounts/users/password_reset.html\"\n    email_template_name = \"accounts/users/password_reset_email.html\"\n    subject_template_name = \"accounts/users/password_reset_subject.txt\"\n    from_email = settings.EMAIL_HOST_USER\n    success_url = reverse_lazy(\"accounts_password_reset_done\")\n\n\nclass PasswordResetDoneView(auth_views.PasswordResetDoneView):\n    template_name = \"accounts/users/password_reset_done.html\"\n\n\nclass PasswordResetConfirmView(auth_views.PasswordResetConfirmView):\n    template_name = \"accounts/users/password_reset_confirm.html\"\n    success_url = reverse_lazy(\"accounts_password_reset_complete\")\n\n\nclass PasswordResetCompleteView(auth_views.PasswordResetCompleteView):\n    template_name = \"accounts/users/password_reset_complete.html\"\n\n\nclass SettingsView(LoginRequiredMixin, UpdateView):\n    \"\"\"A form view to edit Profile\"\"\"\n\n    login_url = \"accounts_login\"\n    form_class = ProfileEditForm\n    success_url = reverse_lazy(\"accounts_settings\")\n    template_name = \"accounts/update_settings.html\"\n\n    def get_object(self, queryset=None):\n        return Profile.objects.get(user=self.request.user)\n\n    def get_initial(self):\n        profile = Profile.objects.get(user=self.request.user)\n        self.initial.update(\n            {\n                \"username\": profile.user.username,\n                \"email\": profile.user.email,\n                \"first_name\": profile.first_name or None,\n                \"last_name\": profile.last_name or None,\n                \"about_me\": profile.about_me or None,\n            }\n        )\n        return super(SettingsView, self).get_initial()\n\n\nclass ProfileActivationView(View):\n    \"\"\"\n    This shows different views to the user when they are verifying\n    their account based on whether they are already verified or not.\n    \"\"\"\n\n    def get(self, request, uidb64, token):\n\n        try:\n            uid = force_str(urlsafe_base64_decode(uidb64))\n            user = get_user_model().objects.get(pk=uid)\n\n        except (TypeError, ValueError, OverflowError, get_user_model().DoesNotExist):\n            user = None\n\n        if user is not None and account_activation_token.check_token(user, token):\n            profile = user.profile\n            if profile.is_verified:\n                redirect_link = {\"href\": \"/\", \"label\": \"Back to Main\"}\n                template_var = {\n                    \"title\": \"Email Already Verified\",\n                    \"content\": \"You have already verified your email\",\n                    \"link\": redirect_link,\n                }\n            else:\n                profile.is_verified = True\n                profile.save()\n\n                redirect_link = {\"href\": \"/\", \"label\": \"Back to Main\"}\n                template_var = {\n                    \"title\": \"Email Verification Successful\",\n                    \"content\": \"Thank you for verifying your email with CiviWiki\",\n                    \"link\": redirect_link,\n                }\n        else:\n            # invalid link\n            redirect_link = {\"href\": \"/\", \"label\": \"Back to Main\"}\n            template_var = {\n                \"title\": \"Email Verification Error\",\n                \"content\": \"Email could not be verified\",\n                \"link\": redirect_link,\n            }\n\n        return TemplateResponse(request, \"general_message.html\", template_var)\n\n\nclass ProfileSetupView(LoginRequiredMixin, View):\n    \"\"\"A view to make the user profile full_profile\"\"\"\n\n    login_url = \"accounts_login\"\n\n    def get(self, request):\n        profile = Profile.objects.get(user=request.user)\n        if profile.full_profile:\n            return HttpResponseRedirect(\"/\")\n            # start temp rep rendering TODO: REMOVE THIS\n        else:\n            data = {\n                \"username\": request.user.username,\n                \"email\": request.user.email,\n            }\n            return TemplateResponse(request, \"accounts/user-setup.html\", data)\n\n\n@login_required\n@full_profile\ndef user_profile(request, username=None):\n    if request.method == \"GET\":\n        if not username:\n            return HttpResponseRedirect(f\"/profile/{request.user}\")\n        else:\n            is_owner = username == request.user.username\n            try:\n                user = get_user_model().objects.get(username=username)\n            except get_user_model().DoesNotExist:\n                return HttpResponseRedirect(\"/404\")\n\n        form = ProfileEditForm(\n            initial={\n                \"username\": user.username,\n                \"email\": user.email,\n                \"first_name\": user.profile.first_name or None,\n                \"last_name\": user.profile.last_name or None,\n                \"about_me\": user.profile.about_me or None,\n            },\n            readonly=True,\n        )\n        data = {\n            \"username\": user,\n            \"profile_image_form\": UpdateProfileImage,\n            \"form\": form if is_owner else None,\n            \"readonly\": True,\n        }\n        return TemplateResponse(request, \"account.html\", data)\n", "path": "project/accounts/views.py"}], "after_files": [{"content": "from django.urls import path\nfrom django.contrib.auth import views as auth_views\nfrom accounts.views import (\n    RegisterView,\n    SettingsView,\n    ProfileActivationView,\n    PasswordResetView,\n    PasswordResetDoneView,\n    PasswordResetConfirmView,\n    PasswordResetCompleteView,\n    ProfileSetupView,\n    UserProfileView,\n)\n\nurlpatterns = [\n    path(\n        \"login/\",\n        auth_views.LoginView.as_view(template_name=\"accounts/register/login.html\"),\n        name=\"accounts_login\",\n    ),\n    path(\"logout/\", auth_views.LogoutView.as_view(), name=\"accounts_logout\"),\n    path(\"register/\", RegisterView.as_view(), name=\"accounts_register\"),\n    path(\"settings/\", SettingsView.as_view(), name=\"accounts_settings\"),\n    path(\"setup/\", ProfileSetupView.as_view(), name=\"accounts_profile_setup\"),\n    path(\"profile/<str:username>/\", UserProfileView.as_view(), name=\"profile\"),\n    path(\n        \"activate_account/<uidb64>/<token>/\",\n        ProfileActivationView.as_view(),\n        name=\"accounts_activate\",\n    ),\n    path(\n        \"accounts/password_reset/\",\n        PasswordResetView.as_view(),\n        name=\"accounts_password_reset\",\n    ),\n    path(\n        \"accounts/password_reset_done/\",\n        PasswordResetDoneView.as_view(),\n        name=\"accounts_password_reset_done\",\n    ),\n    path(\n        \"accounts/password_reset_confirm/<uidb64>/<token>/\",\n        PasswordResetConfirmView.as_view(),\n        name=\"accounts_password_reset_confirm\",\n    ),\n    path(\n        \"accounts/password_reset_complete/\",\n        PasswordResetCompleteView.as_view(),\n        name=\"accounts_password_reset_complete\",\n    ),\n]\n", "path": "project/accounts/urls/urls.py"}, {"content": "\"\"\"\nClass based views.\n\nThis module will include views for the accounts app.\n\"\"\"\n\nfrom core.custom_decorators import full_profile\nfrom django.conf import settings\nfrom django.contrib.auth import get_user_model, login\nfrom django.contrib.auth import views as auth_views\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.contrib.sites.shortcuts import get_current_site\nfrom django.http import HttpResponseRedirect\nfrom django.template.response import TemplateResponse\nfrom django.urls import reverse_lazy\nfrom django.utils.encoding import force_str\nfrom django.utils.http import urlsafe_base64_decode\nfrom django.utils.decorators import method_decorator\nfrom django.views import View\nfrom django.views.generic.edit import FormView, UpdateView\n\nfrom accounts.authentication import account_activation_token, send_activation_email\nfrom accounts.forms import ProfileEditForm, UpdateProfileImage, UserRegistrationForm\nfrom accounts.models import Profile\n\n\nclass RegisterView(FormView):\n    \"\"\"\n    A form view that handles user registration.\n    \"\"\"\n\n    template_name = \"accounts/register/register.html\"\n    form_class = UserRegistrationForm\n    success_url = \"/\"\n\n    def _create_user(self, form):\n        username = form.cleaned_data[\"username\"]\n        password = form.cleaned_data[\"password\"]\n        email = form.cleaned_data[\"email\"]\n        user = get_user_model().objects.create_user(username, email, password)\n        return user\n\n    def _send_email(self, user):\n        domain = get_current_site(self.request).domain\n        send_activation_email(user, domain)\n\n    def _login(self, user):\n        login(self.request, user)\n\n    def form_valid(self, form):\n        user = self._create_user(form)\n\n        self._send_email(user)\n        self._login(user)\n\n        return super(RegisterView, self).form_valid(form)\n\n\nclass PasswordResetView(auth_views.PasswordResetView):\n    template_name = \"accounts/users/password_reset.html\"\n    email_template_name = \"accounts/users/password_reset_email.html\"\n    subject_template_name = \"accounts/users/password_reset_subject.txt\"\n    from_email = settings.EMAIL_HOST_USER\n    success_url = reverse_lazy(\"accounts_password_reset_done\")\n\n\nclass PasswordResetDoneView(auth_views.PasswordResetDoneView):\n    template_name = \"accounts/users/password_reset_done.html\"\n\n\nclass PasswordResetConfirmView(auth_views.PasswordResetConfirmView):\n    template_name = \"accounts/users/password_reset_confirm.html\"\n    success_url = reverse_lazy(\"accounts_password_reset_complete\")\n\n\nclass PasswordResetCompleteView(auth_views.PasswordResetCompleteView):\n    template_name = \"accounts/users/password_reset_complete.html\"\n\n\nclass SettingsView(LoginRequiredMixin, UpdateView):\n    \"\"\"A form view to edit Profile\"\"\"\n\n    login_url = \"accounts_login\"\n    form_class = ProfileEditForm\n    success_url = reverse_lazy(\"accounts_settings\")\n    template_name = \"accounts/update_settings.html\"\n\n    def get_object(self, queryset=None):\n        return Profile.objects.get(user=self.request.user)\n\n    def get_initial(self):\n        profile = Profile.objects.get(user=self.request.user)\n        self.initial.update(\n            {\n                \"username\": profile.user.username,\n                \"email\": profile.user.email,\n                \"first_name\": profile.first_name or None,\n                \"last_name\": profile.last_name or None,\n                \"about_me\": profile.about_me or None,\n            }\n        )\n        return super(SettingsView, self).get_initial()\n\n\nclass ProfileActivationView(View):\n    \"\"\"\n    This shows different views to the user when they are verifying\n    their account based on whether they are already verified or not.\n    \"\"\"\n\n    def get(self, request, uidb64, token):\n\n        try:\n            uid = force_str(urlsafe_base64_decode(uidb64))\n            user = get_user_model().objects.get(pk=uid)\n\n        except (TypeError, ValueError, OverflowError, get_user_model().DoesNotExist):\n            user = None\n\n        if user is not None and account_activation_token.check_token(user, token):\n            profile = user.profile\n            if profile.is_verified:\n                redirect_link = {\"href\": \"/\", \"label\": \"Back to Main\"}\n                template_var = {\n                    \"title\": \"Email Already Verified\",\n                    \"content\": \"You have already verified your email\",\n                    \"link\": redirect_link,\n                }\n            else:\n                profile.is_verified = True\n                profile.save()\n\n                redirect_link = {\"href\": \"/\", \"label\": \"Back to Main\"}\n                template_var = {\n                    \"title\": \"Email Verification Successful\",\n                    \"content\": \"Thank you for verifying your email with CiviWiki\",\n                    \"link\": redirect_link,\n                }\n        else:\n            # invalid link\n            redirect_link = {\"href\": \"/\", \"label\": \"Back to Main\"}\n            template_var = {\n                \"title\": \"Email Verification Error\",\n                \"content\": \"Email could not be verified\",\n                \"link\": redirect_link,\n            }\n\n        return TemplateResponse(request, \"general_message.html\", template_var)\n\n\nclass ProfileSetupView(LoginRequiredMixin, View):\n    \"\"\"A view to make the user profile full_profile\"\"\"\n\n    login_url = \"accounts_login\"\n\n    def get(self, request):\n        profile = Profile.objects.get(user=request.user)\n        if profile.full_profile:\n            return HttpResponseRedirect(\"/\")\n            # start temp rep rendering TODO: REMOVE THIS\n        else:\n            data = {\n                \"username\": request.user.username,\n                \"email\": request.user.email,\n            }\n            return TemplateResponse(request, \"accounts/user-setup.html\", data)\n\n\nclass UserProfileView(LoginRequiredMixin, View):\n    \"\"\"A view that shows profile for authorized users\"\"\"\n\n    @method_decorator(full_profile)\n    def get(self, request, username=None):\n        if not username:\n            return HttpResponseRedirect(f\"/profile/{request.user}\")\n        else:\n            is_owner = username == request.user.username\n            try:\n                user = get_user_model().objects.get(username=username)\n\n            except get_user_model().DoesNotExist:\n                return HttpResponseRedirect(\"/404\")\n\n        form = ProfileEditForm(\n            initial={\n                \"username\": user.username,\n                \"email\": user.email,\n                \"first_name\": user.profile.first_name or None,\n                \"last_name\": user.profile.last_name or None,\n                \"about_me\": user.profile.about_me or None,\n            },\n            readonly=True,\n        )\n        data = {\n            \"username\": user,\n            \"profile_image_form\": UpdateProfileImage,\n            \"form\": form if is_owner else None,\n            \"readonly\": True,\n        }\n        return TemplateResponse(request, \"account.html\", data)\n", "path": "project/accounts/views.py"}]}