We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Filtering for POIs in event list not working
### Describe the Bug
<!-- A clear and concise description of what the bug is. -->
When filters for POIs in the event list are applied, all events are returned, independent from their location

### Steps to Reproduce

1. Go to event list
2. Filter for event location

### Expected Behavior
<!-- A clear and concise description of what you expected to happen. -->
Only the events with the selected location should be shown

### Actual Behavior
<!-- A clear and concise description of what actually happened. -->
All events are shown

### Additional Information
<!-- Add any other context (e.g. logs, screenshots, etc.) about the problem here. -->



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `integreat_cms/cms/views/events/event_form_view.py`
Content:
```
1 import logging
2 
3 from django.conf import settings
4 from django.contrib import messages
5 from django.core.exceptions import PermissionDenied
6 from django.shortcuts import render, redirect
7 from django.utils.decorators import method_decorator
8 from django.utils.translation import ugettext as _
9 from django.views.generic import TemplateView
10 
11 
12 from ...constants import status, translation_status
13 from ...decorators import permission_required
14 from ...forms import EventForm, EventTranslationForm, RecurrenceRuleForm
15 from ...models import Language, Event, EventTranslation, RecurrenceRule, POI
16 from .event_context_mixin import EventContextMixin
17 from ..media.media_context_mixin import MediaContextMixin
18 
19 
20 logger = logging.getLogger(__name__)
21 
22 
23 @method_decorator(permission_required("cms.view_event"), name="dispatch")
24 @method_decorator(permission_required("cms.change_event"), name="post")
25 class EventFormView(TemplateView, EventContextMixin, MediaContextMixin):
26     """
27     Class for rendering the events form
28     """
29 
30     #: The template to render (see :class:`~django.views.generic.base.TemplateResponseMixin`)
31     template_name = "events/event_form.html"
32     #: The context dict passed to the template (see :class:`~django.views.generic.base.ContextMixin`)
33     extra_context = {
34         "current_menu_item": "events_form",
35         "translation_status": translation_status,
36     }
37 
38     # pylint: disable=too-many-locals
39     def get(self, request, *args, **kwargs):
40         r"""
41         Render event form for HTTP GET requests
42 
43         :param request: Object representing the user call
44         :type request: ~django.http.HttpRequest
45 
46         :param \*args: The supplied arguments
47         :type \*args: list
48 
49         :param \**kwargs: The supplied keyword arguments
50         :type \**kwargs: dict
51 
52         :return: The rendered template response
53         :rtype: ~django.template.response.TemplateResponse
54         """
55         region = request.region
56         language = region.get_language_or_404(
57             kwargs.get("language_slug"), only_active=True
58         )
59 
60         # get event and event translation objects if they exist, otherwise objects are None
61         event_instance = region.events.filter(id=kwargs.get("event_id")).first()
62         event_translation_instance = language.event_translations.filter(
63             event=event_instance
64         ).first()
65         recurrence_rule_instance = RecurrenceRule.objects.filter(
66             event=event_instance
67         ).first()
68         poi_instance = region.pois.filter(events=event_instance).first()
69 
70         # Make form disabled if event is archived or user doesn't have the permission to edit the event
71         if event_instance and event_instance.archived:
72             disabled = True
73             messages.warning(
74                 request, _("You cannot edit this event because it is archived.")
75             )
76         elif not request.user.has_perm("cms.change_event"):
77             disabled = True
78             messages.warning(
79                 request, _("You don't have the permission to edit events.")
80             )
81         else:
82             disabled = False
83 
84         if not request.user.has_perm("cms.publish_event"):
85             messages.warning(
86                 request,
87                 _(
88                     "You don't have the permission to publish events, but you can propose changes and submit them for review instead."
89                 ),
90             )
91 
92         event_form = EventForm(instance=event_instance, disabled=disabled)
93         event_translation_form = EventTranslationForm(
94             instance=event_translation_instance, disabled=disabled
95         )
96         recurrence_rule_form = RecurrenceRuleForm(
97             instance=recurrence_rule_instance, disabled=disabled
98         )
99         url_link = f"{settings.WEBAPP_URL}/{region.slug}/{language.slug}/events/"
100         return render(
101             request,
102             self.template_name,
103             {
104                 **self.get_context_data(**kwargs),
105                 "event_form": event_form,
106                 "event_translation_form": event_translation_form,
107                 "recurrence_rule_form": recurrence_rule_form,
108                 "poi": poi_instance,
109                 "language": language,
110                 "languages": region.active_languages if event_instance else [language],
111                 "url_link": url_link,
112                 "translation_states": event_instance.translation_states
113                 if event_instance
114                 else [],
115             },
116         )
117 
118     # pylint: disable=too-many-locals,too-many-branches
119     def post(self, request, **kwargs):
120         r"""
121         Save event and ender event form for HTTP POST requests
122 
123         :param request: Object representing the user call
124         :type request: ~django.http.HttpRequest
125 
126         :param \**kwargs: The supplied keyword arguments
127         :type \**kwargs: dict
128 
129         :raises ~django.core.exceptions.PermissionDenied: If user does not have the permission to publish events
130 
131         :return: The rendered template response
132         :rtype: ~django.template.response.TemplateResponse
133         """
134         region = request.region
135         language = Language.objects.get(slug=kwargs.get("language_slug"))
136         poi = POI.objects.filter(id=request.POST.get("location")).first()
137 
138         event_instance = Event.objects.filter(id=kwargs.get("event_id")).first()
139         recurrence_rule_instance = RecurrenceRule.objects.filter(
140             event=event_instance
141         ).first()
142         event_translation_instance = EventTranslation.objects.filter(
143             event=event_instance, language=language
144         ).first()
145 
146         event_form = EventForm(
147             data=request.POST,
148             files=request.FILES,
149             instance=event_instance,
150             additional_instance_attributes={"region": region, "location": poi},
151         )
152         # clean data of event form to be able to pass the cleaned start date to the recurrence form for validation
153         event_form_valid = event_form.is_valid()
154         recurrence_rule_form = RecurrenceRuleForm(
155             data=request.POST,
156             instance=recurrence_rule_instance,
157             event_start_date=event_form.cleaned_data.get("start_date", None),
158         )
159         event_translation_form = EventTranslationForm(
160             data=request.POST,
161             instance=event_translation_instance,
162             additional_instance_attributes={
163                 "creator": request.user,
164                 "language": language,
165                 "event": event_form.instance,
166             },
167         )
168 
169         if (
170             not event_form_valid
171             or not event_translation_form.is_valid()
172             or (
173                 event_form.cleaned_data["is_recurring"]
174                 and not recurrence_rule_form.is_valid()
175             )
176         ):
177             # Add error messages
178             event_form.add_error_messages(request)
179             event_translation_form.add_error_messages(request)
180             # do not call recurrence rule form clean method when recurrence rule is not set
181             if event_form.cleaned_data["is_recurring"]:
182                 recurrence_rule_form.add_error_messages(request)
183         elif (
184             event_translation_form.instance.status == status.AUTO_SAVE
185             and not event_form.has_changed()
186             and not event_translation_form.has_changed()
187             and not recurrence_rule_form.has_changed()
188         ):
189             messages.info(request, _("No changes detected, autosave skipped"))
190         else:
191             # Check publish permissions
192             if event_translation_form.instance.status == status.PUBLIC:
193                 if not request.user.has_perm("cms.publish_event"):
194                     raise PermissionDenied(
195                         f"{request.user!r} does not have the permission 'cms.publish_event'"
196                     )
197             # Save forms
198             if event_form.cleaned_data.get("is_recurring"):
199                 # If event is recurring, save recurrence rule
200                 event_form.instance.recurrence_rule = recurrence_rule_form.save()
201             elif event_form.instance.recurrence_rule:
202                 # If the event is not recurring but it was before, delete the associated recurrence rule
203                 event_form.instance.recurrence_rule.delete()
204                 event_form.instance.recurrence_rule = None
205             event_translation_form.instance.event = event_form.save()
206             event_translation_form.save()
207             # Add the success message and redirect to the edit page
208             if not event_instance:
209                 messages.success(
210                     request,
211                     _('Event "{}" was successfully created').format(
212                         event_translation_form.instance
213                     ),
214                 )
215             elif (
216                 not event_form.has_changed()
217                 and not event_translation_form.has_changed()
218                 and not recurrence_rule_form.has_changed()
219             ):
220                 messages.info(request, _("No changes detected, but date refreshed"))
221             else:
222                 # Add the success message
223                 event_translation_form.add_success_message(request)
224             return redirect(
225                 "edit_event",
226                 **{
227                     "event_id": event_form.instance.id,
228                     "region_slug": region.slug,
229                     "language_slug": language.slug,
230                 },
231             )
232 
233         return render(
234             request,
235             self.template_name,
236             {
237                 **self.get_context_data(**kwargs),
238                 "event_form": event_form,
239                 "event_translation_form": event_translation_form,
240                 "recurrence_rule_form": recurrence_rule_form,
241                 "poi": poi,
242                 "language": language,
243                 "languages": region.active_languages if event_instance else [language],
244                 "translation_states": event_instance.translation_states
245                 if event_instance
246                 else [],
247             },
248         )
249
```
--- 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/integreat_cms/cms/views/events/event_form_view.py b/integreat_cms/cms/views/events/event_form_view.py
--- a/integreat_cms/cms/views/events/event_form_view.py
+++ b/integreat_cms/cms/views/events/event_form_view.py
@@ -65,7 +65,10 @@
         recurrence_rule_instance = RecurrenceRule.objects.filter(
             event=event_instance
         ).first()
