We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Cannot add events on staging/master
### Describe the bug
`KeyError at /admin/events/event/add/`

### How to reproduce
Steps to reproduce the behaviour:
1. Go to admin
2. Try to add event
3. See error mentioned above

### Expected behaviour
Get the actual admin page

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `website/events/admin/event.py`
Content:
```
1 """Registers admin interfaces for the event model."""
2 
3 from django.contrib import admin
4 from django.db.models import Count, Q
5 from django.template.defaultfilters import date as _date
6 from django.urls import reverse, path, resolve
7 from django.utils import timezone
8 from django.utils.html import format_html
9 from django.utils.translation import gettext_lazy as _
10 
11 from activemembers.models import MemberGroup
12 from events import services
13 from events import models
14 from events.admin.filters import LectureYearFilter
15 from events.admin.forms import RegistrationInformationFieldForm, EventAdminForm
16 from events.admin.inlines import (
17     RegistrationInformationFieldInline,
18     PizzaEventInline,
19     PromotionRequestInline,
20 )
21 from events.admin.views import (
22     EventAdminDetails,
23     EventRegistrationsExport,
24     EventMessage,
25     EventMarkPresentQR,
26 )
27 from utils.admin import DoNextModelAdmin
28 
29 
30 @admin.register(models.Event)
31 class EventAdmin(DoNextModelAdmin):
32     """Manage the events."""
33 
34     form = EventAdminForm
35 
36     inlines = (
37         RegistrationInformationFieldInline,
38         PizzaEventInline,
39         PromotionRequestInline,
40     )
41     list_display = (
42         "overview_link",
43         "event_date",
44         "registration_date",
45         "num_participants",
46         "category",
47         "published",
48         "edit_link",
49     )
50     list_display_links = ("edit_link",)
51     list_filter = (LectureYearFilter, "start", "published", "category")
52     actions = ("make_published", "make_unpublished")
53     date_hierarchy = "start"
54     search_fields = ("title", "description")
55     prepopulated_fields = {"map_location": ("location",)}
56     filter_horizontal = ("documents", "organisers")
57 
58     fieldsets = (
59         (
60             _("General"),
61             {
62                 "fields": (
63                     "title",
64                     "published",
65                     "organisers",
66                 )
67             },
68         ),
69         (
70             _("Detail"),
71             {
72                 "fields": (
73                     "category",
74                     "start",
75                     "end",
76                     "description",
77                     "caption",
78                     "location",
79                     "map_location",
80                 ),
81                 "classes": ("collapse", "start-open"),
82             },
83         ),
84         (
85             _("Registrations"),
86             {
87                 "fields": (
88                     "price",
89                     "fine",
90                     "tpay_allowed",
91                     "max_participants",
92                     "registration_start",
93                     "registration_end",
94                     "cancel_deadline",
95                     "send_cancel_email",
96                     "optional_registrations",
97                     "no_registration_message",
98                 ),
99                 "classes": ("collapse",),
100             },
101         ),
102         (
103             _("Extra"),
104             {"fields": ("slide", "documents", "shift"), "classes": ("collapse",)},
105         ),
106     )
107 
108     def get_queryset(self, request):
109         return (
110             super()
111             .get_queryset(request)
112             .annotate(
113                 participant_count=Count(
114                     "eventregistration",
115                     filter=~Q(eventregistration__date_cancelled__lt=timezone.now()),
116                 )
117             )
118         )
119 
120     def get_form(self, request, obj=None, change=False, **kwargs):
121         form = super().get_form(request, obj, change, **kwargs)
122         form.clean = lambda form: form.instance.clean_changes(form.changed_data)
123         return form
124 
125     def overview_link(self, obj):
126         return format_html(
127             '<a href="{link}">{title}</a>',
128             link=reverse("admin:events_event_details", kwargs={"pk": obj.pk}),
129             title=obj.title,
130         )
131 
132     def has_change_permission(self, request, obj=None):
133         """Only allow access to the change form if the user is an organiser."""
134         if obj is not None and not services.is_organiser(request.member, obj):
135             return False
136         return super().has_change_permission(request, obj)
137 
138     def event_date(self, obj):
139         event_date = timezone.make_naive(obj.start)
140         return _date(event_date, "l d b Y, G:i")
141 
142     event_date.short_description = _("Event Date")
143     event_date.admin_order_field = "start"
144 
145     def registration_date(self, obj):
146         if obj.registration_start is not None:
147             start_date = timezone.make_naive(obj.registration_start)
148         else:
149             start_date = obj.registration_start
150 
151         return _date(start_date, "l d b Y, G:i")
152 
153     registration_date.short_description = _("Registration Start")
154     registration_date.admin_order_field = "registration_start"
155 
156     def edit_link(self, obj):
157         return _("Edit")
158 
159     edit_link.short_description = ""
160 
161     def num_participants(self, obj):
162         """Pretty-print the number of participants."""
163         num = obj.participant_count  # from annotation
164         if not obj.max_participants:
165             return f"{num}/∞"
166         return f"{num}/{obj.max_participants}"
167 
168     num_participants.short_description = _("Number of participants")
169 
170     def make_published(self, request, queryset):
171         """Change the status of the event to published."""
172         self._change_published(request, queryset, True)
173 
174     make_published.short_description = _("Publish selected events")
175 
176     def make_unpublished(self, request, queryset):
177         """Change the status of the event to unpublished."""
178         self._change_published(request, queryset, False)
179 
180     make_unpublished.short_description = _("Unpublish selected events")
181 
182     @staticmethod
183     def _change_published(request, queryset, published):
184         if not request.user.is_superuser:
185             queryset = queryset.filter(
186                 organisers__in=request.member.get_member_groups()
187             )
188         queryset.update(published=published)
189 
190     def save_formset(self, request, form, formset, change):
191         """Save formsets with their order."""
192         formset.save()
193 
194         informationfield_forms = (
195             x
196             for x in formset.forms
197             if isinstance(x, RegistrationInformationFieldForm)
198             and "DELETE" not in x.changed_data
199         )
200         form.instance.set_registrationinformationfield_order(
201             [
202                 f.instance.pk
203                 for f in sorted(
204                     informationfield_forms,
205                     key=lambda x: (x.cleaned_data["order"], x.instance.pk),
206                 )
207             ]
208         )
209         form.instance.save()
210 
211     def get_actions(self, request):
212         actions = super().get_actions(request)
213         if "delete_selected" in actions:
214             del actions["delete_selected"]
215         return actions
216 
217     def get_formsets_with_inlines(self, request, obj=None):
218         for inline in self.get_inline_instances(request, obj):
219             if self.has_change_permission(request, obj) or obj is None:
220                 yield inline.get_formset(request, obj), inline
221 
222     def get_urls(self):
223         urls = super().get_urls()
224         custom_urls = [
225             path(
226                 "<int:pk>/details/",
227                 self.admin_site.admin_view(EventAdminDetails.as_view()),
228                 name="events_event_details",
229             ),
230             path(
231                 "<int:pk>/export/",
232                 self.admin_site.admin_view(EventRegistrationsExport.as_view()),
233                 name="events_event_export",
234             ),
235             path(
236                 "<int:pk>/message/",
237                 self.admin_site.admin_view(EventMessage.as_view(admin=self)),
238                 name="events_event_message",
239             ),
240             path(
241                 "<int:pk>/mark-present-qr/",
242                 self.admin_site.admin_view(EventMarkPresentQR.as_view()),
243                 name="events_event_mark_present_qr",
244             ),
245         ]
246         return custom_urls + urls
247 
248     def get_field_queryset(self, db, db_field, request):
249         """Members without the can view as organiser permission can only assign their own groups as organiser."""
250         pk = resolve(request.path_info).kwargs["object_id"]
251         if db_field.name == "organisers" and not request.user.has_perm(
252             "events.override_organiser"
253         ):
254             return request.member.get_member_groups().union(
255                 MemberGroup.objects.filter(event_organiser__pk=pk)
256             )
257         return super().get_field_queryset(db, db_field, request)
258
```
--- 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/website/events/admin/event.py b/website/events/admin/event.py
--- a/website/events/admin/event.py
+++ b/website/events/admin/event.py
@@ -246,12 +246,15 @@
         return custom_urls + urls
 
     def get_field_queryset(self, db, db_field, request):
