We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Liste der Benutzer ansehen
Als Manager möchte ich die Liste der Nutzer sehen, dafür soll es einen entsprechenden Menüpunkt geben.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `event_management/views.py`
Content:
```
1 import json
2 
3 import guardian.mixins
4 from django.contrib import messages
5 from django.contrib.auth import get_user_model
6 from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
7 from django.contrib.auth.models import Group
8 from django.core.exceptions import ValidationError
9 from django.http import HttpResponse
10 from django.shortcuts import get_object_or_404, redirect
11 from django.urls import reverse, reverse_lazy
12 from django.utils.timezone import get_default_timezone
13 from django.views.generic import (
14     DeleteView,
15     DetailView,
16     ListView,
17     TemplateView,
18     UpdateView,
19     View,
20     CreateView,
21     RedirectView,
22 )
23 from django.views.generic.detail import SingleObjectMixin
24 from guardian.shortcuts import get_objects_for_user, get_users_with_perms
25 
26 from event_management.forms import EventForm, ShiftForm
27 from event_management.models import (
28     Event,
29     Shift,
30     AbstractParticipation,
31 )
32 from django.utils.translation import gettext as _
33 
34 from event_management.signup import SignupError, DeclineError
35 from jep.permissions import get_groups_with_perms
36 
37 
38 class HomeView(LoginRequiredMixin, TemplateView):
39     template_name = "event_management/home.html"
40 
41 
42 class EventListView(LoginRequiredMixin, ListView):
43     model = Event
44 
45     def get_queryset(self):
46         return get_objects_for_user(self.request.user, "event_management.view_event")
47 
48 
49 class EventDetailView(guardian.mixins.PermissionRequiredMixin, DetailView):
50     model = Event
51     permission_required = "event_management.view_event"
52 
53     def get_queryset(self):
54         if self.request.user.has_perm("event_management.add_event"):
55             return Event.all_objects
56         else:
57             return Event.objects
58 
59 
60 class EventUpdateView(guardian.mixins.PermissionRequiredMixin, UpdateView):
61     model = Event
62     queryset = Event.all_objects
63     permission_required = "event_management.change_event"
64     raise_exception = True
65     accept_global_perms = True
66 
67     def get_form(self, form_class=None):
68         visible_queryset = get_objects_for_user(
69             self.request.user, "publish_event_for_group", klass=Group
70         )
71         initial = {
72             "visible_for": get_groups_with_perms(self.object, only_with_perms_in=["view_event"]),
73             "responsible_persons": get_users_with_perms(
74                 self.object, only_with_perms_in=["change_event"], with_group_users=False
75             ),
76             "responsible_groups": get_groups_with_perms(
77                 self.object, only_with_perms_in=["change_event"]
78             ),
79         }
80         event_form = EventForm(self.request.POST or None, instance=self.object, initial=initial)
81         event_form.fields["visible_for"].queryset = visible_queryset
82         return event_form
83 
84 
85 class EventCreateView(PermissionRequiredMixin, CreateView):
86     template_name = "event_management/event_form.html"
87     permission_required = "event_management.add_event"
88 
89     def get_form(self, form_class=None):
90         visible_for_queryset = get_objects_for_user(
91             self.request.user, "publish_event_for_group", klass=Group
92         )
93         event_form = EventForm(
94             self.request.POST or None,
95             initial={
96                 "responsible_persons": get_user_model().objects.filter(pk=self.request.user.pk),
97                 "responsible_groups": Group.objects.none(),
98                 "visible_for": visible_for_queryset,
99             },
100         )
101         event_form.fields["visible_for"].queryset = visible_for_queryset
102         return event_form
103 
104     def get_context_data(self, **kwargs):
105         inactive_events = Event.all_objects.filter(active=False)
106         kwargs.setdefault("inactive_events", inactive_events)
107         return super().get_context_data(**kwargs)
108 
109     def get_success_url(self):
110         return reverse("event_management:event_createshift", kwargs={"pk": self.object.pk})
111 
112 
113 class EventActivateView(PermissionRequiredMixin, RedirectView):
114     permission_required = "event_management.add_event"
115 
116     def get_redirect_url(self, *args, **kwargs):
117         event = get_object_or_404(Event.all_objects, pk=kwargs["pk"])
118         event.active = True
119         event.save()
120         messages.success(
121             self.request, _("The event {title} has been saved.".format(title=event.title))
122         )
123         return event.get_absolute_url()
124 
125 
126 class EventDeleteView(PermissionRequiredMixin, DeleteView):
127     queryset = Event.all_objects
128     permission_required = "event_management.delete_event"
129     success_url = reverse_lazy("event_management:event_list")
130 
131 
132 class ShiftCreateView(PermissionRequiredMixin, TemplateView):
133     permission_required = "event_management.add_event"
134     template_name = "event_management/shift_form.html"
135 
136     def get_event(self):
137         return get_object_or_404(Event.all_objects, pk=self.kwargs.get("pk"))
138 
139     def get_shift_form(self):
140         return ShiftForm(self.request.POST or None)
141 
142     def get_context_data(self, **kwargs):
143         event = self.get_event()
144         kwargs.setdefault("event", event)
145         kwargs.setdefault("form", self.get_shift_form())
146         return super().get_context_data(**kwargs)
147 
148     def post(self, *args, **kwargs):
149         form = self.get_shift_form()
150         try:
151             from event_management.signup import signup_method_from_slug
152 
153             signup_method = signup_method_from_slug(self.request.POST["signup_method_slug"])
154             configuration_form = signup_method.get_configuration_form(self.request.POST)
155         except ValueError as e:
156             raise ValidationError(e)
157         if form.is_valid() and configuration_form.is_valid():
158             shift = form.save(commit=False)
159             event = self.get_event()
160             shift.event = event
161             shift.signup_configuration = configuration_form.get_configuration()
162             shift.save()
163             if "addAnother" in self.request.POST:
164                 return redirect(
165                     reverse(
166                         "event_management:event_createshift", kwargs={"pk": self.kwargs.get("pk")}
167                     )
168                 )
169             else:
170                 event.active = True
171                 event.save()
172                 messages.success(
173                     self.request, _("The event {title} has been saved.".format(title=event.title))
174                 )
175                 return redirect(event.get_absolute_url())
176         else:
177             return self.render_to_response(
178                 self.get_context_data(
179                     form=form,
180                     configuration_form=signup_method.render_configuration_form(configuration_form),
181                 )
182             )
183 
184 
185 class ShiftConfigurationFormView(View):
186     def get(self, request, *args, **kwargs):
187         from event_management.signup import signup_method_from_slug
188 
189         signup_method = signup_method_from_slug(self.kwargs.get("slug"))
190         return HttpResponse(signup_method.render_configuration_form())
191 
192 
193 class ShiftUpdateView(guardian.mixins.PermissionRequiredMixin, TemplateView, SingleObjectMixin):
194     model = Shift
195     template_name = "event_management/shift_form.html"
196     permission_required = "event_management.change_event"
197     raise_exception = True
198     accept_global_perms = True
199 
200     def get_permission_object(self):
201         return self.get_object().event
202 
203     def get_shift_form(self):
204         return ShiftForm(
205             self.request.POST or None,
206             instance=self.object,
207             initial={
208                 "date": self.object.meeting_time.date(),
209                 "meeting_time": self.object.meeting_time.astimezone(get_default_timezone()).time(),
210                 "start_time": self.object.start_time.astimezone(get_default_timezone()).time(),
211                 "end_time": self.object.end_time.astimezone(get_default_timezone()).time(),
212             },
213         )
214 
215     def get_configuration_form(self):
216         return self.object.signup_method.render_configuration_form(
217             data=self.request.POST or None, initial=json.loads(self.object.signup_configuration)
218         )
219 
220     def get_context_data(self, **kwargs):
221         self.object = self.get_object()
222         kwargs.setdefault("event", self.object.event)
223         kwargs.setdefault("form", self.get_shift_form())
224         kwargs.setdefault("configuration_form", self.get_configuration_form())
225         return super().get_context_data(**kwargs)
226 
227     def post(self, *args, **kwargs):
228         self.object = self.get_object()
229         form = self.get_shift_form()
230         try:
231             from event_management.signup import signup_method_from_slug
232 
233             signup_method = signup_method_from_slug(self.request.POST["signup_method_slug"])
234             configuration_form = signup_method.get_configuration_form(self.request.POST)
235         except ValueError as e:
236             raise ValidationError(e)
237         if form.is_valid() and configuration_form.is_valid():
238             shift = form.save(commit=False)
239             shift.signup_configuration = configuration_form.get_configuration()
240             shift.save()
241             if "addAnother" in self.request.POST:
242                 return redirect(
243                     reverse("event_management:event_createshift", kwargs={"pk": shift.event.pk})
244                 )
245             else:
246                 messages.success(
247                     self.request, _("The shift {shift} has been saved.".format(shift=shift))
248                 )
249                 return redirect(self.object.event.get_absolute_url())
250         else:
251             return self.render_to_response(
252                 self.get_context_data(
253                     form=form,
254                     configuration_form=signup_method.render_configuration_form(configuration_form),
255                 )
256             )
257 
258 
259 class ShiftDeleteView(PermissionRequiredMixin, DeleteView):
260     permission_required = "event_management.change_event"
261     model = Shift
262 
263     def delete(self, request, *args, **kwargs):
264         self.object = self.get_object()
265         if self.object.event.shifts.count() == 1:
266             messages.error(self.request, _("You cannot delete the last shift!"))
267             return redirect(self.object.event.get_absolute_url())
268         else:
269             return super().delete(request, *args, **kwargs)
270 
271     def get_success_url(self):
272         messages.success(self.request, _("The shift has been deleted."))
273         return self.object.event.get_absolute_url()
274 
275 
276 # TODO rename to signup
277 class ShiftRegisterView(LoginRequiredMixin, View):
278     def get(self, request, *args, **kwargs):
279         shift = get_object_or_404(Shift, id=self.kwargs["pk"])
280         return shift.signup_method.signup_view(request, *args, **kwargs)
281 
282 
283 class ShiftDeclineView(RedirectView):
284     def get_redirect_url(self, *args, **kwargs):
285         shift = get_object_or_404(Shift, id=self.kwargs["pk"])
286         return shift.signup_method.decline_view(self.request)
287
```

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 ]
13
```

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_users_with_perms, get_objects_for_group
7 
8 from user_management.forms import GroupForm
9 from django.utils.translation import gettext as _
10 
11 from user_management.models import UserProfile
12 
13 
14 class ProfileView(LoginRequiredMixin, DetailView):
15     def get_object(self, queryset=None):
16         return self.request.user
17 
18 
19 class GroupListView(PermissionRequiredMixin, ListView):
20     model = Group
21     permission_required = "auth.view_group"
22     template_name = "user_management/group_list.html"
23 
24 
25 class GroupCreateView(PermissionRequiredMixin, CreateView):
26     model = Group
27     permission_required = "auth.add_group"
28     template_name = "user_management/group_form.html"
29     form_class = GroupForm
30 
31     def get_form_kwargs(self):
32         kwargs = super().get_form_kwargs()
33         kwargs["initial"] = {
34             "users": UserProfile.objects.none(),
35             "can_add_event": False,
36             "publish_event_for_group": Group.objects.none(),
37         }
38         return kwargs
39 
40     def get_success_url(self):
41         messages.success(self.request, _("Group succesfully created."))
42         return reverse("user_management:group_list")
43 
44 
45 class GroupUpdateView(PermissionRequiredMixin, UpdateView):
46     model = Group
47     permission_required = "auth.change_group"
48     template_name = "user_management/group_form.html"
49     form_class = GroupForm
50 
51     def get_form_kwargs(self):
52         kwargs = super().get_form_kwargs()
53         kwargs["initial"] = {
54             "users": self.object.user_set.all(),
55             "can_add_event": self.object.permissions.filter(codename="add_event").exists(),
56             "publish_event_for_group": get_objects_for_group(
57                 self.object, "publish_event_for_group", klass=Group
58             ),
59         }
60         return kwargs
61 
62     def get_success_url(self):
63         return reverse("user_management:group_list")
64 
65 
66 class GroupDeleteView(PermissionRequiredMixin, DeleteView):
67     model = Group
68     permission_required = "auth.delete_group"
69     template_name = "user_management/group_confirm_delete.html"
70 
71     def get_success_url(self):
72         return reverse("user_management:group_list")
73
```
--- 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/event_management/views.py b/event_management/views.py
--- a/event_management/views.py
+++ b/event_management/views.py
@@ -170,7 +170,7 @@
                 event.active = True
                 event.save()
                 messages.success(
-                    self.request, _("The event {title} has been saved.".format(title=event.title))
+                    self.request, _("The event {title} has been saved.").format(title=event.title)
                 )
                 return redirect(event.get_absolute_url())
         else:
@@ -244,7 +244,7 @@
                 )
             else:
                 messages.success(
-                    self.request, _("The shift {shift} has been saved.".format(shift=shift))
+                    self.request, _("The shift {shift} has been saved.").format(shift=shift)
                 )
                 return redirect(self.object.event.get_absolute_url())
         else:
diff --git a/user_management/urls.py b/user_management/urls.py
--- a/user_management/urls.py
+++ b/user_management/urls.py
@@ -9,4 +9,5 @@
     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",),
 ]
diff --git a/user_management/views.py b/user_management/views.py
--- a/user_management/views.py
+++ b/user_management/views.py
@@ -16,6 +16,14 @@
         return self.request.user
 
 
+class UserProfileListView(PermissionRequiredMixin, ListView):
+    model = UserProfile
+    permission_required = "user.view_user"
+
+    def get_queryset(self):
+        return UserProfile.objects.all()
+
+
 class GroupListView(PermissionRequiredMixin, ListView):
     model = Group
     permission_required = "auth.view_group"

{"golden_diff": "diff --git a/event_management/views.py b/event_management/views.py\n--- a/event_management/views.py\n+++ b/event_management/views.py\n@@ -170,7 +170,7 @@\n                 event.active = True\n                 event.save()\n                 messages.success(\n-                    self.request, _(\"The event {title} has been saved.\".format(title=event.title))\n+                    self.request, _(\"The event {title} has been saved.\").format(title=event.title)\n                 )\n                 return redirect(event.get_absolute_url())\n         else:\n@@ -244,7 +244,7 @@\n                 )\n             else:\n                 messages.success(\n-                    self.request, _(\"The shift {shift} has been saved.\".format(shift=shift))\n+                    self.request, _(\"The shift {shift} has been saved.\").format(shift=shift)\n                 )\n                 return redirect(self.object.event.get_absolute_url())\n         else:\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,4 +9,5 @@\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 ]\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@@ -16,6 +16,14 @@\n         return self.request.user\n \n \n+class UserProfileListView(PermissionRequiredMixin, ListView):\n+    model = UserProfile\n+    permission_required = \"user.view_user\"\n+\n+    def get_queryset(self):\n+        return UserProfile.objects.all()\n+\n+\n class GroupListView(PermissionRequiredMixin, ListView):\n     model = Group\n     permission_required = \"auth.view_group\"\n", "issue": "Liste der Benutzer ansehen\nAls Manager m\u00f6chte ich die Liste der Nutzer sehen, daf\u00fcr soll es einen entsprechenden Men\u00fcpunkt geben.\n", "before_files": [{"content": "import json\n\nimport guardian.mixins\nfrom django.contrib import messages\nfrom django.contrib.auth import get_user_model\nfrom django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin\nfrom django.contrib.auth.models import Group\nfrom django.core.exceptions import ValidationError\nfrom django.http import HttpResponse\nfrom django.shortcuts import get_object_or_404, redirect\nfrom django.urls import reverse, reverse_lazy\nfrom django.utils.timezone import get_default_timezone\nfrom django.views.generic import (\n    DeleteView,\n    DetailView,\n    ListView,\n    TemplateView,\n    UpdateView,\n    View,\n    CreateView,\n    RedirectView,\n)\nfrom django.views.generic.detail import SingleObjectMixin\nfrom guardian.shortcuts import get_objects_for_user, get_users_with_perms\n\nfrom event_management.forms import EventForm, ShiftForm\nfrom event_management.models import (\n    Event,\n    Shift,\n    AbstractParticipation,\n)\nfrom django.utils.translation import gettext as _\n\nfrom event_management.signup import SignupError, DeclineError\nfrom jep.permissions import get_groups_with_perms\n\n\nclass HomeView(LoginRequiredMixin, TemplateView):\n    template_name = \"event_management/home.html\"\n\n\nclass EventListView(LoginRequiredMixin, ListView):\n    model = Event\n\n    def get_queryset(self):\n        return get_objects_for_user(self.request.user, \"event_management.view_event\")\n\n\nclass EventDetailView(guardian.mixins.PermissionRequiredMixin, DetailView):\n    model = Event\n    permission_required = \"event_management.view_event\"\n\n    def get_queryset(self):\n        if self.request.user.has_perm(\"event_management.add_event\"):\n            return Event.all_objects\n        else:\n            return Event.objects\n\n\nclass EventUpdateView(guardian.mixins.PermissionRequiredMixin, UpdateView):\n    model = Event\n    queryset = Event.all_objects\n    permission_required = \"event_management.change_event\"\n    raise_exception = True\n    accept_global_perms = True\n\n    def get_form(self, form_class=None):\n        visible_queryset = get_objects_for_user(\n            self.request.user, \"publish_event_for_group\", klass=Group\n        )\n        initial = {\n            \"visible_for\": get_groups_with_perms(self.object, only_with_perms_in=[\"view_event\"]),\n            \"responsible_persons\": get_users_with_perms(\n                self.object, only_with_perms_in=[\"change_event\"], with_group_users=False\n            ),\n            \"responsible_groups\": get_groups_with_perms(\n                self.object, only_with_perms_in=[\"change_event\"]\n            ),\n        }\n        event_form = EventForm(self.request.POST or None, instance=self.object, initial=initial)\n        event_form.fields[\"visible_for\"].queryset = visible_queryset\n        return event_form\n\n\nclass EventCreateView(PermissionRequiredMixin, CreateView):\n    template_name = \"event_management/event_form.html\"\n    permission_required = \"event_management.add_event\"\n\n    def get_form(self, form_class=None):\n        visible_for_queryset = get_objects_for_user(\n            self.request.user, \"publish_event_for_group\", klass=Group\n        )\n        event_form = EventForm(\n            self.request.POST or None,\n            initial={\n                \"responsible_persons\": get_user_model().objects.filter(pk=self.request.user.pk),\n                \"responsible_groups\": Group.objects.none(),\n                \"visible_for\": visible_for_queryset,\n            },\n        )\n        event_form.fields[\"visible_for\"].queryset = visible_for_queryset\n        return event_form\n\n    def get_context_data(self, **kwargs):\n        inactive_events = Event.all_objects.filter(active=False)\n        kwargs.setdefault(\"inactive_events\", inactive_events)\n        return super().get_context_data(**kwargs)\n\n    def get_success_url(self):\n        return reverse(\"event_management:event_createshift\", kwargs={\"pk\": self.object.pk})\n\n\nclass EventActivateView(PermissionRequiredMixin, RedirectView):\n    permission_required = \"event_management.add_event\"\n\n    def get_redirect_url(self, *args, **kwargs):\n        event = get_object_or_404(Event.all_objects, pk=kwargs[\"pk\"])\n        event.active = True\n        event.save()\n        messages.success(\n            self.request, _(\"The event {title} has been saved.\".format(title=event.title))\n        )\n        return event.get_absolute_url()\n\n\nclass EventDeleteView(PermissionRequiredMixin, DeleteView):\n    queryset = Event.all_objects\n    permission_required = \"event_management.delete_event\"\n    success_url = reverse_lazy(\"event_management:event_list\")\n\n\nclass ShiftCreateView(PermissionRequiredMixin, TemplateView):\n    permission_required = \"event_management.add_event\"\n    template_name = \"event_management/shift_form.html\"\n\n    def get_event(self):\n        return get_object_or_404(Event.all_objects, pk=self.kwargs.get(\"pk\"))\n\n    def get_shift_form(self):\n        return ShiftForm(self.request.POST or None)\n\n    def get_context_data(self, **kwargs):\n        event = self.get_event()\n        kwargs.setdefault(\"event\", event)\n        kwargs.setdefault(\"form\", self.get_shift_form())\n        return super().get_context_data(**kwargs)\n\n    def post(self, *args, **kwargs):\n        form = self.get_shift_form()\n        try:\n            from event_management.signup import signup_method_from_slug\n\n            signup_method = signup_method_from_slug(self.request.POST[\"signup_method_slug\"])\n            configuration_form = signup_method.get_configuration_form(self.request.POST)\n        except ValueError as e:\n            raise ValidationError(e)\n        if form.is_valid() and configuration_form.is_valid():\n            shift = form.save(commit=False)\n            event = self.get_event()\n            shift.event = event\n            shift.signup_configuration = configuration_form.get_configuration()\n            shift.save()\n            if \"addAnother\" in self.request.POST:\n                return redirect(\n                    reverse(\n                        \"event_management:event_createshift\", kwargs={\"pk\": self.kwargs.get(\"pk\")}\n                    )\n                )\n            else:\n                event.active = True\n                event.save()\n                messages.success(\n                    self.request, _(\"The event {title} has been saved.\".format(title=event.title))\n                )\n                return redirect(event.get_absolute_url())\n        else:\n            return self.render_to_response(\n                self.get_context_data(\n                    form=form,\n                    configuration_form=signup_method.render_configuration_form(configuration_form),\n                )\n            )\n\n\nclass ShiftConfigurationFormView(View):\n    def get(self, request, *args, **kwargs):\n        from event_management.signup import signup_method_from_slug\n\n        signup_method = signup_method_from_slug(self.kwargs.get(\"slug\"))\n        return HttpResponse(signup_method.render_configuration_form())\n\n\nclass ShiftUpdateView(guardian.mixins.PermissionRequiredMixin, TemplateView, SingleObjectMixin):\n    model = Shift\n    template_name = \"event_management/shift_form.html\"\n    permission_required = \"event_management.change_event\"\n    raise_exception = True\n    accept_global_perms = True\n\n    def get_permission_object(self):\n        return self.get_object().event\n\n    def get_shift_form(self):\n        return ShiftForm(\n            self.request.POST or None,\n            instance=self.object,\n            initial={\n                \"date\": self.object.meeting_time.date(),\n                \"meeting_time\": self.object.meeting_time.astimezone(get_default_timezone()).time(),\n                \"start_time\": self.object.start_time.astimezone(get_default_timezone()).time(),\n                \"end_time\": self.object.end_time.astimezone(get_default_timezone()).time(),\n            },\n        )\n\n    def get_configuration_form(self):\n        return self.object.signup_method.render_configuration_form(\n            data=self.request.POST or None, initial=json.loads(self.object.signup_configuration)\n        )\n\n    def get_context_data(self, **kwargs):\n        self.object = self.get_object()\n        kwargs.setdefault(\"event\", self.object.event)\n        kwargs.setdefault(\"form\", self.get_shift_form())\n        kwargs.setdefault(\"configuration_form\", self.get_configuration_form())\n        return super().get_context_data(**kwargs)\n\n    def post(self, *args, **kwargs):\n        self.object = self.get_object()\n        form = self.get_shift_form()\n        try:\n            from event_management.signup import signup_method_from_slug\n\n            signup_method = signup_method_from_slug(self.request.POST[\"signup_method_slug\"])\n            configuration_form = signup_method.get_configuration_form(self.request.POST)\n        except ValueError as e:\n            raise ValidationError(e)\n        if form.is_valid() and configuration_form.is_valid():\n            shift = form.save(commit=False)\n            shift.signup_configuration = configuration_form.get_configuration()\n            shift.save()\n            if \"addAnother\" in self.request.POST:\n                return redirect(\n                    reverse(\"event_management:event_createshift\", kwargs={\"pk\": shift.event.pk})\n                )\n            else:\n                messages.success(\n                    self.request, _(\"The shift {shift} has been saved.\".format(shift=shift))\n                )\n                return redirect(self.object.event.get_absolute_url())\n        else:\n            return self.render_to_response(\n                self.get_context_data(\n                    form=form,\n                    configuration_form=signup_method.render_configuration_form(configuration_form),\n                )\n            )\n\n\nclass ShiftDeleteView(PermissionRequiredMixin, DeleteView):\n    permission_required = \"event_management.change_event\"\n    model = Shift\n\n    def delete(self, request, *args, **kwargs):\n        self.object = self.get_object()\n        if self.object.event.shifts.count() == 1:\n            messages.error(self.request, _(\"You cannot delete the last shift!\"))\n            return redirect(self.object.event.get_absolute_url())\n        else:\n            return super().delete(request, *args, **kwargs)\n\n    def get_success_url(self):\n        messages.success(self.request, _(\"The shift has been deleted.\"))\n        return self.object.event.get_absolute_url()\n\n\n# TODO rename to signup\nclass ShiftRegisterView(LoginRequiredMixin, View):\n    def get(self, request, *args, **kwargs):\n        shift = get_object_or_404(Shift, id=self.kwargs[\"pk\"])\n        return shift.signup_method.signup_view(request, *args, **kwargs)\n\n\nclass ShiftDeclineView(RedirectView):\n    def get_redirect_url(self, *args, **kwargs):\n        shift = get_object_or_404(Shift, id=self.kwargs[\"pk\"])\n        return shift.signup_method.decline_view(self.request)\n", "path": "event_management/views.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]\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_users_with_perms, get_objects_for_group\n\nfrom user_management.forms import GroupForm\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 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 succesfully created.\"))\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_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": "import json\n\nimport guardian.mixins\nfrom django.contrib import messages\nfrom django.contrib.auth import get_user_model\nfrom django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin\nfrom django.contrib.auth.models import Group\nfrom django.core.exceptions import ValidationError\nfrom django.http import HttpResponse\nfrom django.shortcuts import get_object_or_404, redirect\nfrom django.urls import reverse, reverse_lazy\nfrom django.utils.timezone import get_default_timezone\nfrom django.views.generic import (\n    DeleteView,\n    DetailView,\n    ListView,\n    TemplateView,\n    UpdateView,\n    View,\n    CreateView,\n    RedirectView,\n)\nfrom django.views.generic.detail import SingleObjectMixin\nfrom guardian.shortcuts import get_objects_for_user, get_users_with_perms\n\nfrom event_management.forms import EventForm, ShiftForm\nfrom event_management.models import (\n    Event,\n    Shift,\n    AbstractParticipation,\n)\nfrom django.utils.translation import gettext as _\n\nfrom event_management.signup import SignupError, DeclineError\nfrom jep.permissions import get_groups_with_perms\n\n\nclass HomeView(LoginRequiredMixin, TemplateView):\n    template_name = \"event_management/home.html\"\n\n\nclass EventListView(LoginRequiredMixin, ListView):\n    model = Event\n\n    def get_queryset(self):\n        return get_objects_for_user(self.request.user, \"event_management.view_event\")\n\n\nclass EventDetailView(guardian.mixins.PermissionRequiredMixin, DetailView):\n    model = Event\n    permission_required = \"event_management.view_event\"\n\n    def get_queryset(self):\n        if self.request.user.has_perm(\"event_management.add_event\"):\n            return Event.all_objects\n        else:\n            return Event.objects\n\n\nclass EventUpdateView(guardian.mixins.PermissionRequiredMixin, UpdateView):\n    model = Event\n    queryset = Event.all_objects\n    permission_required = \"event_management.change_event\"\n    raise_exception = True\n    accept_global_perms = True\n\n    def get_form(self, form_class=None):\n        visible_queryset = get_objects_for_user(\n            self.request.user, \"publish_event_for_group\", klass=Group\n        )\n        initial = {\n            \"visible_for\": get_groups_with_perms(self.object, only_with_perms_in=[\"view_event\"]),\n            \"responsible_persons\": get_users_with_perms(\n                self.object, only_with_perms_in=[\"change_event\"], with_group_users=False\n            ),\n            \"responsible_groups\": get_groups_with_perms(\n                self.object, only_with_perms_in=[\"change_event\"]\n            ),\n        }\n        event_form = EventForm(self.request.POST or None, instance=self.object, initial=initial)\n        event_form.fields[\"visible_for\"].queryset = visible_queryset\n        return event_form\n\n\nclass EventCreateView(PermissionRequiredMixin, CreateView):\n    template_name = \"event_management/event_form.html\"\n    permission_required = \"event_management.add_event\"\n\n    def get_form(self, form_class=None):\n        visible_for_queryset = get_objects_for_user(\n            self.request.user, \"publish_event_for_group\", klass=Group\n        )\n        event_form = EventForm(\n            self.request.POST or None,\n            initial={\n                \"responsible_persons\": get_user_model().objects.filter(pk=self.request.user.pk),\n                \"responsible_groups\": Group.objects.none(),\n                \"visible_for\": visible_for_queryset,\n            },\n        )\n        event_form.fields[\"visible_for\"].queryset = visible_for_queryset\n        return event_form\n\n    def get_context_data(self, **kwargs):\n        inactive_events = Event.all_objects.filter(active=False)\n        kwargs.setdefault(\"inactive_events\", inactive_events)\n        return super().get_context_data(**kwargs)\n\n    def get_success_url(self):\n        return reverse(\"event_management:event_createshift\", kwargs={\"pk\": self.object.pk})\n\n\nclass EventActivateView(PermissionRequiredMixin, RedirectView):\n    permission_required = \"event_management.add_event\"\n\n    def get_redirect_url(self, *args, **kwargs):\n        event = get_object_or_404(Event.all_objects, pk=kwargs[\"pk\"])\n        event.active = True\n        event.save()\n        messages.success(\n            self.request, _(\"The event {title} has been saved.\".format(title=event.title))\n        )\n        return event.get_absolute_url()\n\n\nclass EventDeleteView(PermissionRequiredMixin, DeleteView):\n    queryset = Event.all_objects\n    permission_required = \"event_management.delete_event\"\n    success_url = reverse_lazy(\"event_management:event_list\")\n\n\nclass ShiftCreateView(PermissionRequiredMixin, TemplateView):\n    permission_required = \"event_management.add_event\"\n    template_name = \"event_management/shift_form.html\"\n\n    def get_event(self):\n        return get_object_or_404(Event.all_objects, pk=self.kwargs.get(\"pk\"))\n\n    def get_shift_form(self):\n        return ShiftForm(self.request.POST or None)\n\n    def get_context_data(self, **kwargs):\n        event = self.get_event()\n        kwargs.setdefault(\"event\", event)\n        kwargs.setdefault(\"form\", self.get_shift_form())\n        return super().get_context_data(**kwargs)\n\n    def post(self, *args, **kwargs):\n        form = self.get_shift_form()\n        try:\n            from event_management.signup import signup_method_from_slug\n\n            signup_method = signup_method_from_slug(self.request.POST[\"signup_method_slug\"])\n            configuration_form = signup_method.get_configuration_form(self.request.POST)\n        except ValueError as e:\n            raise ValidationError(e)\n        if form.is_valid() and configuration_form.is_valid():\n            shift = form.save(commit=False)\n            event = self.get_event()\n            shift.event = event\n            shift.signup_configuration = configuration_form.get_configuration()\n            shift.save()\n            if \"addAnother\" in self.request.POST:\n                return redirect(\n                    reverse(\n                        \"event_management:event_createshift\", kwargs={\"pk\": self.kwargs.get(\"pk\")}\n                    )\n                )\n            else:\n                event.active = True\n                event.save()\n                messages.success(\n                    self.request, _(\"The event {title} has been saved.\").format(title=event.title)\n                )\n                return redirect(event.get_absolute_url())\n        else:\n            return self.render_to_response(\n                self.get_context_data(\n                    form=form,\n                    configuration_form=signup_method.render_configuration_form(configuration_form),\n                )\n            )\n\n\nclass ShiftConfigurationFormView(View):\n    def get(self, request, *args, **kwargs):\n        from event_management.signup import signup_method_from_slug\n\n        signup_method = signup_method_from_slug(self.kwargs.get(\"slug\"))\n        return HttpResponse(signup_method.render_configuration_form())\n\n\nclass ShiftUpdateView(guardian.mixins.PermissionRequiredMixin, TemplateView, SingleObjectMixin):\n    model = Shift\n    template_name = \"event_management/shift_form.html\"\n    permission_required = \"event_management.change_event\"\n    raise_exception = True\n    accept_global_perms = True\n\n    def get_permission_object(self):\n        return self.get_object().event\n\n    def get_shift_form(self):\n        return ShiftForm(\n            self.request.POST or None,\n            instance=self.object,\n            initial={\n                \"date\": self.object.meeting_time.date(),\n                \"meeting_time\": self.object.meeting_time.astimezone(get_default_timezone()).time(),\n                \"start_time\": self.object.start_time.astimezone(get_default_timezone()).time(),\n                \"end_time\": self.object.end_time.astimezone(get_default_timezone()).time(),\n            },\n        )\n\n    def get_configuration_form(self):\n        return self.object.signup_method.render_configuration_form(\n            data=self.request.POST or None, initial=json.loads(self.object.signup_configuration)\n        )\n\n    def get_context_data(self, **kwargs):\n        self.object = self.get_object()\n        kwargs.setdefault(\"event\", self.object.event)\n        kwargs.setdefault(\"form\", self.get_shift_form())\n        kwargs.setdefault(\"configuration_form\", self.get_configuration_form())\n        return super().get_context_data(**kwargs)\n\n    def post(self, *args, **kwargs):\n        self.object = self.get_object()\n        form = self.get_shift_form()\n        try:\n            from event_management.signup import signup_method_from_slug\n\n            signup_method = signup_method_from_slug(self.request.POST[\"signup_method_slug\"])\n            configuration_form = signup_method.get_configuration_form(self.request.POST)\n        except ValueError as e:\n            raise ValidationError(e)\n        if form.is_valid() and configuration_form.is_valid():\n            shift = form.save(commit=False)\n            shift.signup_configuration = configuration_form.get_configuration()\n            shift.save()\n            if \"addAnother\" in self.request.POST:\n                return redirect(\n                    reverse(\"event_management:event_createshift\", kwargs={\"pk\": shift.event.pk})\n                )\n            else:\n                messages.success(\n                    self.request, _(\"The shift {shift} has been saved.\").format(shift=shift)\n                )\n                return redirect(self.object.event.get_absolute_url())\n        else:\n            return self.render_to_response(\n                self.get_context_data(\n                    form=form,\n                    configuration_form=signup_method.render_configuration_form(configuration_form),\n                )\n            )\n\n\nclass ShiftDeleteView(PermissionRequiredMixin, DeleteView):\n    permission_required = \"event_management.change_event\"\n    model = Shift\n\n    def delete(self, request, *args, **kwargs):\n        self.object = self.get_object()\n        if self.object.event.shifts.count() == 1:\n            messages.error(self.request, _(\"You cannot delete the last shift!\"))\n            return redirect(self.object.event.get_absolute_url())\n        else:\n            return super().delete(request, *args, **kwargs)\n\n    def get_success_url(self):\n        messages.success(self.request, _(\"The shift has been deleted.\"))\n        return self.object.event.get_absolute_url()\n\n\n# TODO rename to signup\nclass ShiftRegisterView(LoginRequiredMixin, View):\n    def get(self, request, *args, **kwargs):\n        shift = get_object_or_404(Shift, id=self.kwargs[\"pk\"])\n        return shift.signup_method.signup_view(request, *args, **kwargs)\n\n\nclass ShiftDeclineView(RedirectView):\n    def get_redirect_url(self, *args, **kwargs):\n        shift = get_object_or_404(Shift, id=self.kwargs[\"pk\"])\n        return shift.signup_method.decline_view(self.request)\n", "path": "event_management/views.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]\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_users_with_perms, get_objects_for_group\n\nfrom user_management.forms import GroupForm\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.view_user\"\n\n    def get_queryset(self):\n        return UserProfile.objects.all()\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 succesfully created.\"))\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_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"}]}