prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Benutzer bearbeiten
  Als Manager möchte ich einen Nutzer bearbeiten. Dabei möchte ich die selben Optionen haben wie beim Anlegen des Nutzers. In der Liste der Nutzer soll es für jeden Nutzer eine entsprechende Schaltfläche geben. Der Nutzer soll über Änderungen per Mail informiert werden.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `user_management/mail.py`
  Content:
  ```
  1 from django.contrib.auth.tokens import default_token_generator
  2 from django.core import mail
  3 from django.core.mail import EmailMultiAlternatives
  4 from django.template.loader import render_to_string
  5 from django.urls import reverse
  6 from django.utils.encoding import force_bytes
  7 from django.utils.http import urlsafe_base64_encode
  8 from django.utils.translation import gettext as _
  9 
  10 from jep.settings import SITE_URL
  11 
  12 
  13 def send_account_creation_info(userprofile):
  14     messages = []
  15     subject = _("Welcome to JEP!")
  16     uid = urlsafe_base64_encode(force_bytes(userprofile.id))
  17     token = default_token_generator.make_token(userprofile)
  18     reset_link = reverse("password_reset_confirm", kwargs={"uidb64": uid, "token": token})
  19     text_content = _(
  20         "You're receiving this email because a new account has been created for you at JEP.\n"
  21         "Please go to the following page and choose a password: {url}{reset_link}\n"
  22         "Your username is your email address: {email}\n"
  23     ).format(url=SITE_URL, reset_link=reset_link, email=userprofile.email)
  24 
  25     html_content = render_to_string(
  26         "user_management/new_account_email.html",
  27         {"uid": uid, "token": token, "site_url": SITE_URL, "email": userprofile.email,},
  28     )
  29     message = EmailMultiAlternatives(to=[userprofile.email], subject=subject, body=text_content)
  30     message.attach_alternative(html_content, "text/html")
  31     messages.append(message)
  32 
  33     mail.get_connection().send_messages(messages)
  34
  ```
  
  Path: `user_management/urls.py`
  Content:
  ```
  1 from django.urls import path
  2 
  3 from user_management import views
  4 
  5 app_name = "user_management"
  6 urlpatterns = [
  7     path("profile/", views.ProfileView.as_view(), name="profile"),
  8     path("groups/", views.GroupListView.as_view(), name="group_list"),
  9     path("groups/<int:pk>/edit", views.GroupUpdateView.as_view(), name="group_edit"),
  10     path("groups/<int:pk>/delete", views.GroupDeleteView.as_view(), name="group_delete"),
  11     path("groups/create", views.GroupCreateView.as_view(), name="group_add"),
  12     path("users/", views.UserProfileListView.as_view(), name="user_list",),
  13     path("users/create/", views.UserProfileCreateView.as_view(), name="userprofile_create",),
  14 ]
  15
  ```
  
  Path: `user_management/views.py`
  Content:
  ```
  1 from django.contrib import messages
  2 from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
  3 from django.contrib.auth.models import Group
  4 from django.urls import reverse
  5 from django.views.generic import DetailView, ListView, UpdateView, CreateView, DeleteView
  6 from guardian.shortcuts import get_objects_for_group
  7 
  8 from user_management import mail
  9 from user_management.forms import GroupForm, UserProfileForm
  10 from django.utils.translation import gettext as _
  11 
  12 from user_management.models import UserProfile
  13 
  14 
  15 class ProfileView(LoginRequiredMixin, DetailView):
  16     def get_object(self, queryset=None):
  17         return self.request.user
  18 
  19 
  20 class UserProfileListView(PermissionRequiredMixin, ListView):
  21     model = UserProfile
  22     permission_required = "user_management.view_userprofile"
  23 
  24 
  25 class UserProfileCreateView(PermissionRequiredMixin, CreateView):
  26     template_name = "user_management/userprofile_form.html"
  27     permission_required = "user_management.add_userprofile"
  28     model = UserProfile
  29     form_class = UserProfileForm
  30 
  31     def get_success_url(self):
  32         messages.success(self.request, _("User added successfully."))
  33         return reverse("user_management:user_list")
  34 
  35     def form_valid(self, form):
  36         response = super().form_valid(form)
  37         userprofile = self.object
  38         if userprofile.is_active:
  39             mail.send_account_creation_info(userprofile)
  40         return response
  41 
  42 
  43 class GroupListView(PermissionRequiredMixin, ListView):
  44     model = Group
  45     permission_required = "auth.view_group"
  46     template_name = "user_management/group_list.html"
  47 
  48 
  49 class GroupCreateView(PermissionRequiredMixin, CreateView):
  50     model = Group
  51     permission_required = "auth.add_group"
  52     template_name = "user_management/group_form.html"
  53     form_class = GroupForm
  54 
  55     def get_form_kwargs(self):
  56         kwargs = super().get_form_kwargs()
  57         kwargs["initial"] = {
  58             "users": UserProfile.objects.none(),
  59             "can_add_event": False,
  60             "publish_event_for_group": Group.objects.none(),
  61         }
  62         return kwargs
  63 
  64     def get_success_url(self):
  65         messages.success(self.request, _("Group created successfully."))
  66         return reverse("user_management:group_list")
  67 
  68 
  69 class GroupUpdateView(PermissionRequiredMixin, UpdateView):
  70     model = Group
  71     permission_required = "auth.change_group"
  72     template_name = "user_management/group_form.html"
  73     form_class = GroupForm
  74 
  75     def get_form_kwargs(self):
  76         kwargs = super().get_form_kwargs()
  77         kwargs["initial"] = {
  78             "users": self.object.user_set.all(),
  79             "can_view_past_event": self.object.permissions.filter(
  80                 codename="view_past_event"
  81             ).exists(),
  82             "can_add_event": self.object.permissions.filter(codename="add_event").exists(),
  83             "publish_event_for_group": get_objects_for_group(
  84                 self.object, "publish_event_for_group", klass=Group
  85             ),
  86         }
  87         return kwargs
  88 
  89     def get_success_url(self):
  90         return reverse("user_management:group_list")
  91 
  92 
  93 class GroupDeleteView(PermissionRequiredMixin, DeleteView):
  94     model = Group
  95     permission_required = "auth.delete_group"
  96     template_name = "user_management/group_confirm_delete.html"
  97 
  98     def get_success_url(self):
  99         return reverse("user_management:group_list")
  100
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/user_management/mail.py b/user_management/mail.py
  --- a/user_management/mail.py
  +++ b/user_management/mail.py
  @@ -11,7 +11,6 @@
   
   
   def send_account_creation_info(userprofile):
  -    messages = []
       subject = _("Welcome to JEP!")
       uid = urlsafe_base64_encode(force_bytes(userprofile.id))
       token = default_token_generator.make_token(userprofile)
  @@ -24,10 +23,26 @@
   
       html_content = render_to_string(
           "user_management/new_account_email.html",
  -        {"uid": uid, "token": token, "site_url": SITE_URL, "email": userprofile.email,},
  +        {"uid": uid, "token": token, "site_url": SITE_URL, "email": userprofile.email},
       )
       message = EmailMultiAlternatives(to=[userprofile.email], subject=subject, body=text_content)
       message.attach_alternative(html_content, "text/html")
  -    messages.append(message)
  +    message.send()
   
  -    mail.get_connection().send_messages(messages)
  +
  +def send_account_update_info(userprofile):
  +    subject = _("JEP account updated")
  +    url = reverse("user_management:profile")
  +    text_content = _(
  +        "You're receiving this email because your account at JEP has been updated.\n"
  +        "You can see the changes in your profile: {site_url}{url}\n"
  +        "Your username is your email address: {email}\n"
  +    ).format(site_url=SITE_URL, url=url, email=userprofile.email)
  +
  +    html_content = render_to_string(
  +        "user_management/account_updated_email.html",
  +        {"site_url": SITE_URL, "url": url, "email": userprofile.email},
  +    )
  +    message = EmailMultiAlternatives(to=[userprofile.email], subject=subject, body=text_content)
  +    message.attach_alternative(html_content, "text/html")
  +    message.send()
  diff --git a/user_management/urls.py b/user_management/urls.py
  --- a/user_management/urls.py
  +++ b/user_management/urls.py
  @@ -9,6 +9,7 @@
       path("groups/<int:pk>/edit", views.GroupUpdateView.as_view(), name="group_edit"),
       path("groups/<int:pk>/delete", views.GroupDeleteView.as_view(), name="group_delete"),
       path("groups/create", views.GroupCreateView.as_view(), name="group_add"),
  -    path("users/", views.UserProfileListView.as_view(), name="user_list",),
  +    path("users/", views.UserProfileListView.as_view(), name="userprofile_list",),
  +    path("users/<int:pk>/edit", views.UserProfileUpdateView.as_view(), name="userprofile_edit",),
       path("users/create/", views.UserProfileCreateView.as_view(), name="userprofile_create",),
   ]
  diff --git a/user_management/views.py b/user_management/views.py
  --- a/user_management/views.py
  +++ b/user_management/views.py
  @@ -30,7 +30,7 @@
   
       def get_success_url(self):
           messages.success(self.request, _("User added successfully."))
  -        return reverse("user_management:user_list")
  +        return reverse("user_management:userprofile_list")
   
       def form_valid(self, form):
           response = super().form_valid(form)
  @@ -40,6 +40,31 @@
           return response
   
   
  +class UserProfileUpdateView(PermissionRequiredMixin, UpdateView):
  +    model = UserProfile
  +    permission_required = "user_management.change_userprofile"
  +    template_name = "user_management/userprofile_form.html"
  +    form_class = UserProfileForm
  +
  +    def get_success_url(self):
  +        messages.success(self.request, _("User updated successfully."))
  +        return reverse("user_management:userprofile_list")
  +
  +    def form_valid(self, form):
  +        response = super().form_valid(form)
  +        userprofile = self.object
  +        if userprofile.is_active:
  +            mail.send_account_update_info(userprofile)
  +        return response
  +
  +    def get_form_kwargs(self):
  +        kwargs = super().get_form_kwargs()
  +        kwargs["initial"] = {
  +            "groups": self.object.groups.all(),
  +        }
  +        return kwargs
  +
  +
   class GroupListView(PermissionRequiredMixin, ListView):
       model = Group
       permission_required = "auth.view_group"
  @@ -87,6 +112,7 @@
           return kwargs
   
       def get_success_url(self):
  +        messages.success(self.request, _("Group updated successfully."))
           return reverse("user_management:group_list")
  
verification_info: {"golden_diff": "diff --git a/user_management/mail.py b/user_management/mail.py\n--- a/user_management/mail.py\n+++ b/user_management/mail.py\n@@ -11,7 +11,6 @@\n \n \n def send_account_creation_info(userprofile):\n-    messages = []\n     subject = _(\"Welcome to JEP!\")\n     uid = urlsafe_base64_encode(force_bytes(userprofile.id))\n     token = default_token_generator.make_token(userprofile)\n@@ -24,10 +23,26 @@\n \n     html_content = render_to_string(\n         \"user_management/new_account_email.html\",\n-        {\"uid\": uid, \"token\": token, \"site_url\": SITE_URL, \"email\": userprofile.email,},\n+        {\"uid\": uid, \"token\": token, \"site_url\": SITE_URL, \"email\": userprofile.email},\n     )\n     message = EmailMultiAlternatives(to=[userprofile.email], subject=subject, body=text_content)\n     message.attach_alternative(html_content, \"text/html\")\n-    messages.append(message)\n+    message.send()\n \n-    mail.get_connection().send_messages(messages)\n+\n+def send_account_update_info(userprofile):\n+    subject = _(\"JEP account updated\")\n+    url = reverse(\"user_management:profile\")\n+    text_content = _(\n+        \"You're receiving this email because your account at JEP has been updated.\\n\"\n+        \"You can see the changes in your profile: {site_url}{url}\\n\"\n+        \"Your username is your email address: {email}\\n\"\n+    ).format(site_url=SITE_URL, url=url, email=userprofile.email)\n+\n+    html_content = render_to_string(\n+        \"user_management/account_updated_email.html\",\n+        {\"site_url\": SITE_URL, \"url\": url, \"email\": userprofile.email},\n+    )\n+    message = EmailMultiAlternatives(to=[userprofile.email], subject=subject, body=text_content)\n+    message.attach_alternative(html_content, \"text/html\")\n+    message.send()\ndiff --git a/user_management/urls.py b/user_management/urls.py\n--- a/user_management/urls.py\n+++ b/user_management/urls.py\n@@ -9,6 +9,7 @@\n     path(\"groups/<int:pk>/edit\", views.GroupUpdateView.as_view(), name=\"group_edit\"),\n     path(\"groups/<int:pk>/delete\", views.GroupDeleteView.as_view(), name=\"group_delete\"),\n     path(\"groups/create\", views.GroupCreateView.as_view(), name=\"group_add\"),\n-    path(\"users/\", views.UserProfileListView.as_view(), name=\"user_list\",),\n+    path(\"users/\", views.UserProfileListView.as_view(), name=\"userprofile_list\",),\n+    path(\"users/<int:pk>/edit\", views.UserProfileUpdateView.as_view(), name=\"userprofile_edit\",),\n     path(\"users/create/\", views.UserProfileCreateView.as_view(), name=\"userprofile_create\",),\n ]\ndiff --git a/user_management/views.py b/user_management/views.py\n--- a/user_management/views.py\n+++ b/user_management/views.py\n@@ -30,7 +30,7 @@\n \n     def get_success_url(self):\n         messages.success(self.request, _(\"User added successfully.\"))\n-        return reverse(\"user_management:user_list\")\n+        return reverse(\"user_management:userprofile_list\")\n \n     def form_valid(self, form):\n         response = super().form_valid(form)\n@@ -40,6 +40,31 @@\n         return response\n \n \n+class UserProfileUpdateView(PermissionRequiredMixin, UpdateView):\n+    model = UserProfile\n+    permission_required = \"user_management.change_userprofile\"\n+    template_name = \"user_management/userprofile_form.html\"\n+    form_class = UserProfileForm\n+\n+    def get_success_url(self):\n+        messages.success(self.request, _(\"User updated successfully.\"))\n+        return reverse(\"user_management:userprofile_list\")\n+\n+    def form_valid(self, form):\n+        response = super().form_valid(form)\n+        userprofile = self.object\n+        if userprofile.is_active:\n+            mail.send_account_update_info(userprofile)\n+        return response\n+\n+    def get_form_kwargs(self):\n+        kwargs = super().get_form_kwargs()\n+        kwargs[\"initial\"] = {\n+            \"groups\": self.object.groups.all(),\n+        }\n+        return kwargs\n+\n+\n class GroupListView(PermissionRequiredMixin, ListView):\n     model = Group\n     permission_required = \"auth.view_group\"\n@@ -87,6 +112,7 @@\n         return kwargs\n \n     def get_success_url(self):\n+        messages.success(self.request, _(\"Group updated successfully.\"))\n         return reverse(\"user_management:group_list\")\n", "issue": "Benutzer bearbeiten\nAls Manager m\u00f6chte ich einen Nutzer bearbeiten. Dabei m\u00f6chte ich die selben Optionen haben wie beim Anlegen des Nutzers. In der Liste der Nutzer soll es f\u00fcr jeden Nutzer eine entsprechende Schaltfl\u00e4che geben. Der Nutzer soll \u00fcber \u00c4nderungen per Mail informiert werden.\n", "before_files": [{"content": "from django.contrib.auth.tokens import default_token_generator\nfrom django.core import mail\nfrom django.core.mail import EmailMultiAlternatives\nfrom django.template.loader import render_to_string\nfrom django.urls import reverse\nfrom django.utils.encoding import force_bytes\nfrom django.utils.http import urlsafe_base64_encode\nfrom django.utils.translation import gettext as _\n\nfrom jep.settings import SITE_URL\n\n\ndef send_account_creation_info(userprofile):\n    messages = []\n    subject = _(\"Welcome to JEP!\")\n    uid = urlsafe_base64_encode(force_bytes(userprofile.id))\n    token = default_token_generator.make_token(userprofile)\n    reset_link = reverse(\"password_reset_confirm\", kwargs={\"uidb64\": uid, \"token\": token})\n    text_content = _(\n        \"You're receiving this email because a new account has been created for you at JEP.\\n\"\n        \"Please go to the following page and choose a password: {url}{reset_link}\\n\"\n        \"Your username is your email address: {email}\\n\"\n    ).format(url=SITE_URL, reset_link=reset_link, email=userprofile.email)\n\n    html_content = render_to_string(\n        \"user_management/new_account_email.html\",\n        {\"uid\": uid, \"token\": token, \"site_url\": SITE_URL, \"email\": userprofile.email,},\n    )\n    message = EmailMultiAlternatives(to=[userprofile.email], subject=subject, body=text_content)\n    message.attach_alternative(html_content, \"text/html\")\n    messages.append(message)\n\n    mail.get_connection().send_messages(messages)\n", "path": "user_management/mail.py"}, {"content": "from django.urls import path\n\nfrom user_management import views\n\napp_name = \"user_management\"\nurlpatterns = [\n    path(\"profile/\", views.ProfileView.as_view(), name=\"profile\"),\n    path(\"groups/\", views.GroupListView.as_view(), name=\"group_list\"),\n    path(\"groups/<int:pk>/edit\", views.GroupUpdateView.as_view(), name=\"group_edit\"),\n    path(\"groups/<int:pk>/delete\", views.GroupDeleteView.as_view(), name=\"group_delete\"),\n    path(\"groups/create\", views.GroupCreateView.as_view(), name=\"group_add\"),\n    path(\"users/\", views.UserProfileListView.as_view(), name=\"user_list\",),\n    path(\"users/create/\", views.UserProfileCreateView.as_view(), name=\"userprofile_create\",),\n]\n", "path": "user_management/urls.py"}, {"content": "from django.contrib import messages\nfrom django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin\nfrom django.contrib.auth.models import Group\nfrom django.urls import reverse\nfrom django.views.generic import DetailView, ListView, UpdateView, CreateView, DeleteView\nfrom guardian.shortcuts import get_objects_for_group\n\nfrom user_management import mail\nfrom user_management.forms import GroupForm, UserProfileForm\nfrom django.utils.translation import gettext as _\n\nfrom user_management.models import UserProfile\n\n\nclass ProfileView(LoginRequiredMixin, DetailView):\n    def get_object(self, queryset=None):\n        return self.request.user\n\n\nclass UserProfileListView(PermissionRequiredMixin, ListView):\n    model = UserProfile\n    permission_required = \"user_management.view_userprofile\"\n\n\nclass UserProfileCreateView(PermissionRequiredMixin, CreateView):\n    template_name = \"user_management/userprofile_form.html\"\n    permission_required = \"user_management.add_userprofile\"\n    model = UserProfile\n    form_class = UserProfileForm\n\n    def get_success_url(self):\n        messages.success(self.request, _(\"User added successfully.\"))\n        return reverse(\"user_management:user_list\")\n\n    def form_valid(self, form):\n        response = super().form_valid(form)\n        userprofile = self.object\n        if userprofile.is_active:\n            mail.send_account_creation_info(userprofile)\n        return response\n\n\nclass GroupListView(PermissionRequiredMixin, ListView):\n    model = Group\n    permission_required = \"auth.view_group\"\n    template_name = \"user_management/group_list.html\"\n\n\nclass GroupCreateView(PermissionRequiredMixin, CreateView):\n    model = Group\n    permission_required = \"auth.add_group\"\n    template_name = \"user_management/group_form.html\"\n    form_class = GroupForm\n\n    def get_form_kwargs(self):\n        kwargs = super().get_form_kwargs()\n        kwargs[\"initial\"] = {\n            \"users\": UserProfile.objects.none(),\n            \"can_add_event\": False,\n            \"publish_event_for_group\": Group.objects.none(),\n        }\n        return kwargs\n\n    def get_success_url(self):\n        messages.success(self.request, _(\"Group created successfully.\"))\n        return reverse(\"user_management:group_list\")\n\n\nclass GroupUpdateView(PermissionRequiredMixin, UpdateView):\n    model = Group\n    permission_required = \"auth.change_group\"\n    template_name = \"user_management/group_form.html\"\n    form_class = GroupForm\n\n    def get_form_kwargs(self):\n        kwargs = super().get_form_kwargs()\n        kwargs[\"initial\"] = {\n            \"users\": self.object.user_set.all(),\n            \"can_view_past_event\": self.object.permissions.filter(\n                codename=\"view_past_event\"\n            ).exists(),\n            \"can_add_event\": self.object.permissions.filter(codename=\"add_event\").exists(),\n            \"publish_event_for_group\": get_objects_for_group(\n                self.object, \"publish_event_for_group\", klass=Group\n            ),\n        }\n        return kwargs\n\n    def get_success_url(self):\n        return reverse(\"user_management:group_list\")\n\n\nclass GroupDeleteView(PermissionRequiredMixin, DeleteView):\n    model = Group\n    permission_required = \"auth.delete_group\"\n    template_name = \"user_management/group_confirm_delete.html\"\n\n    def get_success_url(self):\n        return reverse(\"user_management:group_list\")\n", "path": "user_management/views.py"}], "after_files": [{"content": "from django.contrib.auth.tokens import default_token_generator\nfrom django.core import mail\nfrom django.core.mail import EmailMultiAlternatives\nfrom django.template.loader import render_to_string\nfrom django.urls import reverse\nfrom django.utils.encoding import force_bytes\nfrom django.utils.http import urlsafe_base64_encode\nfrom django.utils.translation import gettext as _\n\nfrom jep.settings import SITE_URL\n\n\ndef send_account_creation_info(userprofile):\n    subject = _(\"Welcome to JEP!\")\n    uid = urlsafe_base64_encode(force_bytes(userprofile.id))\n    token = default_token_generator.make_token(userprofile)\n    reset_link = reverse(\"password_reset_confirm\", kwargs={\"uidb64\": uid, \"token\": token})\n    text_content = _(\n        \"You're receiving this email because a new account has been created for you at JEP.\\n\"\n        \"Please go to the following page and choose a password: {url}{reset_link}\\n\"\n        \"Your username is your email address: {email}\\n\"\n    ).format(url=SITE_URL, reset_link=reset_link, email=userprofile.email)\n\n    html_content = render_to_string(\n        \"user_management/new_account_email.html\",\n        {\"uid\": uid, \"token\": token, \"site_url\": SITE_URL, \"email\": userprofile.email},\n    )\n    message = EmailMultiAlternatives(to=[userprofile.email], subject=subject, body=text_content)\n    message.attach_alternative(html_content, \"text/html\")\n    message.send()\n\n\ndef send_account_update_info(userprofile):\n    subject = _(\"JEP account updated\")\n    url = reverse(\"user_management:profile\")\n    text_content = _(\n        \"You're receiving this email because your account at JEP has been updated.\\n\"\n        \"You can see the changes in your profile: {site_url}{url}\\n\"\n        \"Your username is your email address: {email}\\n\"\n    ).format(site_url=SITE_URL, url=url, email=userprofile.email)\n\n    html_content = render_to_string(\n        \"user_management/account_updated_email.html\",\n        {\"site_url\": SITE_URL, \"url\": url, \"email\": userprofile.email},\n    )\n    message = EmailMultiAlternatives(to=[userprofile.email], subject=subject, body=text_content)\n    message.attach_alternative(html_content, \"text/html\")\n    message.send()\n", "path": "user_management/mail.py"}, {"content": "from django.urls import path\n\nfrom user_management import views\n\napp_name = \"user_management\"\nurlpatterns = [\n    path(\"profile/\", views.ProfileView.as_view(), name=\"profile\"),\n    path(\"groups/\", views.GroupListView.as_view(), name=\"group_list\"),\n    path(\"groups/<int:pk>/edit\", views.GroupUpdateView.as_view(), name=\"group_edit\"),\n    path(\"groups/<int:pk>/delete\", views.GroupDeleteView.as_view(), name=\"group_delete\"),\n    path(\"groups/create\", views.GroupCreateView.as_view(), name=\"group_add\"),\n    path(\"users/\", views.UserProfileListView.as_view(), name=\"userprofile_list\",),\n    path(\"users/<int:pk>/edit\", views.UserProfileUpdateView.as_view(), name=\"userprofile_edit\",),\n    path(\"users/create/\", views.UserProfileCreateView.as_view(), name=\"userprofile_create\",),\n]\n", "path": "user_management/urls.py"}, {"content": "from django.contrib import messages\nfrom django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin\nfrom django.contrib.auth.models import Group\nfrom django.urls import reverse\nfrom django.views.generic import DetailView, ListView, UpdateView, CreateView, DeleteView\nfrom guardian.shortcuts import get_objects_for_group\n\nfrom user_management import mail\nfrom user_management.forms import GroupForm, UserProfileForm\nfrom django.utils.translation import gettext as _\n\nfrom user_management.models import UserProfile\n\n\nclass ProfileView(LoginRequiredMixin, DetailView):\n    def get_object(self, queryset=None):\n        return self.request.user\n\n\nclass UserProfileListView(PermissionRequiredMixin, ListView):\n    model = UserProfile\n    permission_required = \"user_management.view_userprofile\"\n\n\nclass UserProfileCreateView(PermissionRequiredMixin, CreateView):\n    template_name = \"user_management/userprofile_form.html\"\n    permission_required = \"user_management.add_userprofile\"\n    model = UserProfile\n    form_class = UserProfileForm\n\n    def get_success_url(self):\n        messages.success(self.request, _(\"User added successfully.\"))\n        return reverse(\"user_management:userprofile_list\")\n\n    def form_valid(self, form):\n        response = super().form_valid(form)\n        userprofile = self.object\n        if userprofile.is_active:\n            mail.send_account_creation_info(userprofile)\n        return response\n\n\nclass UserProfileUpdateView(PermissionRequiredMixin, UpdateView):\n    model = UserProfile\n    permission_required = \"user_management.change_userprofile\"\n    template_name = \"user_management/userprofile_form.html\"\n    form_class = UserProfileForm\n\n    def get_success_url(self):\n        messages.success(self.request, _(\"User updated successfully.\"))\n        return reverse(\"user_management:userprofile_list\")\n\n    def form_valid(self, form):\n        response = super().form_valid(form)\n        userprofile = self.object\n        if userprofile.is_active:\n            mail.send_account_update_info(userprofile)\n        return response\n\n    def get_form_kwargs(self):\n        kwargs = super().get_form_kwargs()\n        kwargs[\"initial\"] = {\n            \"groups\": self.object.groups.all(),\n        }\n        return kwargs\n\n\nclass GroupListView(PermissionRequiredMixin, ListView):\n    model = Group\n    permission_required = \"auth.view_group\"\n    template_name = \"user_management/group_list.html\"\n\n\nclass GroupCreateView(PermissionRequiredMixin, CreateView):\n    model = Group\n    permission_required = \"auth.add_group\"\n    template_name = \"user_management/group_form.html\"\n    form_class = GroupForm\n\n    def get_form_kwargs(self):\n        kwargs = super().get_form_kwargs()\n        kwargs[\"initial\"] = {\n            \"users\": UserProfile.objects.none(),\n            \"can_add_event\": False,\n            \"publish_event_for_group\": Group.objects.none(),\n        }\n        return kwargs\n\n    def get_success_url(self):\n        messages.success(self.request, _(\"Group created successfully.\"))\n        return reverse(\"user_management:group_list\")\n\n\nclass GroupUpdateView(PermissionRequiredMixin, UpdateView):\n    model = Group\n    permission_required = \"auth.change_group\"\n    template_name = \"user_management/group_form.html\"\n    form_class = GroupForm\n\n    def get_form_kwargs(self):\n        kwargs = super().get_form_kwargs()\n        kwargs[\"initial\"] = {\n            \"users\": self.object.user_set.all(),\n            \"can_view_past_event\": self.object.permissions.filter(\n                codename=\"view_past_event\"\n            ).exists(),\n            \"can_add_event\": self.object.permissions.filter(codename=\"add_event\").exists(),\n            \"publish_event_for_group\": get_objects_for_group(\n                self.object, \"publish_event_for_group\", klass=Group\n            ),\n        }\n        return kwargs\n\n    def get_success_url(self):\n        messages.success(self.request, _(\"Group updated successfully.\"))\n        return reverse(\"user_management:group_list\")\n\n\nclass GroupDeleteView(PermissionRequiredMixin, DeleteView):\n    model = Group\n    permission_required = \"auth.delete_group\"\n    template_name = \"user_management/group_confirm_delete.html\"\n\n    def get_success_url(self):\n        return reverse(\"user_management:group_list\")\n", "path": "user_management/views.py"}]}