-        poi_instance = region.pois.filter(events=event_instance).first()
+        if event_instance:
+            poi_instance = event_instance.location
+        else:
+            poi_instance = None
 
         # Make form disabled if event is archived or user doesn't have the permission to edit the event
         if event_instance and event_instance.archived:

{"golden_diff": "diff --git a/integreat_cms/cms/views/events/event_form_view.py b/integreat_cms/cms/views/events/event_form_view.py\n--- a/integreat_cms/cms/views/events/event_form_view.py\n+++ b/integreat_cms/cms/views/events/event_form_view.py\n@@ -65,7 +65,10 @@\n         recurrence_rule_instance = RecurrenceRule.objects.filter(\n             event=event_instance\n         ).first()\n-        poi_instance = region.pois.filter(events=event_instance).first()\n+        if event_instance:\n+            poi_instance = event_instance.location\n+        else:\n+            poi_instance = None\n \n         # Make form disabled if event is archived or user doesn't have the permission to edit the event\n         if event_instance and event_instance.archived:\n", "issue": "Filtering for POIs in event list not working\n### Describe the Bug\r\n<!-- A clear and concise description of what the bug is. -->\r\nWhen filters for POIs in the event list are applied, all events are returned, independent from their location\r\n\r\n### Steps to Reproduce\r\n\r\n1. Go to event list\r\n2. Filter for event location\r\n\r\n### Expected Behavior\r\n<!-- A clear and concise description of what you expected to happen. -->\r\nOnly the events with the selected location should be shown\r\n\r\n### Actual Behavior\r\n<!-- A clear and concise description of what actually happened. -->\r\nAll events are shown\r\n\r\n### Additional Information\r\n<!-- Add any other context (e.g. logs, screenshots, etc.) about the problem here. -->\r\n\r\n\n", "before_files": [{"content": "import logging\n\nfrom django.conf import settings\nfrom django.contrib import messages\nfrom django.core.exceptions import PermissionDenied\nfrom django.shortcuts import render, redirect\nfrom django.utils.decorators import method_decorator\nfrom django.utils.translation import ugettext as _\nfrom django.views.generic import TemplateView\n\n\nfrom ...constants import status, translation_status\nfrom ...decorators import permission_required\nfrom ...forms import EventForm, EventTranslationForm, RecurrenceRuleForm\nfrom ...models import Language, Event, EventTranslation, RecurrenceRule, POI\nfrom .event_context_mixin import EventContextMixin\nfrom ..media.media_context_mixin import MediaContextMixin\n\n\nlogger = logging.getLogger(__name__)\n\n\n@method_decorator(permission_required(\"cms.view_event\"), name=\"dispatch\")\n@method_decorator(permission_required(\"cms.change_event\"), name=\"post\")\nclass EventFormView(TemplateView, EventContextMixin, MediaContextMixin):\n    \"\"\"\n    Class for rendering the events form\n    \"\"\"\n\n    #: The template to render (see :class:`~django.views.generic.base.TemplateResponseMixin`)\n    template_name = \"events/event_form.html\"\n    #: The context dict passed to the template (see :class:`~django.views.generic.base.ContextMixin`)\n    extra_context = {\n        \"current_menu_item\": \"events_form\",\n        \"translation_status\": translation_status,\n    }\n\n    # pylint: disable=too-many-locals\n    def get(self, request, *args, **kwargs):\n        r\"\"\"\n        Render event form for HTTP GET requests\n\n        :param request: Object representing the user call\n        :type request: ~django.http.HttpRequest\n\n        :param \\*args: The supplied arguments\n        :type \\*args: list\n\n        :param \\**kwargs: The supplied keyword arguments\n        :type \\**kwargs: dict\n\n        :return: The rendered template response\n        :rtype: ~django.template.response.TemplateResponse\n        \"\"\"\n        region = request.region\n        language = region.get_language_or_404(\n            kwargs.get(\"language_slug\"), only_active=True\n        )\n\n        # get event and event translation objects if they exist, otherwise objects are None\n        event_instance = region.events.filter(id=kwargs.get(\"event_id\")).first()\n        event_translation_instance = language.event_translations.filter(\n            event=event_instance\n        ).first()\n        recurrence_rule_instance = RecurrenceRule.objects.filter(\n            event=event_instance\n        ).first()\n        poi_instance = region.pois.filter(events=event_instance).first()\n\n        # Make form disabled if event is archived or user doesn't have the permission to edit the event\n        if event_instance and event_instance.archived:\n            disabled = True\n            messages.warning(\n                request, _(\"You cannot edit this event because it is archived.\")\n            )\n        elif not request.user.has_perm(\"cms.change_event\"):\n            disabled = True\n            messages.warning(\n                request, _(\"You don't have the permission to edit events.\")\n            )\n        else:\n            disabled = False\n\n        if not request.user.has_perm(\"cms.publish_event\"):\n            messages.warning(\n                request,\n                _(\n                    \"You don't have the permission to publish events, but you can propose changes and submit them for review instead.\"\n                ),\n            )\n\n        event_form = EventForm(instance=event_instance, disabled=disabled)\n        event_translation_form = EventTranslationForm(\n            instance=event_translation_instance, disabled=disabled\n        )\n        recurrence_rule_form = RecurrenceRuleForm(\n            instance=recurrence_rule_instance, disabled=disabled\n        )\n        url_link = f\"{settings.WEBAPP_URL}/{region.slug}/{language.slug}/events/\"\n        return render(\n            request,\n            self.template_name,\n            {\n                **self.get_context_data(**kwargs),\n                \"event_form\": event_form,\n                \"event_translation_form\": event_translation_form,\n                \"recurrence_rule_form\": recurrence_rule_form,\n                \"poi\": poi_instance,\n                \"language\": language,\n                \"languages\": region.active_languages if event_instance else [language],\n                \"url_link\": url_link,\n                \"translation_states\": event_instance.translation_states\n                if event_instance\n                else [],\n            },\n        )\n\n    # pylint: disable=too-many-locals,too-many-branches\n    def post(self, request, **kwargs):\n        r\"\"\"\n        Save event and ender event form for HTTP POST requests\n\n        :param request: Object representing the user call\n        :type request: ~django.http.HttpRequest\n\n        :param \\**kwargs: The supplied keyword arguments\n        :type \\**kwargs: dict\n\n        :raises ~django.core.exceptions.PermissionDenied: If user does not have the permission to publish events\n\n        :return: The rendered template response\n        :rtype: ~django.template.response.TemplateResponse\n        \"\"\"\n        region = request.region\n        language = Language.objects.get(slug=kwargs.get(\"language_slug\"))\n        poi = POI.objects.filter(id=request.POST.get(\"location\")).first()\n\n        event_instance = Event.objects.filter(id=kwargs.get(\"event_id\")).first()\n        recurrence_rule_instance = RecurrenceRule.objects.filter(\n            event=event_instance\n        ).first()\n        event_translation_instance = EventTranslation.objects.filter(\n            event=event_instance, language=language\n        ).first()\n\n        event_form = EventForm(\n            data=request.POST,\n            files=request.FILES,\n            instance=event_instance,\n            additional_instance_attributes={\"region\": region, \"location\": poi},\n        )\n        # clean data of event form to be able to pass the cleaned start date to the recurrence form for validation\n        event_form_valid = event_form.is_valid()\n        recurrence_rule_form = RecurrenceRuleForm(\n            data=request.POST,\n            instance=recurrence_rule_instance,\n            event_start_date=event_form.cleaned_data.get(\"start_date\", None),\n        )\n        event_translation_form = EventTranslationForm(\n            data=request.POST,\n            instance=event_translation_instance,\n            additional_instance_attributes={\n                \"creator\": request.user,\n                \"language\": language,\n                \"event\": event_form.instance,\n            },\n        )\n\n        if (\n            not event_form_valid\n            or not event_translation_form.is_valid()\n            or (\n                event_form.cleaned_data[\"is_recurring\"]\n                and not recurrence_rule_form.is_valid()\n            )\n        ):\n            # Add error messages\n            event_form.add_error_messages(request)\n            event_translation_form.add_error_messages(request)\n            # do not call recurrence rule form clean method when recurrence rule is not set\n            if event_form.cleaned_data[\"is_recurring\"]:\n                recurrence_rule_form.add_error_messages(request)\n        elif (\n            event_translation_form.instance.status == status.AUTO_SAVE\n            and not event_form.has_changed()\n            and not event_translation_form.has_changed()\n            and not recurrence_rule_form.has_changed()\n        ):\n            messages.info(request, _(\"No changes detected, autosave skipped\"))\n        else:\n            # Check publish permissions\n            if event_translation_form.instance.status == status.PUBLIC:\n                if not request.user.has_perm(\"cms.publish_event\"):\n                    raise PermissionDenied(\n                        f\"{request.user!r} does not have the permission 'cms.publish_event'\"\n                    )\n            # Save forms\n            if event_form.cleaned_data.get(\"is_recurring\"):\n                # If event is recurring, save recurrence rule\n                event_form.instance.recurrence_rule = recurrence_rule_form.save()\n            elif event_form.instance.recurrence_rule:\n                # If the event is not recurring but it was before, delete the associated recurrence rule\n                event_form.instance.recurrence_rule.delete()\n                event_form.instance.recurrence_rule = None\n            event_translation_form.instance.event = event_form.save()\n            event_translation_form.save()\n            # Add the success message and redirect to the edit page\n            if not event_instance:\n                messages.success(\n                    request,\n                    _('Event \"{}\" was successfully created').format(\n                        event_translation_form.instance\n                    ),\n                )\n            elif (\n                not event_form.has_changed()\n                and not event_translation_form.has_changed()\n                and not recurrence_rule_form.has_changed()\n            ):\n                messages.info(request, _(\"No changes detected, but date refreshed\"))\n            else:\n                # Add the success message\n                event_translation_form.add_success_message(request)\n            return redirect(\n                \"edit_event\",\n                **{\n                    \"event_id\": event_form.instance.id,\n                    \"region_slug\": region.slug,\n                    \"language_slug\": language.slug,\n                },\n            )\n\n        return render(\n            request,\n            self.template_name,\n            {\n                **self.get_context_data(**kwargs),\n                \"event_form\": event_form,\n                \"event_translation_form\": event_translation_form,\n                \"recurrence_rule_form\": recurrence_rule_form,\n                \"poi\": poi,\n                \"language\": language,\n                \"languages\": region.active_languages if event_instance else [language],\n                \"translation_states\": event_instance.translation_states\n                if event_instance\n                else [],\n            },\n        )\n", "path": "integreat_cms/cms/views/events/event_form_view.py"}], "after_files": [{"content": "import logging\n\nfrom django.conf import settings\nfrom django.contrib import messages\nfrom django.core.exceptions import PermissionDenied\nfrom django.shortcuts import render, redirect\nfrom django.utils.decorators import method_decorator\nfrom django.utils.translation import ugettext as _\nfrom django.views.generic import TemplateView\n\n\nfrom ...constants import status, translation_status\nfrom ...decorators import permission_required\nfrom ...forms import EventForm, EventTranslationForm, RecurrenceRuleForm\nfrom ...models import Language, Event, EventTranslation, RecurrenceRule, POI\nfrom .event_context_mixin import EventContextMixin\nfrom ..media.media_context_mixin import MediaContextMixin\n\n\nlogger = logging.getLogger(__name__)\n\n\n@method_decorator(permission_required(\"cms.view_event\"), name=\"dispatch\")\n@method_decorator(permission_required(\"cms.change_event\"), name=\"post\")\nclass EventFormView(TemplateView, EventContextMixin, MediaContextMixin):\n    \"\"\"\n    Class for rendering the events form\n    \"\"\"\n\n    #: The template to render (see :class:`~django.views.generic.base.TemplateResponseMixin`)\n    template_name = \"events/event_form.html\"\n    #: The context dict passed to the template (see :class:`~django.views.generic.base.ContextMixin`)\n    extra_context = {\n        \"current_menu_item\": \"events_form\",\n        \"translation_status\": translation_status,\n    }\n\n    # pylint: disable=too-many-locals\n    def get(self, request, *args, **kwargs):\n        r\"\"\"\n        Render event form for HTTP GET requests\n\n        :param request: Object representing the user call\n        :type request: ~django.http.HttpRequest\n\n        :param \\*args: The supplied arguments\n        :type \\*args: list\n\n        :param \\**kwargs: The supplied keyword arguments\n        :type \\**kwargs: dict\n\n        :return: The rendered template response\n        :rtype: ~django.template.response.TemplateResponse\n        \"\"\"\n        region = request.region\n        language = region.get_language_or_404(\n            kwargs.get(\"language_slug\"), only_active=True\n        )\n\n        # get event and event translation objects if they exist, otherwise objects are None\n        event_instance = region.events.filter(id=kwargs.get(\"event_id\")).first()\n        event_translation_instance = language.event_translations.filter(\n            event=event_instance\n        ).first()\n        recurrence_rule_instance = RecurrenceRule.objects.filter(\n            event=event_instance\n        ).first()\n        if event_instance:\n            poi_instance = event_instance.location\n        else:\n            poi_instance = None\n\n        # Make form disabled if event is archived or user doesn't have the permission to edit the event\n        if event_instance and event_instance.archived:\n            disabled = True\n            messages.warning(\n                request, _(\"You cannot edit this event because it is archived.\")\n            )\n        elif not request.user.has_perm(\"cms.change_event\"):\n            disabled = True\n            messages.warning(\n                request, _(\"You don't have the permission to edit events.\")\n            )\n        else:\n            disabled = False\n\n        if not request.user.has_perm(\"cms.publish_event\"):\n            messages.warning(\n                request,\n                _(\n                    \"You don't have the permission to publish events, but you can propose changes and submit them for review instead.\"\n                ),\n            )\n\n        event_form = EventForm(instance=event_instance, disabled=disabled)\n        event_translation_form = EventTranslationForm(\n            instance=event_translation_instance, disabled=disabled\n        )\n        recurrence_rule_form = RecurrenceRuleForm(\n            instance=recurrence_rule_instance, disabled=disabled\n        )\n        url_link = f\"{settings.WEBAPP_URL}/{region.slug}/{language.slug}/events/\"\n        return render(\n            request,\n            self.template_name,\n            {\n                **self.get_context_data(**kwargs),\n                \"event_form\": event_form,\n                \"event_translation_form\": event_translation_form,\n                \"recurrence_rule_form\": recurrence_rule_form,\n                \"poi\": poi_instance,\n                \"language\": language,\n                \"languages\": region.active_languages if event_instance else [language],\n                \"url_link\": url_link,\n                \"translation_states\": event_instance.translation_states\n                if event_instance\n                else [],\n            },\n        )\n\n    # pylint: disable=too-many-locals,too-many-branches\n    def post(self, request, **kwargs):\n        r\"\"\"\n        Save event and ender event form for HTTP POST requests\n\n        :param request: Object representing the user call\n        :type request: ~django.http.HttpRequest\n\n        :param \\**kwargs: The supplied keyword arguments\n        :type \\**kwargs: dict\n\n        :raises ~django.core.exceptions.PermissionDenied: If user does not have the permission to publish events\n\n        :return: The rendered template response\n        :rtype: ~django.template.response.TemplateResponse\n        \"\"\"\n        region = request.region\n        language = Language.objects.get(slug=kwargs.get(\"language_slug\"))\n        poi = POI.objects.filter(id=request.POST.get(\"location\")).first()\n\n        event_instance = Event.objects.filter(id=kwargs.get(\"event_id\")).first()\n        recurrence_rule_instance = RecurrenceRule.objects.filter(\n            event=event_instance\n        ).first()\n        event_translation_instance = EventTranslation.objects.filter(\n            event=event_instance, language=language\n        ).first()\n\n        event_form = EventForm(\n            data=request.POST,\n            files=request.FILES,\n            instance=event_instance,\n            additional_instance_attributes={\"region\": region, \"location\": poi},\n        )\n        # clean data of event form to be able to pass the cleaned start date to the recurrence form for validation\n        event_form_valid = event_form.is_valid()\n        recurrence_rule_form = RecurrenceRuleForm(\n            data=request.POST,\n            instance=recurrence_rule_instance,\n            event_start_date=event_form.cleaned_data.get(\"start_date\", None),\n        )\n        event_translation_form = EventTranslationForm(\n            data=request.POST,\n            instance=event_translation_instance,\n            additional_instance_attributes={\n                \"creator\": request.user,\n                \"language\": language,\n                \"event\": event_form.instance,\n            },\n        )\n\n        if (\n            not event_form_valid\n            or not event_translation_form.is_valid()\n            or (\n                event_form.cleaned_data[\"is_recurring\"]\n                and not recurrence_rule_form.is_valid()\n            )\n        ):\n            # Add error messages\n            event_form.add_error_messages(request)\n            event_translation_form.add_error_messages(request)\n            # do not call recurrence rule form clean method when recurrence rule is not set\n            if event_form.cleaned_data[\"is_recurring\"]:\n                recurrence_rule_form.add_error_messages(request)\n        elif (\n            event_translation_form.instance.status == status.AUTO_SAVE\n            and not event_form.has_changed()\n            and not event_translation_form.has_changed()\n            and not recurrence_rule_form.has_changed()\n        ):\n            messages.info(request, _(\"No changes detected, autosave skipped\"))\n        else:\n            # Check publish permissions\n            if event_translation_form.instance.status == status.PUBLIC:\n                if not request.user.has_perm(\"cms.publish_event\"):\n                    raise PermissionDenied(\n                        f\"{request.user!r} does not have the permission 'cms.publish_event'\"\n                    )\n            # Save forms\n            if event_form.cleaned_data.get(\"is_recurring\"):\n                # If event is recurring, save recurrence rule\n                event_form.instance.recurrence_rule = recurrence_rule_form.save()\n            elif event_form.instance.recurrence_rule:\n                # If the event is not recurring but it was before, delete the associated recurrence rule\n                event_form.instance.recurrence_rule.delete()\n                event_form.instance.recurrence_rule = None\n            event_translation_form.instance.event = event_form.save()\n            event_translation_form.save()\n            # Add the success message and redirect to the edit page\n            if not event_instance:\n                messages.success(\n                    request,\n                    _('Event \"{}\" was successfully created').format(\n                        event_translation_form.instance\n                    ),\n                )\n            elif (\n                not event_form.has_changed()\n                and not event_translation_form.has_changed()\n                and not recurrence_rule_form.has_changed()\n            ):\n                messages.info(request, _(\"No changes detected, but date refreshed\"))\n            else:\n                # Add the success message\n                event_translation_form.add_success_message(request)\n            return redirect(\n                \"edit_event\",\n                **{\n                    \"event_id\": event_form.instance.id,\n                    \"region_slug\": region.slug,\n                    \"language_slug\": language.slug,\n                },\n            )\n\n        return render(\n            request,\n            self.template_name,\n            {\n                **self.get_context_data(**kwargs),\n                \"event_form\": event_form,\n                \"event_translation_form\": event_translation_form,\n                \"recurrence_rule_form\": recurrence_rule_form,\n                \"poi\": poi,\n                \"language\": language,\n                \"languages\": region.active_languages if event_instance else [language],\n                \"translation_states\": event_instance.translation_states\n                if event_instance\n                else [],\n            },\n        )\n", "path": "integreat_cms/cms/views/events/event_form_view.py"}]}