We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add "Issues" tab to the user profile view
We recently removed some features from the user Profile view and now want to reimplement them using only Django.

This task will be to add an "Issues" tab to the user profile view. The tab should link to a sub-path of the user profile so it is clear to the viewer that they are viewing Issues related to the user.

## Task
All of these tasks should be done in the `accounts` app.

- [ ] create a Django view called `UserIssues` (in `accounts/views.py`)
- [ ] create a URL definition `profile/<str:username>/issues` that renders the `UserIssues` view ( in `accounts/urls.py`)
- [ ] ensure the `UserIssues` view context contains a list of users that are following the relevant user (given via the `username` in the URL) 
    - note, it should be possible to get the issues via `user.issue_civis`
- [ ] create a template to render the user issues - for now, extending `base.html` so we have consistent branding  (in `accounts/templates/accounts/user_civis.html`) 
    - unless the `profile_base.html` is available, in which case use that instead


--- 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/views.py`
Content:
```
1 """
2 Class based views.
3 
4 This module will include views for the accounts app.
5 """
6 
7 from accounts.authentication import account_activation_token, send_activation_email
8 from accounts.forms import ProfileEditForm, UserRegistrationForm
9 from accounts.models import Profile
10 from django.conf import settings
11 from django.contrib.auth import get_user_model, login
12 from django.contrib.auth import views as auth_views
13 from django.contrib.auth.decorators import login_required
14 from django.contrib.auth.mixins import LoginRequiredMixin
15 from django.contrib.sites.shortcuts import get_current_site
16 from django.http import HttpResponseRedirect
17 from django.shortcuts import get_object_or_404, redirect
18 from django.template.response import TemplateResponse
19 from django.urls import reverse, reverse_lazy
20 from django.utils.encoding import force_str
21 from django.utils.http import urlsafe_base64_decode
22 from django.views import View
23 from django.views.generic.edit import FormView, UpdateView
24 
25 
26 class ProfileFollow(LoginRequiredMixin, View):
27     def get(self, request, *args, **kwargs):
28         # Prevent users from following themselves.
29         if request.user.username == kwargs["username"]:
30             pass
31         else:
32             following_profile = Profile.objects.get(user__username=kwargs["username"])
33 
34             self.request.user.profile.following.add(following_profile)
35 
36         redirect_to = reverse("profile", kwargs={"username": kwargs["username"]})
37 
38         return HttpResponseRedirect(redirect_to)
39 
40 
41 class ProfileUnfollow(LoginRequiredMixin, View):
42     def get(self, request, *args, **kwargs):
43         # Prevent users from following themselves.
44         if request.user.username == kwargs["username"]:
45             pass
46         else:
47             following_profile = Profile.objects.get(user__username=kwargs["username"])
48 
49             self.request.user.profile.following.remove(following_profile)
50 
51         redirect_to = reverse("profile", kwargs={"username": kwargs["username"]})
52 
53         return HttpResponseRedirect(redirect_to)
54 
55 
56 class RegisterView(FormView):
57     """
58     A form view that handles user registration.
59     """
60 
61     template_name = "accounts/register/register.html"
62     form_class = UserRegistrationForm
63     success_url = "/"
64 
65     def _create_user(self, form):
66         username = form.cleaned_data["username"]
67         password = form.cleaned_data["password"]
68         email = form.cleaned_data["email"]
69         user = get_user_model().objects.create_user(username, email, password)
70         return user
71 
72     def _send_email(self, user):
73         domain = get_current_site(self.request).domain
74         send_activation_email(user, domain)
75 
76     def _login(self, user):
77         login(self.request, user)
78 
79     def form_valid(self, form):
80         user = self._create_user(form)
81 
82         self._send_email(user)
83         self._login(user)
84 
85         return super(RegisterView, self).form_valid(form)
86 
87 
88 class ProfileActivationView(View):
89     """
90     This shows different views to the user when they are verifying
91     their account based on whether they are already verified or not.
92     """
93 
94     def get(self, request, uidb64, token):
95 
96         try:
97             uid = force_str(urlsafe_base64_decode(uidb64))
98             user = get_user_model().objects.get(pk=uid)
99 
100         except (TypeError, ValueError, OverflowError, get_user_model().DoesNotExist):
101             user = None
102 
103         redirect_link = {"href": "/", "label": "Back to Main"}
104 
105         template_var = {
106             "link": redirect_link,
107         }
108 
109         if user is not None and account_activation_token.check_token(user, token):
110             profile = user.profile
111 
112             if profile.is_verified:
113                 template_var["title"] = "Email Already Verified"
114                 template_var["content"] = "You have already verified your email."
115             else:
116                 profile.is_verified = True
117                 profile.save()
118 
119                 template_var["title"] = "Email Verification Successful"
120                 template_var["content"] = "Thank you for verifying your email."
121         else:
122             # invalid link
123             template_var["title"] = "Email Verification Error"
124             template_var["content"] = "Email could not be verified"
125 
126         return TemplateResponse(request, "general_message.html", template_var)
127 
128 
129 class PasswordResetView(auth_views.PasswordResetView):
130     template_name = "accounts/users/password_reset.html"
131     email_template_name = "accounts/users/password_reset_email.html"
132     subject_template_name = "accounts/users/password_reset_subject.txt"
133     from_email = settings.EMAIL_HOST_USER
134     success_url = reverse_lazy("accounts_password_reset_done")
135 
136 
137 class PasswordResetDoneView(auth_views.PasswordResetDoneView):
138     template_name = "accounts/users/password_reset_done.html"
139 
140 
141 class PasswordResetConfirmView(auth_views.PasswordResetConfirmView):
142     template_name = "accounts/users/password_reset_confirm.html"
143     success_url = reverse_lazy("accounts_password_reset_complete")
144 
145 
146 class PasswordResetCompleteView(auth_views.PasswordResetCompleteView):
147     template_name = "accounts/users/password_reset_complete.html"
148 
149 
150 class SettingsView(LoginRequiredMixin, UpdateView):
151     """A form view to edit Profile"""
152 
153     login_url = "accounts_login"
154     form_class = ProfileEditForm
155     success_url = reverse_lazy("accounts_settings")
156     template_name = "accounts/settings.html"
157 
158     def get_object(self, queryset=None):
159         return Profile.objects.get(user=self.request.user)
160 
161     def get_initial(self):
162         profile = Profile.objects.get(user=self.request.user)
163         self.initial.update(
164             {
165                 "username": profile.user.username,
166                 "email": profile.user.email,
167                 "first_name": profile.first_name or None,
168                 "last_name": profile.last_name or None,
169                 "about_me": profile.about_me or None,
170                 "profile_image": profile.profile_image or None,
171             }
172         )
173         return super(SettingsView, self).get_initial()
174 
175 
176 class UserProfileView(LoginRequiredMixin, View):
177     """A view that shows profile for authorized users"""
178 
179     def get(self, request, username=None):
180         profile = get_object_or_404(Profile, user__username=username)
181 
182         return TemplateResponse(
183             request,
184             "account.html",
185             {
186                 "profile": profile,
187             },
188         )
189 
190 
191 
192 class UserFollowers(LoginRequiredMixin, View):
193     """A view that shows the followers for authorized users"""
194     
195     def get(self, request, username=None):
196         profile = get_object_or_404(Profile, user__username=username)
197 
198         return TemplateResponse(
199             request,
200             "user_followers.html",
201             {
202                 "profile": profile,
203             },
204         )
205 
206 
207 class ProfileFollowing(LoginRequiredMixin, View):
208     """
209     A view that shows list of profiles
210     that profile with given username is following
211     """
212 
213     def get(self, request, username=None):
214         profile = get_object_or_404(Profile, user__username=username)
215 
216         return TemplateResponse(
217             request,
218 
219             "profile_following.html",
220 
221             {
222                 "profile": profile,
223             },
224         )
225 
226 
227 
228 class UserCivis(LoginRequiredMixin, View):
229     """
230     A view that shows list of civis
231     that profile with given username created
232     """
233 
234     def get(self, request, username=None):
235         profile = get_object_or_404(Profile, user__username=username)
236         user = profile.user
237         civis = user.civis.all()
238 
239         return TemplateResponse(
240             request,
241             "user_civis.html",
242             {"profile": profile, "civis": civis},
243         )
244 
245 
246 
247 @login_required
248 def expunge_user(request):
249     """
250     Delete User Information
251     """
252 
253     user_model = get_user_model()
254     user = get_object_or_404(user_model, username=request.user.username)
255 
256     profile = get_object_or_404(Profile, user=user)
257 
258     # Expunge personally identifiable data in user
259     expunged_user_data = {
260         "is_active": False,
261         "email": "",
262         "first_name": "",
263         "last_name": "",
264         "username": f"expunged-{ user.id }",
265     }
266     user.__dict__.update(expunged_user_data)
267     user.save()
268 
269     # Expunge personally identifiable data in profile
270     expunged_profile_data = {
271         "first_name": "",
272         "last_name": "",
273         "about_me": "",
274     }
275     profile.__dict__.update(expunged_profile_data)
276     profile.save()
277 
278     return redirect("/")
279
```

Path: `project/accounts/urls.py`
Content:
```
1 from accounts.views import (
2     PasswordResetCompleteView,
3     PasswordResetConfirmView,
4     PasswordResetDoneView,
5     PasswordResetView,
6     ProfileActivationView,
7     ProfileFollow,
8     ProfileUnfollow,
9     RegisterView,
10     SettingsView,
11     UserFollowers,
12     ProfileFollowing,
13     UserProfileView,
14     UserCivis,
15     expunge_user,
16 )
17 from django.contrib.auth import views as auth_views
18 from django.urls import path
19 
20 urlpatterns = [
21     path(
22         "login/",
23         auth_views.LoginView.as_view(template_name="accounts/register/login.html"),
24         name="accounts_login",
25     ),
26     path("logout/", auth_views.LogoutView.as_view(), name="accounts_logout"),
27     path("register/", RegisterView.as_view(), name="accounts_register"),
28     path("settings/", SettingsView.as_view(), name="accounts_settings"),
29     path(
30         "activate_account/<uidb64>/<token>/",
31         ProfileActivationView.as_view(),
32         name="accounts_activate",
33     ),
34     path("profile/<str:username>/", UserProfileView.as_view(), name="profile"),
35     path(
36         "profile/<str:username>/follow", ProfileFollow.as_view(), name="profile-follow"
37     ),
38     path(
39         "profile/<str:username>/followers",
40         UserFollowers.as_view(),
41         name="user-followers",
42     ),
43     path(
44         "profile/<str:username>/unfollow",
45         ProfileUnfollow.as_view(),
46         name="profile-unfollow",
47     ),
48     path(
49         "profile/<str:username>/following",
50         ProfileFollowing.as_view(),
51         name="profile-following",
52     ),
53     path(
54         "profile/<str:username>/civis/",
55         UserCivis.as_view(),
56         name="user-civis",
57     ),
58     path(
59         "accounts/password_reset/",
60         PasswordResetView.as_view(),
61         name="accounts_password_reset",
62     ),
63     path(
64         "accounts/password_reset_done/",
65         PasswordResetDoneView.as_view(),
66         name="accounts_password_reset_done",
67     ),
68     path(
69         "accounts/password_reset_confirm/<uidb64>/<token>/",
70         PasswordResetConfirmView.as_view(),
71         name="accounts_password_reset_confirm",
72     ),
73     path(
74         "accounts/password_reset_complete/",
75         PasswordResetCompleteView.as_view(),
76         name="accounts_password_reset_complete",
77     ),
78     path("accounts/expunge/", expunge_user, name="expunge_user"),
79 ]
80
```
--- 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.py b/project/accounts/urls.py
--- a/project/accounts/urls.py
+++ b/project/accounts/urls.py
@@ -5,13 +5,14 @@
     PasswordResetView,
     ProfileActivationView,
     ProfileFollow,
+    ProfileFollowing,
     ProfileUnfollow,
     RegisterView,
     SettingsView,
+    UserCivis,
     UserFollowers,
-    ProfileFollowing,
+    UserIssues,
     UserProfileView,
-    UserCivis,
     expunge_user,
 )
 from django.contrib.auth import views as auth_views
@@ -55,6 +56,11 @@
         UserCivis.as_view(),
         name="user-civis",
     ),
+    path(
+        "profile/<str:username>/issues/",
+        UserIssues.as_view(),
+        name="user-issues",
+    ),
     path(
         "accounts/password_reset/",
         PasswordResetView.as_view(),
diff --git a/project/accounts/views.py b/project/accounts/views.py
--- a/project/accounts/views.py
+++ b/project/accounts/views.py
@@ -188,10 +188,9 @@
         )
 
 
-
 class UserFollowers(LoginRequiredMixin, View):
     """A view that shows the followers for authorized users"""
-    
+
     def get(self, request, username=None):
         profile = get_object_or_404(Profile, user__username=username)
 
@@ -215,16 +214,13 @@
 
         return TemplateResponse(
             request,
-
             "profile_following.html",
-
             {
                 "profile": profile,
             },
         )
 
 
-
 class UserCivis(LoginRequiredMixin, View):
     """
     A view that shows list of civis
@@ -243,7 +239,6 @@
         )
 
 
-
 @login_required
 def expunge_user(request):
     """
@@ -276,3 +271,17 @@
     profile.save()
 
     return redirect("/")
+
+
+class UserIssues(LoginRequiredMixin, View):
+    def get(self, request, username=None):
+        profile = get_object_or_404(Profile, user__username=username)
+        user = profile.user
+        civis = user.civis.all()
+        followers = profile.followers.all()
+
+        return TemplateResponse(
+            request,
+            "user_civis.html",
+            {"profile": profile, "followers": followers, "civis": civis},
+        )

{"golden_diff": "diff --git a/project/accounts/urls.py b/project/accounts/urls.py\n--- a/project/accounts/urls.py\n+++ b/project/accounts/urls.py\n@@ -5,13 +5,14 @@\n     PasswordResetView,\n     ProfileActivationView,\n     ProfileFollow,\n+    ProfileFollowing,\n     ProfileUnfollow,\n     RegisterView,\n     SettingsView,\n+    UserCivis,\n     UserFollowers,\n-    ProfileFollowing,\n+    UserIssues,\n     UserProfileView,\n-    UserCivis,\n     expunge_user,\n )\n from django.contrib.auth import views as auth_views\n@@ -55,6 +56,11 @@\n         UserCivis.as_view(),\n         name=\"user-civis\",\n     ),\n+    path(\n+        \"profile/<str:username>/issues/\",\n+        UserIssues.as_view(),\n+        name=\"user-issues\",\n+    ),\n     path(\n         \"accounts/password_reset/\",\n         PasswordResetView.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@@ -188,10 +188,9 @@\n         )\n \n \n-\n class UserFollowers(LoginRequiredMixin, View):\n     \"\"\"A view that shows the followers for authorized users\"\"\"\n-    \n+\n     def get(self, request, username=None):\n         profile = get_object_or_404(Profile, user__username=username)\n \n@@ -215,16 +214,13 @@\n \n         return TemplateResponse(\n             request,\n-\n             \"profile_following.html\",\n-\n             {\n                 \"profile\": profile,\n             },\n         )\n \n \n-\n class UserCivis(LoginRequiredMixin, View):\n     \"\"\"\n     A view that shows list of civis\n@@ -243,7 +239,6 @@\n         )\n \n \n-\n @login_required\n def expunge_user(request):\n     \"\"\"\n@@ -276,3 +271,17 @@\n     profile.save()\n \n     return redirect(\"/\")\n+\n+\n+class UserIssues(LoginRequiredMixin, View):\n+    def get(self, request, username=None):\n+        profile = get_object_or_404(Profile, user__username=username)\n+        user = profile.user\n+        civis = user.civis.all()\n+        followers = profile.followers.all()\n+\n+        return TemplateResponse(\n+            request,\n+            \"user_civis.html\",\n+            {\"profile\": profile, \"followers\": followers, \"civis\": civis},\n+        )\n", "issue": "Add \"Issues\" tab to the user profile view\nWe recently removed some features from the user Profile view and now want to reimplement them using only Django.\r\n\r\nThis task will be to add an \"Issues\" tab to the user profile view. The tab should link to a sub-path of the user profile so it is clear to the viewer that they are viewing Issues related to the user.\r\n\r\n## Task\r\nAll of these tasks should be done in the `accounts` app.\r\n\r\n- [ ] create a Django view called `UserIssues` (in `accounts/views.py`)\r\n- [ ] create a URL definition `profile/<str:username>/issues` that renders the `UserIssues` view ( in `accounts/urls.py`)\r\n- [ ] ensure the `UserIssues` view context contains a list of users that are following the relevant user (given via the `username` in the URL) \r\n    - note, it should be possible to get the issues via `user.issue_civis`\r\n- [ ] create a template to render the user issues - for now, extending `base.html` so we have consistent branding  (in `accounts/templates/accounts/user_civis.html`) \r\n    - unless the `profile_base.html` is available, in which case use that instead\r\n\n", "before_files": [{"content": "\"\"\"\nClass based views.\n\nThis module will include views for the accounts app.\n\"\"\"\n\nfrom accounts.authentication import account_activation_token, send_activation_email\nfrom accounts.forms import ProfileEditForm, UserRegistrationForm\nfrom accounts.models import 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.decorators import login_required\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.contrib.sites.shortcuts import get_current_site\nfrom django.http import HttpResponseRedirect\nfrom django.shortcuts import get_object_or_404, redirect\nfrom django.template.response import TemplateResponse\nfrom django.urls import reverse, 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\n\nclass ProfileFollow(LoginRequiredMixin, View):\n    def get(self, request, *args, **kwargs):\n        # Prevent users from following themselves.\n        if request.user.username == kwargs[\"username\"]:\n            pass\n        else:\n            following_profile = Profile.objects.get(user__username=kwargs[\"username\"])\n\n            self.request.user.profile.following.add(following_profile)\n\n        redirect_to = reverse(\"profile\", kwargs={\"username\": kwargs[\"username\"]})\n\n        return HttpResponseRedirect(redirect_to)\n\n\nclass ProfileUnfollow(LoginRequiredMixin, View):\n    def get(self, request, *args, **kwargs):\n        # Prevent users from following themselves.\n        if request.user.username == kwargs[\"username\"]:\n            pass\n        else:\n            following_profile = Profile.objects.get(user__username=kwargs[\"username\"])\n\n            self.request.user.profile.following.remove(following_profile)\n\n        redirect_to = reverse(\"profile\", kwargs={\"username\": kwargs[\"username\"]})\n\n        return HttpResponseRedirect(redirect_to)\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 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        redirect_link = {\"href\": \"/\", \"label\": \"Back to Main\"}\n\n        template_var = {\n            \"link\": redirect_link,\n        }\n\n        if user is not None and account_activation_token.check_token(user, token):\n            profile = user.profile\n\n            if profile.is_verified:\n                template_var[\"title\"] = \"Email Already Verified\"\n                template_var[\"content\"] = \"You have already verified your email.\"\n            else:\n                profile.is_verified = True\n                profile.save()\n\n                template_var[\"title\"] = \"Email Verification Successful\"\n                template_var[\"content\"] = \"Thank you for verifying your email.\"\n        else:\n            # invalid link\n            template_var[\"title\"] = \"Email Verification Error\"\n            template_var[\"content\"] = \"Email could not be verified\"\n\n        return TemplateResponse(request, \"general_message.html\", template_var)\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/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                \"profile_image\": profile.profile_image or None,\n            }\n        )\n        return super(SettingsView, self).get_initial()\n\n\nclass UserProfileView(LoginRequiredMixin, View):\n    \"\"\"A view that shows profile for authorized users\"\"\"\n\n    def get(self, request, username=None):\n        profile = get_object_or_404(Profile, user__username=username)\n\n        return TemplateResponse(\n            request,\n            \"account.html\",\n            {\n                \"profile\": profile,\n            },\n        )\n\n\n\nclass UserFollowers(LoginRequiredMixin, View):\n    \"\"\"A view that shows the followers for authorized users\"\"\"\n    \n    def get(self, request, username=None):\n        profile = get_object_or_404(Profile, user__username=username)\n\n        return TemplateResponse(\n            request,\n            \"user_followers.html\",\n            {\n                \"profile\": profile,\n            },\n        )\n\n\nclass ProfileFollowing(LoginRequiredMixin, View):\n    \"\"\"\n    A view that shows list of profiles\n    that profile with given username is following\n    \"\"\"\n\n    def get(self, request, username=None):\n        profile = get_object_or_404(Profile, user__username=username)\n\n        return TemplateResponse(\n            request,\n\n            \"profile_following.html\",\n\n            {\n                \"profile\": profile,\n            },\n        )\n\n\n\nclass UserCivis(LoginRequiredMixin, View):\n    \"\"\"\n    A view that shows list of civis\n    that profile with given username created\n    \"\"\"\n\n    def get(self, request, username=None):\n        profile = get_object_or_404(Profile, user__username=username)\n        user = profile.user\n        civis = user.civis.all()\n\n        return TemplateResponse(\n            request,\n            \"user_civis.html\",\n            {\"profile\": profile, \"civis\": civis},\n        )\n\n\n\n@login_required\ndef expunge_user(request):\n    \"\"\"\n    Delete User Information\n    \"\"\"\n\n    user_model = get_user_model()\n    user = get_object_or_404(user_model, username=request.user.username)\n\n    profile = get_object_or_404(Profile, user=user)\n\n    # Expunge personally identifiable data in user\n    expunged_user_data = {\n        \"is_active\": False,\n        \"email\": \"\",\n        \"first_name\": \"\",\n        \"last_name\": \"\",\n        \"username\": f\"expunged-{ user.id }\",\n    }\n    user.__dict__.update(expunged_user_data)\n    user.save()\n\n    # Expunge personally identifiable data in profile\n    expunged_profile_data = {\n        \"first_name\": \"\",\n        \"last_name\": \"\",\n        \"about_me\": \"\",\n    }\n    profile.__dict__.update(expunged_profile_data)\n    profile.save()\n\n    return redirect(\"/\")\n", "path": "project/accounts/views.py"}, {"content": "from accounts.views import (\n    PasswordResetCompleteView,\n    PasswordResetConfirmView,\n    PasswordResetDoneView,\n    PasswordResetView,\n    ProfileActivationView,\n    ProfileFollow,\n    ProfileUnfollow,\n    RegisterView,\n    SettingsView,\n    UserFollowers,\n    ProfileFollowing,\n    UserProfileView,\n    UserCivis,\n    expunge_user,\n)\nfrom django.contrib.auth import views as auth_views\nfrom django.urls import path\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(\n        \"activate_account/<uidb64>/<token>/\",\n        ProfileActivationView.as_view(),\n        name=\"accounts_activate\",\n    ),\n    path(\"profile/<str:username>/\", UserProfileView.as_view(), name=\"profile\"),\n    path(\n        \"profile/<str:username>/follow\", ProfileFollow.as_view(), name=\"profile-follow\"\n    ),\n    path(\n        \"profile/<str:username>/followers\",\n        UserFollowers.as_view(),\n        name=\"user-followers\",\n    ),\n    path(\n        \"profile/<str:username>/unfollow\",\n        ProfileUnfollow.as_view(),\n        name=\"profile-unfollow\",\n    ),\n    path(\n        \"profile/<str:username>/following\",\n        ProfileFollowing.as_view(),\n        name=\"profile-following\",\n    ),\n    path(\n        \"profile/<str:username>/civis/\",\n        UserCivis.as_view(),\n        name=\"user-civis\",\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    path(\"accounts/expunge/\", expunge_user, name=\"expunge_user\"),\n]\n", "path": "project/accounts/urls.py"}], "after_files": [{"content": "\"\"\"\nClass based views.\n\nThis module will include views for the accounts app.\n\"\"\"\n\nfrom accounts.authentication import account_activation_token, send_activation_email\nfrom accounts.forms import ProfileEditForm, UserRegistrationForm\nfrom accounts.models import 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.decorators import login_required\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.contrib.sites.shortcuts import get_current_site\nfrom django.http import HttpResponseRedirect\nfrom django.shortcuts import get_object_or_404, redirect\nfrom django.template.response import TemplateResponse\nfrom django.urls import reverse, 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\n\nclass ProfileFollow(LoginRequiredMixin, View):\n    def get(self, request, *args, **kwargs):\n        # Prevent users from following themselves.\n        if request.user.username == kwargs[\"username\"]:\n            pass\n        else:\n            following_profile = Profile.objects.get(user__username=kwargs[\"username\"])\n\n            self.request.user.profile.following.add(following_profile)\n\n        redirect_to = reverse(\"profile\", kwargs={\"username\": kwargs[\"username\"]})\n\n        return HttpResponseRedirect(redirect_to)\n\n\nclass ProfileUnfollow(LoginRequiredMixin, View):\n    def get(self, request, *args, **kwargs):\n        # Prevent users from following themselves.\n        if request.user.username == kwargs[\"username\"]:\n            pass\n        else:\n            following_profile = Profile.objects.get(user__username=kwargs[\"username\"])\n\n            self.request.user.profile.following.remove(following_profile)\n\n        redirect_to = reverse(\"profile\", kwargs={\"username\": kwargs[\"username\"]})\n\n        return HttpResponseRedirect(redirect_to)\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 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        redirect_link = {\"href\": \"/\", \"label\": \"Back to Main\"}\n\n        template_var = {\n            \"link\": redirect_link,\n        }\n\n        if user is not None and account_activation_token.check_token(user, token):\n            profile = user.profile\n\n            if profile.is_verified:\n                template_var[\"title\"] = \"Email Already Verified\"\n                template_var[\"content\"] = \"You have already verified your email.\"\n            else:\n                profile.is_verified = True\n                profile.save()\n\n                template_var[\"title\"] = \"Email Verification Successful\"\n                template_var[\"content\"] = \"Thank you for verifying your email.\"\n        else:\n            # invalid link\n            template_var[\"title\"] = \"Email Verification Error\"\n            template_var[\"content\"] = \"Email could not be verified\"\n\n        return TemplateResponse(request, \"general_message.html\", template_var)\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/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                \"profile_image\": profile.profile_image or None,\n            }\n        )\n        return super(SettingsView, self).get_initial()\n\n\nclass UserProfileView(LoginRequiredMixin, View):\n    \"\"\"A view that shows profile for authorized users\"\"\"\n\n    def get(self, request, username=None):\n        profile = get_object_or_404(Profile, user__username=username)\n\n        return TemplateResponse(\n            request,\n            \"account.html\",\n            {\n                \"profile\": profile,\n            },\n        )\n\n\nclass UserFollowers(LoginRequiredMixin, View):\n    \"\"\"A view that shows the followers for authorized users\"\"\"\n\n    def get(self, request, username=None):\n        profile = get_object_or_404(Profile, user__username=username)\n\n        return TemplateResponse(\n            request,\n            \"user_followers.html\",\n            {\n                \"profile\": profile,\n            },\n        )\n\n\nclass ProfileFollowing(LoginRequiredMixin, View):\n    \"\"\"\n    A view that shows list of profiles\n    that profile with given username is following\n    \"\"\"\n\n    def get(self, request, username=None):\n        profile = get_object_or_404(Profile, user__username=username)\n\n        return TemplateResponse(\n            request,\n            \"profile_following.html\",\n            {\n                \"profile\": profile,\n            },\n        )\n\n\nclass UserCivis(LoginRequiredMixin, View):\n    \"\"\"\n    A view that shows list of civis\n    that profile with given username created\n    \"\"\"\n\n    def get(self, request, username=None):\n        profile = get_object_or_404(Profile, user__username=username)\n        user = profile.user\n        civis = user.civis.all()\n\n        return TemplateResponse(\n            request,\n            \"user_civis.html\",\n            {\"profile\": profile, \"civis\": civis},\n        )\n\n\n@login_required\ndef expunge_user(request):\n    \"\"\"\n    Delete User Information\n    \"\"\"\n\n    user_model = get_user_model()\n    user = get_object_or_404(user_model, username=request.user.username)\n\n    profile = get_object_or_404(Profile, user=user)\n\n    # Expunge personally identifiable data in user\n    expunged_user_data = {\n        \"is_active\": False,\n        \"email\": \"\",\n        \"first_name\": \"\",\n        \"last_name\": \"\",\n        \"username\": f\"expunged-{ user.id }\",\n    }\n    user.__dict__.update(expunged_user_data)\n    user.save()\n\n    # Expunge personally identifiable data in profile\n    expunged_profile_data = {\n        \"first_name\": \"\",\n        \"last_name\": \"\",\n        \"about_me\": \"\",\n    }\n    profile.__dict__.update(expunged_profile_data)\n    profile.save()\n\n    return redirect(\"/\")\n\n\nclass UserIssues(LoginRequiredMixin, View):\n    def get(self, request, username=None):\n        profile = get_object_or_404(Profile, user__username=username)\n        user = profile.user\n        civis = user.civis.all()\n        followers = profile.followers.all()\n\n        return TemplateResponse(\n            request,\n            \"user_civis.html\",\n            {\"profile\": profile, \"followers\": followers, \"civis\": civis},\n        )\n", "path": "project/accounts/views.py"}, {"content": "from accounts.views import (\n    PasswordResetCompleteView,\n    PasswordResetConfirmView,\n    PasswordResetDoneView,\n    PasswordResetView,\n    ProfileActivationView,\n    ProfileFollow,\n    ProfileFollowing,\n    ProfileUnfollow,\n    RegisterView,\n    SettingsView,\n    UserCivis,\n    UserFollowers,\n    UserIssues,\n    UserProfileView,\n    expunge_user,\n)\nfrom django.contrib.auth import views as auth_views\nfrom django.urls import path\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(\n        \"activate_account/<uidb64>/<token>/\",\n        ProfileActivationView.as_view(),\n        name=\"accounts_activate\",\n    ),\n    path(\"profile/<str:username>/\", UserProfileView.as_view(), name=\"profile\"),\n    path(\n        \"profile/<str:username>/follow\", ProfileFollow.as_view(), name=\"profile-follow\"\n    ),\n    path(\n        \"profile/<str:username>/followers\",\n        UserFollowers.as_view(),\n        name=\"user-followers\",\n    ),\n    path(\n        \"profile/<str:username>/unfollow\",\n        ProfileUnfollow.as_view(),\n        name=\"profile-unfollow\",\n    ),\n    path(\n        \"profile/<str:username>/following\",\n        ProfileFollowing.as_view(),\n        name=\"profile-following\",\n    ),\n    path(\n        \"profile/<str:username>/civis/\",\n        UserCivis.as_view(),\n        name=\"user-civis\",\n    ),\n    path(\n        \"profile/<str:username>/issues/\",\n        UserIssues.as_view(),\n        name=\"user-issues\",\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    path(\"accounts/expunge/\", expunge_user, name=\"expunge_user\"),\n]\n", "path": "project/accounts/urls.py"}]}