-        """Members without the can view as organiser permission can only assign their own groups as organiser."""
-        pk = resolve(request.path_info).kwargs["object_id"]
+        """Members without the 'can view as organiser' permission can only assign their own groups as organiser."""
+        pk = resolve(request.path_info).kwargs.get("object_id")
         if db_field.name == "organisers" and not request.user.has_perm(
             "events.override_organiser"
         ):
-            return request.member.get_member_groups().union(
-                MemberGroup.objects.filter(event_organiser__pk=pk)
-            )
+            if pk is None:
+                return request.member.get_member_groups()
+            else:
+                return request.member.get_member_groups().union(
+                    MemberGroup.objects.filter(event_organiser__pk=pk)
+                )
         return super().get_field_queryset(db, db_field, request)

{"golden_diff": "diff --git a/website/events/admin/event.py b/website/events/admin/event.py\n--- a/website/events/admin/event.py\n+++ b/website/events/admin/event.py\n@@ -246,12 +246,15 @@\n         return custom_urls + urls\n \n     def get_field_queryset(self, db, db_field, request):\n-        \"\"\"Members without the can view as organiser permission can only assign their own groups as organiser.\"\"\"\n-        pk = resolve(request.path_info).kwargs[\"object_id\"]\n+        \"\"\"Members without the 'can view as organiser' permission can only assign their own groups as organiser.\"\"\"\n+        pk = resolve(request.path_info).kwargs.get(\"object_id\")\n         if db_field.name == \"organisers\" and not request.user.has_perm(\n             \"events.override_organiser\"\n         ):\n-            return request.member.get_member_groups().union(\n-                MemberGroup.objects.filter(event_organiser__pk=pk)\n-            )\n+            if pk is None:\n+                return request.member.get_member_groups()\n+            else:\n+                return request.member.get_member_groups().union(\n+                    MemberGroup.objects.filter(event_organiser__pk=pk)\n+                )\n         return super().get_field_queryset(db, db_field, request)\n", "issue": "Cannot add events on staging/master\n### Describe the bug\r\n`KeyError at /admin/events/event/add/`\r\n\r\n### How to reproduce\r\nSteps to reproduce the behaviour:\r\n1. Go to admin\r\n2. Try to add event\r\n3. See error mentioned above\r\n\r\n### Expected behaviour\r\nGet the actual admin page\n", "before_files": [{"content": "\"\"\"Registers admin interfaces for the event model.\"\"\"\n\nfrom django.contrib import admin\nfrom django.db.models import Count, Q\nfrom django.template.defaultfilters import date as _date\nfrom django.urls import reverse, path, resolve\nfrom django.utils import timezone\nfrom django.utils.html import format_html\nfrom django.utils.translation import gettext_lazy as _\n\nfrom activemembers.models import MemberGroup\nfrom events import services\nfrom events import models\nfrom events.admin.filters import LectureYearFilter\nfrom events.admin.forms import RegistrationInformationFieldForm, EventAdminForm\nfrom events.admin.inlines import (\n    RegistrationInformationFieldInline,\n    PizzaEventInline,\n    PromotionRequestInline,\n)\nfrom events.admin.views import (\n    EventAdminDetails,\n    EventRegistrationsExport,\n    EventMessage,\n    EventMarkPresentQR,\n)\nfrom utils.admin import DoNextModelAdmin\n\n\n@admin.register(models.Event)\nclass EventAdmin(DoNextModelAdmin):\n    \"\"\"Manage the events.\"\"\"\n\n    form = EventAdminForm\n\n    inlines = (\n        RegistrationInformationFieldInline,\n        PizzaEventInline,\n        PromotionRequestInline,\n    )\n    list_display = (\n        \"overview_link\",\n        \"event_date\",\n        \"registration_date\",\n        \"num_participants\",\n        \"category\",\n        \"published\",\n        \"edit_link\",\n    )\n    list_display_links = (\"edit_link\",)\n    list_filter = (LectureYearFilter, \"start\", \"published\", \"category\")\n    actions = (\"make_published\", \"make_unpublished\")\n    date_hierarchy = \"start\"\n    search_fields = (\"title\", \"description\")\n    prepopulated_fields = {\"map_location\": (\"location\",)}\n    filter_horizontal = (\"documents\", \"organisers\")\n\n    fieldsets = (\n        (\n            _(\"General\"),\n            {\n                \"fields\": (\n                    \"title\",\n                    \"published\",\n                    \"organisers\",\n                )\n            },\n        ),\n        (\n            _(\"Detail\"),\n            {\n                \"fields\": (\n                    \"category\",\n                    \"start\",\n                    \"end\",\n                    \"description\",\n                    \"caption\",\n                    \"location\",\n                    \"map_location\",\n                ),\n                \"classes\": (\"collapse\", \"start-open\"),\n            },\n        ),\n        (\n            _(\"Registrations\"),\n            {\n                \"fields\": (\n                    \"price\",\n                    \"fine\",\n                    \"tpay_allowed\",\n                    \"max_participants\",\n                    \"registration_start\",\n                    \"registration_end\",\n                    \"cancel_deadline\",\n                    \"send_cancel_email\",\n                    \"optional_registrations\",\n                    \"no_registration_message\",\n                ),\n                \"classes\": (\"collapse\",),\n            },\n        ),\n        (\n            _(\"Extra\"),\n            {\"fields\": (\"slide\", \"documents\", \"shift\"), \"classes\": (\"collapse\",)},\n        ),\n    )\n\n    def get_queryset(self, request):\n        return (\n            super()\n            .get_queryset(request)\n            .annotate(\n                participant_count=Count(\n                    \"eventregistration\",\n                    filter=~Q(eventregistration__date_cancelled__lt=timezone.now()),\n                )\n            )\n        )\n\n    def get_form(self, request, obj=None, change=False, **kwargs):\n        form = super().get_form(request, obj, change, **kwargs)\n        form.clean = lambda form: form.instance.clean_changes(form.changed_data)\n        return form\n\n    def overview_link(self, obj):\n        return format_html(\n            '<a href=\"{link}\">{title}</a>',\n            link=reverse(\"admin:events_event_details\", kwargs={\"pk\": obj.pk}),\n            title=obj.title,\n        )\n\n    def has_change_permission(self, request, obj=None):\n        \"\"\"Only allow access to the change form if the user is an organiser.\"\"\"\n        if obj is not None and not services.is_organiser(request.member, obj):\n            return False\n        return super().has_change_permission(request, obj)\n\n    def event_date(self, obj):\n        event_date = timezone.make_naive(obj.start)\n        return _date(event_date, \"l d b Y, G:i\")\n\n    event_date.short_description = _(\"Event Date\")\n    event_date.admin_order_field = \"start\"\n\n    def registration_date(self, obj):\n        if obj.registration_start is not None:\n            start_date = timezone.make_naive(obj.registration_start)\n        else:\n            start_date = obj.registration_start\n\n        return _date(start_date, \"l d b Y, G:i\")\n\n    registration_date.short_description = _(\"Registration Start\")\n    registration_date.admin_order_field = \"registration_start\"\n\n    def edit_link(self, obj):\n        return _(\"Edit\")\n\n    edit_link.short_description = \"\"\n\n    def num_participants(self, obj):\n        \"\"\"Pretty-print the number of participants.\"\"\"\n        num = obj.participant_count  # from annotation\n        if not obj.max_participants:\n            return f\"{num}/\u221e\"\n        return f\"{num}/{obj.max_participants}\"\n\n    num_participants.short_description = _(\"Number of participants\")\n\n    def make_published(self, request, queryset):\n        \"\"\"Change the status of the event to published.\"\"\"\n        self._change_published(request, queryset, True)\n\n    make_published.short_description = _(\"Publish selected events\")\n\n    def make_unpublished(self, request, queryset):\n        \"\"\"Change the status of the event to unpublished.\"\"\"\n        self._change_published(request, queryset, False)\n\n    make_unpublished.short_description = _(\"Unpublish selected events\")\n\n    @staticmethod\n    def _change_published(request, queryset, published):\n        if not request.user.is_superuser:\n            queryset = queryset.filter(\n                organisers__in=request.member.get_member_groups()\n            )\n        queryset.update(published=published)\n\n    def save_formset(self, request, form, formset, change):\n        \"\"\"Save formsets with their order.\"\"\"\n        formset.save()\n\n        informationfield_forms = (\n            x\n            for x in formset.forms\n            if isinstance(x, RegistrationInformationFieldForm)\n            and \"DELETE\" not in x.changed_data\n        )\n        form.instance.set_registrationinformationfield_order(\n            [\n                f.instance.pk\n                for f in sorted(\n                    informationfield_forms,\n                    key=lambda x: (x.cleaned_data[\"order\"], x.instance.pk),\n                )\n            ]\n        )\n        form.instance.save()\n\n    def get_actions(self, request):\n        actions = super().get_actions(request)\n        if \"delete_selected\" in actions:\n            del actions[\"delete_selected\"]\n        return actions\n\n    def get_formsets_with_inlines(self, request, obj=None):\n        for inline in self.get_inline_instances(request, obj):\n            if self.has_change_permission(request, obj) or obj is None:\n                yield inline.get_formset(request, obj), inline\n\n    def get_urls(self):\n        urls = super().get_urls()\n        custom_urls = [\n            path(\n                \"<int:pk>/details/\",\n                self.admin_site.admin_view(EventAdminDetails.as_view()),\n                name=\"events_event_details\",\n            ),\n            path(\n                \"<int:pk>/export/\",\n                self.admin_site.admin_view(EventRegistrationsExport.as_view()),\n                name=\"events_event_export\",\n            ),\n            path(\n                \"<int:pk>/message/\",\n                self.admin_site.admin_view(EventMessage.as_view(admin=self)),\n                name=\"events_event_message\",\n            ),\n            path(\n                \"<int:pk>/mark-present-qr/\",\n                self.admin_site.admin_view(EventMarkPresentQR.as_view()),\n                name=\"events_event_mark_present_qr\",\n            ),\n        ]\n        return custom_urls + urls\n\n    def get_field_queryset(self, db, db_field, request):\n        \"\"\"Members without the can view as organiser permission can only assign their own groups as organiser.\"\"\"\n        pk = resolve(request.path_info).kwargs[\"object_id\"]\n        if db_field.name == \"organisers\" and not request.user.has_perm(\n            \"events.override_organiser\"\n        ):\n            return request.member.get_member_groups().union(\n                MemberGroup.objects.filter(event_organiser__pk=pk)\n            )\n        return super().get_field_queryset(db, db_field, request)\n", "path": "website/events/admin/event.py"}], "after_files": [{"content": "\"\"\"Registers admin interfaces for the event model.\"\"\"\n\nfrom django.contrib import admin\nfrom django.db.models import Count, Q\nfrom django.template.defaultfilters import date as _date\nfrom django.urls import reverse, path, resolve\nfrom django.utils import timezone\nfrom django.utils.html import format_html\nfrom django.utils.translation import gettext_lazy as _\n\nfrom activemembers.models import MemberGroup\nfrom events import services\nfrom events import models\nfrom events.admin.filters import LectureYearFilter\nfrom events.admin.forms import RegistrationInformationFieldForm, EventAdminForm\nfrom events.admin.inlines import (\n    RegistrationInformationFieldInline,\n    PizzaEventInline,\n    PromotionRequestInline,\n)\nfrom events.admin.views import (\n    EventAdminDetails,\n    EventRegistrationsExport,\n    EventMessage,\n    EventMarkPresentQR,\n)\nfrom utils.admin import DoNextModelAdmin\n\n\n@admin.register(models.Event)\nclass EventAdmin(DoNextModelAdmin):\n    \"\"\"Manage the events.\"\"\"\n\n    form = EventAdminForm\n\n    inlines = (\n        RegistrationInformationFieldInline,\n        PizzaEventInline,\n        PromotionRequestInline,\n    )\n    list_display = (\n        \"overview_link\",\n        \"event_date\",\n        \"registration_date\",\n        \"num_participants\",\n        \"category\",\n        \"published\",\n        \"edit_link\",\n    )\n    list_display_links = (\"edit_link\",)\n    list_filter = (LectureYearFilter, \"start\", \"published\", \"category\")\n    actions = (\"make_published\", \"make_unpublished\")\n    date_hierarchy = \"start\"\n    search_fields = (\"title\", \"description\")\n    prepopulated_fields = {\"map_location\": (\"location\",)}\n    filter_horizontal = (\"documents\", \"organisers\")\n\n    fieldsets = (\n        (\n            _(\"General\"),\n            {\n                \"fields\": (\n                    \"title\",\n                    \"published\",\n                    \"organisers\",\n                )\n            },\n        ),\n        (\n            _(\"Detail\"),\n            {\n                \"fields\": (\n                    \"category\",\n                    \"start\",\n                    \"end\",\n                    \"description\",\n                    \"caption\",\n                    \"location\",\n                    \"map_location\",\n                ),\n                \"classes\": (\"collapse\", \"start-open\"),\n            },\n        ),\n        (\n            _(\"Registrations\"),\n            {\n                \"fields\": (\n                    \"price\",\n                    \"fine\",\n                    \"tpay_allowed\",\n                    \"max_participants\",\n                    \"registration_start\",\n                    \"registration_end\",\n                    \"cancel_deadline\",\n                    \"send_cancel_email\",\n                    \"optional_registrations\",\n                    \"no_registration_message\",\n                ),\n                \"classes\": (\"collapse\",),\n            },\n        ),\n        (\n            _(\"Extra\"),\n            {\"fields\": (\"slide\", \"documents\", \"shift\"), \"classes\": (\"collapse\",)},\n        ),\n    )\n\n    def get_queryset(self, request):\n        return (\n            super()\n            .get_queryset(request)\n            .annotate(\n                participant_count=Count(\n                    \"eventregistration\",\n                    filter=~Q(eventregistration__date_cancelled__lt=timezone.now()),\n                )\n            )\n        )\n\n    def get_form(self, request, obj=None, change=False, **kwargs):\n        form = super().get_form(request, obj, change, **kwargs)\n        form.clean = lambda form: form.instance.clean_changes(form.changed_data)\n        return form\n\n    def overview_link(self, obj):\n        return format_html(\n            '<a href=\"{link}\">{title}</a>',\n            link=reverse(\"admin:events_event_details\", kwargs={\"pk\": obj.pk}),\n            title=obj.title,\n        )\n\n    def has_change_permission(self, request, obj=None):\n        \"\"\"Only allow access to the change form if the user is an organiser.\"\"\"\n        if obj is not None and not services.is_organiser(request.member, obj):\n            return False\n        return super().has_change_permission(request, obj)\n\n    def event_date(self, obj):\n        event_date = timezone.make_naive(obj.start)\n        return _date(event_date, \"l d b Y, G:i\")\n\n    event_date.short_description = _(\"Event Date\")\n    event_date.admin_order_field = \"start\"\n\n    def registration_date(self, obj):\n        if obj.registration_start is not None:\n            start_date = timezone.make_naive(obj.registration_start)\n        else:\n            start_date = obj.registration_start\n\n        return _date(start_date, \"l d b Y, G:i\")\n\n    registration_date.short_description = _(\"Registration Start\")\n    registration_date.admin_order_field = \"registration_start\"\n\n    def edit_link(self, obj):\n        return _(\"Edit\")\n\n    edit_link.short_description = \"\"\n\n    def num_participants(self, obj):\n        \"\"\"Pretty-print the number of participants.\"\"\"\n        num = obj.participant_count  # from annotation\n        if not obj.max_participants:\n            return f\"{num}/\u221e\"\n        return f\"{num}/{obj.max_participants}\"\n\n    num_participants.short_description = _(\"Number of participants\")\n\n    def make_published(self, request, queryset):\n        \"\"\"Change the status of the event to published.\"\"\"\n        self._change_published(request, queryset, True)\n\n    make_published.short_description = _(\"Publish selected events\")\n\n    def make_unpublished(self, request, queryset):\n        \"\"\"Change the status of the event to unpublished.\"\"\"\n        self._change_published(request, queryset, False)\n\n    make_unpublished.short_description = _(\"Unpublish selected events\")\n\n    @staticmethod\n    def _change_published(request, queryset, published):\n        if not request.user.is_superuser:\n            queryset = queryset.filter(\n                organisers__in=request.member.get_member_groups()\n            )\n        queryset.update(published=published)\n\n    def save_formset(self, request, form, formset, change):\n        \"\"\"Save formsets with their order.\"\"\"\n        formset.save()\n\n        informationfield_forms = (\n            x\n            for x in formset.forms\n            if isinstance(x, RegistrationInformationFieldForm)\n            and \"DELETE\" not in x.changed_data\n        )\n        form.instance.set_registrationinformationfield_order(\n            [\n                f.instance.pk\n                for f in sorted(\n                    informationfield_forms,\n                    key=lambda x: (x.cleaned_data[\"order\"], x.instance.pk),\n                )\n            ]\n        )\n        form.instance.save()\n\n    def get_actions(self, request):\n        actions = super().get_actions(request)\n        if \"delete_selected\" in actions:\n            del actions[\"delete_selected\"]\n        return actions\n\n    def get_formsets_with_inlines(self, request, obj=None):\n        for inline in self.get_inline_instances(request, obj):\n            if self.has_change_permission(request, obj) or obj is None:\n                yield inline.get_formset(request, obj), inline\n\n    def get_urls(self):\n        urls = super().get_urls()\n        custom_urls = [\n            path(\n                \"<int:pk>/details/\",\n                self.admin_site.admin_view(EventAdminDetails.as_view()),\n                name=\"events_event_details\",\n            ),\n            path(\n                \"<int:pk>/export/\",\n                self.admin_site.admin_view(EventRegistrationsExport.as_view()),\n                name=\"events_event_export\",\n            ),\n            path(\n                \"<int:pk>/message/\",\n                self.admin_site.admin_view(EventMessage.as_view(admin=self)),\n                name=\"events_event_message\",\n            ),\n            path(\n                \"<int:pk>/mark-present-qr/\",\n                self.admin_site.admin_view(EventMarkPresentQR.as_view()),\n                name=\"events_event_mark_present_qr\",\n            ),\n        ]\n        return custom_urls + urls\n\n    def get_field_queryset(self, db, db_field, request):\n        \"\"\"Members without the 'can view as organiser' permission can only assign their own groups as organiser.\"\"\"\n        pk = resolve(request.path_info).kwargs.get(\"object_id\")\n        if db_field.name == \"organisers\" and not request.user.has_perm(\n            \"events.override_organiser\"\n        ):\n            if pk is None:\n                return request.member.get_member_groups()\n            else:\n                return request.member.get_member_groups().union(\n                    MemberGroup.objects.filter(event_organiser__pk=pk)\n                )\n        return super().get_field_queryset(db, db_field, request)\n", "path": "website/events/admin/event.py"}]}