We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
deleting a room, which is in use yields ProtectedError
When you try to delete a room, which has talks assigned to it the app displays an ProtectedError. This can probably be handled it [deleting a submission type](https://github.com/openeventstack/pretalx/blob/master/src/pretalx/orga/views/cfp.py#L147-L152).

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/pretalx/orga/views/settings.py`
Content:
```
1 import string
2 
3 from django.contrib import messages
4 from django.contrib.auth import login
5 from django.core.exceptions import PermissionDenied
6 from django.shortcuts import redirect
7 from django.urls import reverse
8 from django.utils.crypto import get_random_string
9 from django.utils.functional import cached_property
10 from django.utils.translation import ugettext_lazy as _
11 from django.views.generic import FormView, TemplateView, View
12 
13 from pretalx.common.mail import mail_send_task
14 from pretalx.common.urls import build_absolute_uri
15 from pretalx.common.views import ActionFromUrl, CreateOrUpdateView
16 from pretalx.event.models import Event
17 from pretalx.orga.forms import EventForm
18 from pretalx.orga.forms.event import MailSettingsForm
19 from pretalx.person.forms import LoginInfoForm, UserForm, OrgaProfileForm
20 from pretalx.person.models import EventPermission, User
21 from pretalx.schedule.forms import RoomForm
22 from pretalx.schedule.models import Room
23 
24 
25 class EventDetail(ActionFromUrl, CreateOrUpdateView):
26     model = Event
27     form_class = EventForm
28     template_name = 'orga/settings/form.html'
29 
30     def dispatch(self, request, *args, **kwargs):
31         if self._action == 'create':
32             if not request.user.is_anonymous and not request.user.is_superuser:
33                 raise PermissionDenied()
34         return super().dispatch(request, *args, **kwargs)
35 
36     def get_object(self):
37         try:
38             return self.request.event
39         except AttributeError:
40             return
41 
42     def get_success_url(self) -> str:
43         return self.object.orga_urls.settings
44 
45     def form_valid(self, form):
46         new_event = not bool(form.instance.pk)
47         ret = super().form_valid(form)
48         if new_event:
49             messages.success(self.request, _('Yay, a new event! Check the settings and configure a CfP and you\'re good to go!'))
50             form.instance.log_action('pretalx.event.create', person=self.request.user, orga=True)
51             EventPermission.objects.create(
52                 event=form.instance,
53                 user=self.request.user,
54                 is_orga=True,
55             )
56         else:
57             form.instance.log_action('pretalx.event.update', person=self.request.user, orga=True)
58             messages.success(self.request, _('The event settings have been saved.'))
59         return ret
60 
61 
62 class EventMailSettings(ActionFromUrl, FormView):
63     form_class = MailSettingsForm
64     template_name = 'orga/settings/mail.html'
65 
66     def get_success_url(self) -> str:
67         return self.request.event.orga_urls.mail_settings
68 
69     def get_form_kwargs(self):
70         kwargs = super().get_form_kwargs()
71         kwargs['obj'] = self.request.event
72         kwargs['attribute_name'] = 'settings'
73         kwargs['locales'] = self.request.event.locales
74         return kwargs
75 
76     def form_valid(self, form):
77         form.save()
78 
79         if self.request.POST.get('test', '0').strip() == '1':
80             backend = self.request.event.get_mail_backend(force_custom=True)
81             try:
82                 backend.test(self.request.event.settings.mail_from)
83             except Exception as e:
84                 messages.warning(self.request, _('An error occured while contacting the SMTP server: %s') % str(e))
85                 return redirect(reverse('orga:settings.mail.edit', kwargs={'event': self.request.event.slug}))
86             else:
87                 if form.cleaned_data.get('smtp_use_custom'):
88                     messages.success(self.request, _('Yay, your changes have been saved and the connection attempt to '
89                                                      'your SMTP server was successful.'))
90                 else:
91                     messages.success(self.request, _('We\'ve been able to contact the SMTP server you configured. '
92                                                      'Remember to check the "use custom SMTP server" checkbox, '
93                                                      'otherwise your SMTP server will not be used.'))
94         else:
95             messages.success(self.request, _('Yay! We saved your changes.'))
96 
97         ret = super().form_valid(form)
98         return ret
99 
100 
101 class EventTeam(TemplateView):
102     template_name = 'orga/settings/team.html'
103 
104     def get_context_data(self, *args, **kwargs):
105         ctx = super().get_context_data(*args, **kwargs)
106         event = self.request.event
107         ctx['team'] = User.objects.filter(
108             permissions__is_orga=True,
109             permissions__event=event,
110         )
111         ctx['pending'] = EventPermission.objects.filter(event=event, user__isnull=True, is_orga=True)
112         return ctx
113 
114 
115 class EventTeamInvite(View):
116 
117     def post(self, request, event):
118         email = request.POST.get('email')
119         event = request.event
120         invitation_token = get_random_string(allowed_chars=string.ascii_lowercase + string.digits, length=20)
121         invitation_link = build_absolute_uri('orga:invitation.view', kwargs={'code': invitation_token})
122         EventPermission.objects.create(
123             event=event,
124             invitation_email=email,
125             invitation_token=invitation_token,
126             is_orga=True,
127         )
128         invitation_text = _('''Hi!
129 
130 You have been invited to the orga crew of {event} - Please click here to accept:
131 
132     {invitation_link}
133 
134 See you there,
135 The {event} orga crew (minus you)''').format(event=event.name, invitation_link=invitation_link)
136         mail_send_task.apply_async(args=(
137             [email],
138             _('You have been invited to the orga crew of {event}').format(event=request.event.name),
139             invitation_text,
140             request.event.email,
141             event.pk
142         ))
143         request.event.log_action('pretalx.event.invite.orga.send', person=request.user, orga=True)
144         messages.success(
145             request,
146             _('<{email}> has been invited to your team - more team members help distribute the workload, so … yay!').format(email=email)
147         )
148         return redirect(request.event.orga_urls.team_settings)
149 
150 
151 class EventTeamRetract(View):
152 
153     def dispatch(self, request, event, pk):
154         EventPermission.objects.filter(event=request.event, pk=pk).delete()
155         request.event.log_action('pretalx.event.invite.orga.retract', person=request.user, orga=True)
156         return redirect(request.event.orga_urls.team_settings)
157 
158 
159 class EventTeamDelete(View):
160 
161     def dispatch(self, request, event, pk):
162         EventPermission.objects.filter(event=request.event, user__id=pk).update(is_orga=False)
163         return redirect(request.event.orga_urls.team_settings)
164 
165 
166 class InvitationView(FormView):
167     template_name = 'orga/invitation.html'
168     form_class = UserForm
169 
170     def get_context_data(self, *args, **kwargs):
171         ctx = super().get_context_data(*args, **kwargs)
172         ctx['invitation'] = EventPermission.objects.get(
173             invitation_token=self.kwargs.get('code'),
174         )
175         return ctx
176 
177     def form_valid(self, form):
178         form.save()
179         permission = EventPermission.objects.get(invitation_token=self.kwargs.get('code'))
180         user = User.objects.get(pk=form.cleaned_data.get('user_id'))
181 
182         permission.is_orga = True
183         permission.user = user
184         permission.save()
185         permission.event.log_action('pretalx.event.invite.orga.accept', person=user, orga=True)
186         login(self.request, user)
187         return redirect(permission.event.orga_urls.base)
188 
189 
190 class UserSettings(TemplateView):
191     form_class = LoginInfoForm
192     template_name = 'orga/user.html'
193 
194     def get_success_url(self) -> str:
195         return reverse('orga:user.view')
196 
197     @cached_property
198     def login_form(self):
199         return LoginInfoForm(user=self.request.user,
200                              data=(self.request.POST
201                                    if self.request.method == 'POST' and self.request.POST.get('form') == 'login'
202                                    else None))
203 
204     @cached_property
205     def profile_form(self):
206         return OrgaProfileForm(instance=self.request.user,
207                                data=(self.request.POST
208                                      if self.request.method == 'POST' and self.request.POST.get('form') == 'profile'
209                                      else None))
210 
211     def get_context_data(self, **kwargs):
212         ctx = super().get_context_data(**kwargs)
213         ctx['login_form'] = self.login_form
214         ctx['profile_form'] = self.profile_form
215         return ctx
216 
217     def post(self, request, *args, **kwargs):
218         if self.login_form.is_bound:
219             if self.login_form.is_valid():
220                 self.login_form.save()
221                 messages.success(request, _('Your changes have been saved.'))
222                 request.user.log_action('pretalx.user.password.update')
223                 return redirect(self.get_success_url())
224         elif self.profile_form.is_bound:
225             if self.profile_form.is_valid():
226                 self.profile_form.save()
227                 messages.success(request, _('Your changes have been saved.'))
228                 request.user.log_action('pretalx.user.profile.update')
229                 return redirect(self.get_success_url())
230 
231         messages.error(self.request, _('Oh :( We had trouble saving your input. See below for details.'))
232         return super().get(request, *args, **kwargs)
233 
234 
235 class RoomList(TemplateView):
236     template_name = 'orga/settings/room_list.html'
237 
238 
239 class RoomDelete(View):
240 
241     def dispatch(self, request, event, pk):
242         request.event.rooms.get(pk=pk).delete()
243         messages.success(self.request, _('Room deleted. Hopefully nobody was still in there …'))
244         return redirect(request.event.orga_urls.room_settings)
245 
246 
247 class RoomDetail(ActionFromUrl, CreateOrUpdateView):
248     model = Room
249     form_class = RoomForm
250     template_name = 'orga/settings/room_form.html'
251 
252     def get_object(self):
253         try:
254             return self.request.event.rooms.get(pk=self.kwargs['pk'])
255         except (Room.DoesNotExist, KeyError):
256             return
257 
258     def get_success_url(self) -> str:
259         return self.request.event.orga_urls.room_settings
260 
261     def form_valid(self, form):
262         created = not bool(form.instance.pk)
263         form.instance.event = self.request.event
264         ret = super().form_valid(form)
265         messages.success(self.request, _('Saved!'))
266         if created:
267             form.instance.log_action('pretalx.room.create', person=self.request.user, orga=True)
268         else:
269             form.instance.log_action('pretalx.event.update', person=self.request.user, orga=True)
270         return ret
271
```
--- 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/src/pretalx/orga/views/settings.py b/src/pretalx/orga/views/settings.py
--- a/src/pretalx/orga/views/settings.py
+++ b/src/pretalx/orga/views/settings.py
@@ -3,6 +3,7 @@
 from django.contrib import messages
 from django.contrib.auth import login
 from django.core.exceptions import PermissionDenied
+from django.db.models.deletion import ProtectedError
 from django.shortcuts import redirect
 from django.urls import reverse
 from django.utils.crypto import get_random_string
@@ -239,8 +240,12 @@
 class RoomDelete(View):
 
     def dispatch(self, request, event, pk):
-        request.event.rooms.get(pk=pk).delete()
-        messages.success(self.request, _('Room deleted. Hopefully nobody was still in there …'))
+        try:
+            request.event.rooms.get(pk=pk).delete()
+            messages.success(self.request, _('Room deleted. Hopefully nobody was still in there …'))
+        except ProtectedError:  # TODO: show which/how many talks are concerned
+            messages.error(request, _('There is or was a talk scheduled in this room. It cannot be deleted.'))
+
         return redirect(request.event.orga_urls.room_settings)

{"golden_diff": "diff --git a/src/pretalx/orga/views/settings.py b/src/pretalx/orga/views/settings.py\n--- a/src/pretalx/orga/views/settings.py\n+++ b/src/pretalx/orga/views/settings.py\n@@ -3,6 +3,7 @@\n from django.contrib import messages\n from django.contrib.auth import login\n from django.core.exceptions import PermissionDenied\n+from django.db.models.deletion import ProtectedError\n from django.shortcuts import redirect\n from django.urls import reverse\n from django.utils.crypto import get_random_string\n@@ -239,8 +240,12 @@\n class RoomDelete(View):\n \n     def dispatch(self, request, event, pk):\n-        request.event.rooms.get(pk=pk).delete()\n-        messages.success(self.request, _('Room deleted. Hopefully nobody was still in there \u2026'))\n+        try:\n+            request.event.rooms.get(pk=pk).delete()\n+            messages.success(self.request, _('Room deleted. Hopefully nobody was still in there \u2026'))\n+        except ProtectedError:  # TODO: show which/how many talks are concerned\n+            messages.error(request, _('There is or was a talk scheduled in this room. It cannot be deleted.'))\n+\n         return redirect(request.event.orga_urls.room_settings)\n", "issue": "deleting a room, which is in use yields ProtectedError\nWhen you try to delete a room, which has talks assigned to it the app displays an ProtectedError. This can probably be handled it [deleting a submission type](https://github.com/openeventstack/pretalx/blob/master/src/pretalx/orga/views/cfp.py#L147-L152).\n", "before_files": [{"content": "import string\n\nfrom django.contrib import messages\nfrom django.contrib.auth import login\nfrom django.core.exceptions import PermissionDenied\nfrom django.shortcuts import redirect\nfrom django.urls import reverse\nfrom django.utils.crypto import get_random_string\nfrom django.utils.functional import cached_property\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.generic import FormView, TemplateView, View\n\nfrom pretalx.common.mail import mail_send_task\nfrom pretalx.common.urls import build_absolute_uri\nfrom pretalx.common.views import ActionFromUrl, CreateOrUpdateView\nfrom pretalx.event.models import Event\nfrom pretalx.orga.forms import EventForm\nfrom pretalx.orga.forms.event import MailSettingsForm\nfrom pretalx.person.forms import LoginInfoForm, UserForm, OrgaProfileForm\nfrom pretalx.person.models import EventPermission, User\nfrom pretalx.schedule.forms import RoomForm\nfrom pretalx.schedule.models import Room\n\n\nclass EventDetail(ActionFromUrl, CreateOrUpdateView):\n    model = Event\n    form_class = EventForm\n    template_name = 'orga/settings/form.html'\n\n    def dispatch(self, request, *args, **kwargs):\n        if self._action == 'create':\n            if not request.user.is_anonymous and not request.user.is_superuser:\n                raise PermissionDenied()\n        return super().dispatch(request, *args, **kwargs)\n\n    def get_object(self):\n        try:\n            return self.request.event\n        except AttributeError:\n            return\n\n    def get_success_url(self) -> str:\n        return self.object.orga_urls.settings\n\n    def form_valid(self, form):\n        new_event = not bool(form.instance.pk)\n        ret = super().form_valid(form)\n        if new_event:\n            messages.success(self.request, _('Yay, a new event! Check the settings and configure a CfP and you\\'re good to go!'))\n            form.instance.log_action('pretalx.event.create', person=self.request.user, orga=True)\n            EventPermission.objects.create(\n                event=form.instance,\n                user=self.request.user,\n                is_orga=True,\n            )\n        else:\n            form.instance.log_action('pretalx.event.update', person=self.request.user, orga=True)\n            messages.success(self.request, _('The event settings have been saved.'))\n        return ret\n\n\nclass EventMailSettings(ActionFromUrl, FormView):\n    form_class = MailSettingsForm\n    template_name = 'orga/settings/mail.html'\n\n    def get_success_url(self) -> str:\n        return self.request.event.orga_urls.mail_settings\n\n    def get_form_kwargs(self):\n        kwargs = super().get_form_kwargs()\n        kwargs['obj'] = self.request.event\n        kwargs['attribute_name'] = 'settings'\n        kwargs['locales'] = self.request.event.locales\n        return kwargs\n\n    def form_valid(self, form):\n        form.save()\n\n        if self.request.POST.get('test', '0').strip() == '1':\n            backend = self.request.event.get_mail_backend(force_custom=True)\n            try:\n                backend.test(self.request.event.settings.mail_from)\n            except Exception as e:\n                messages.warning(self.request, _('An error occured while contacting the SMTP server: %s') % str(e))\n                return redirect(reverse('orga:settings.mail.edit', kwargs={'event': self.request.event.slug}))\n            else:\n                if form.cleaned_data.get('smtp_use_custom'):\n                    messages.success(self.request, _('Yay, your changes have been saved and the connection attempt to '\n                                                     'your SMTP server was successful.'))\n                else:\n                    messages.success(self.request, _('We\\'ve been able to contact the SMTP server you configured. '\n                                                     'Remember to check the \"use custom SMTP server\" checkbox, '\n                                                     'otherwise your SMTP server will not be used.'))\n        else:\n            messages.success(self.request, _('Yay! We saved your changes.'))\n\n        ret = super().form_valid(form)\n        return ret\n\n\nclass EventTeam(TemplateView):\n    template_name = 'orga/settings/team.html'\n\n    def get_context_data(self, *args, **kwargs):\n        ctx = super().get_context_data(*args, **kwargs)\n        event = self.request.event\n        ctx['team'] = User.objects.filter(\n            permissions__is_orga=True,\n            permissions__event=event,\n        )\n        ctx['pending'] = EventPermission.objects.filter(event=event, user__isnull=True, is_orga=True)\n        return ctx\n\n\nclass EventTeamInvite(View):\n\n    def post(self, request, event):\n        email = request.POST.get('email')\n        event = request.event\n        invitation_token = get_random_string(allowed_chars=string.ascii_lowercase + string.digits, length=20)\n        invitation_link = build_absolute_uri('orga:invitation.view', kwargs={'code': invitation_token})\n        EventPermission.objects.create(\n            event=event,\n            invitation_email=email,\n            invitation_token=invitation_token,\n            is_orga=True,\n        )\n        invitation_text = _('''Hi!\n\nYou have been invited to the orga crew of {event} - Please click here to accept:\n\n    {invitation_link}\n\nSee you there,\nThe {event} orga crew (minus you)''').format(event=event.name, invitation_link=invitation_link)\n        mail_send_task.apply_async(args=(\n            [email],\n            _('You have been invited to the orga crew of {event}').format(event=request.event.name),\n            invitation_text,\n            request.event.email,\n            event.pk\n        ))\n        request.event.log_action('pretalx.event.invite.orga.send', person=request.user, orga=True)\n        messages.success(\n            request,\n            _('<{email}> has been invited to your team - more team members help distribute the workload, so \u2026 yay!').format(email=email)\n        )\n        return redirect(request.event.orga_urls.team_settings)\n\n\nclass EventTeamRetract(View):\n\n    def dispatch(self, request, event, pk):\n        EventPermission.objects.filter(event=request.event, pk=pk).delete()\n        request.event.log_action('pretalx.event.invite.orga.retract', person=request.user, orga=True)\n        return redirect(request.event.orga_urls.team_settings)\n\n\nclass EventTeamDelete(View):\n\n    def dispatch(self, request, event, pk):\n        EventPermission.objects.filter(event=request.event, user__id=pk).update(is_orga=False)\n        return redirect(request.event.orga_urls.team_settings)\n\n\nclass InvitationView(FormView):\n    template_name = 'orga/invitation.html'\n    form_class = UserForm\n\n    def get_context_data(self, *args, **kwargs):\n        ctx = super().get_context_data(*args, **kwargs)\n        ctx['invitation'] = EventPermission.objects.get(\n            invitation_token=self.kwargs.get('code'),\n        )\n        return ctx\n\n    def form_valid(self, form):\n        form.save()\n        permission = EventPermission.objects.get(invitation_token=self.kwargs.get('code'))\n        user = User.objects.get(pk=form.cleaned_data.get('user_id'))\n\n        permission.is_orga = True\n        permission.user = user\n        permission.save()\n        permission.event.log_action('pretalx.event.invite.orga.accept', person=user, orga=True)\n        login(self.request, user)\n        return redirect(permission.event.orga_urls.base)\n\n\nclass UserSettings(TemplateView):\n    form_class = LoginInfoForm\n    template_name = 'orga/user.html'\n\n    def get_success_url(self) -> str:\n        return reverse('orga:user.view')\n\n    @cached_property\n    def login_form(self):\n        return LoginInfoForm(user=self.request.user,\n                             data=(self.request.POST\n                                   if self.request.method == 'POST' and self.request.POST.get('form') == 'login'\n                                   else None))\n\n    @cached_property\n    def profile_form(self):\n        return OrgaProfileForm(instance=self.request.user,\n                               data=(self.request.POST\n                                     if self.request.method == 'POST' and self.request.POST.get('form') == 'profile'\n                                     else None))\n\n    def get_context_data(self, **kwargs):\n        ctx = super().get_context_data(**kwargs)\n        ctx['login_form'] = self.login_form\n        ctx['profile_form'] = self.profile_form\n        return ctx\n\n    def post(self, request, *args, **kwargs):\n        if self.login_form.is_bound:\n            if self.login_form.is_valid():\n                self.login_form.save()\n                messages.success(request, _('Your changes have been saved.'))\n                request.user.log_action('pretalx.user.password.update')\n                return redirect(self.get_success_url())\n        elif self.profile_form.is_bound:\n            if self.profile_form.is_valid():\n                self.profile_form.save()\n                messages.success(request, _('Your changes have been saved.'))\n                request.user.log_action('pretalx.user.profile.update')\n                return redirect(self.get_success_url())\n\n        messages.error(self.request, _('Oh :( We had trouble saving your input. See below for details.'))\n        return super().get(request, *args, **kwargs)\n\n\nclass RoomList(TemplateView):\n    template_name = 'orga/settings/room_list.html'\n\n\nclass RoomDelete(View):\n\n    def dispatch(self, request, event, pk):\n        request.event.rooms.get(pk=pk).delete()\n        messages.success(self.request, _('Room deleted. Hopefully nobody was still in there \u2026'))\n        return redirect(request.event.orga_urls.room_settings)\n\n\nclass RoomDetail(ActionFromUrl, CreateOrUpdateView):\n    model = Room\n    form_class = RoomForm\n    template_name = 'orga/settings/room_form.html'\n\n    def get_object(self):\n        try:\n            return self.request.event.rooms.get(pk=self.kwargs['pk'])\n        except (Room.DoesNotExist, KeyError):\n            return\n\n    def get_success_url(self) -> str:\n        return self.request.event.orga_urls.room_settings\n\n    def form_valid(self, form):\n        created = not bool(form.instance.pk)\n        form.instance.event = self.request.event\n        ret = super().form_valid(form)\n        messages.success(self.request, _('Saved!'))\n        if created:\n            form.instance.log_action('pretalx.room.create', person=self.request.user, orga=True)\n        else:\n            form.instance.log_action('pretalx.event.update', person=self.request.user, orga=True)\n        return ret\n", "path": "src/pretalx/orga/views/settings.py"}], "after_files": [{"content": "import string\n\nfrom django.contrib import messages\nfrom django.contrib.auth import login\nfrom django.core.exceptions import PermissionDenied\nfrom django.db.models.deletion import ProtectedError\nfrom django.shortcuts import redirect\nfrom django.urls import reverse\nfrom django.utils.crypto import get_random_string\nfrom django.utils.functional import cached_property\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.generic import FormView, TemplateView, View\n\nfrom pretalx.common.mail import mail_send_task\nfrom pretalx.common.urls import build_absolute_uri\nfrom pretalx.common.views import ActionFromUrl, CreateOrUpdateView\nfrom pretalx.event.models import Event\nfrom pretalx.orga.forms import EventForm\nfrom pretalx.orga.forms.event import MailSettingsForm\nfrom pretalx.person.forms import LoginInfoForm, UserForm, OrgaProfileForm\nfrom pretalx.person.models import EventPermission, User\nfrom pretalx.schedule.forms import RoomForm\nfrom pretalx.schedule.models import Room\n\n\nclass EventDetail(ActionFromUrl, CreateOrUpdateView):\n    model = Event\n    form_class = EventForm\n    template_name = 'orga/settings/form.html'\n\n    def dispatch(self, request, *args, **kwargs):\n        if self._action == 'create':\n            if not request.user.is_anonymous and not request.user.is_superuser:\n                raise PermissionDenied()\n        return super().dispatch(request, *args, **kwargs)\n\n    def get_object(self):\n        try:\n            return self.request.event\n        except AttributeError:\n            return\n\n    def get_success_url(self) -> str:\n        return self.object.orga_urls.settings\n\n    def form_valid(self, form):\n        new_event = not bool(form.instance.pk)\n        ret = super().form_valid(form)\n        if new_event:\n            messages.success(self.request, _('Yay, a new event! Check the settings and configure a CfP and you\\'re good to go!'))\n            form.instance.log_action('pretalx.event.create', person=self.request.user, orga=True)\n            EventPermission.objects.create(\n                event=form.instance,\n                user=self.request.user,\n                is_orga=True,\n            )\n        else:\n            form.instance.log_action('pretalx.event.update', person=self.request.user, orga=True)\n            messages.success(self.request, _('The event settings have been saved.'))\n        return ret\n\n\nclass EventMailSettings(ActionFromUrl, FormView):\n    form_class = MailSettingsForm\n    template_name = 'orga/settings/mail.html'\n\n    def get_success_url(self) -> str:\n        return self.request.event.orga_urls.mail_settings\n\n    def get_form_kwargs(self):\n        kwargs = super().get_form_kwargs()\n        kwargs['obj'] = self.request.event\n        kwargs['attribute_name'] = 'settings'\n        kwargs['locales'] = self.request.event.locales\n        return kwargs\n\n    def form_valid(self, form):\n        form.save()\n\n        if self.request.POST.get('test', '0').strip() == '1':\n            backend = self.request.event.get_mail_backend(force_custom=True)\n            try:\n                backend.test(self.request.event.settings.mail_from)\n            except Exception as e:\n                messages.warning(self.request, _('An error occured while contacting the SMTP server: %s') % str(e))\n                return redirect(reverse('orga:settings.mail.edit', kwargs={'event': self.request.event.slug}))\n            else:\n                if form.cleaned_data.get('smtp_use_custom'):\n                    messages.success(self.request, _('Yay, your changes have been saved and the connection attempt to '\n                                                     'your SMTP server was successful.'))\n                else:\n                    messages.success(self.request, _('We\\'ve been able to contact the SMTP server you configured. '\n                                                     'Remember to check the \"use custom SMTP server\" checkbox, '\n                                                     'otherwise your SMTP server will not be used.'))\n        else:\n            messages.success(self.request, _('Yay! We saved your changes.'))\n\n        ret = super().form_valid(form)\n        return ret\n\n\nclass EventTeam(TemplateView):\n    template_name = 'orga/settings/team.html'\n\n    def get_context_data(self, *args, **kwargs):\n        ctx = super().get_context_data(*args, **kwargs)\n        event = self.request.event\n        ctx['team'] = User.objects.filter(\n            permissions__is_orga=True,\n            permissions__event=event,\n        )\n        ctx['pending'] = EventPermission.objects.filter(event=event, user__isnull=True, is_orga=True)\n        return ctx\n\n\nclass EventTeamInvite(View):\n\n    def post(self, request, event):\n        email = request.POST.get('email')\n        event = request.event\n        invitation_token = get_random_string(allowed_chars=string.ascii_lowercase + string.digits, length=20)\n        invitation_link = build_absolute_uri('orga:invitation.view', kwargs={'code': invitation_token})\n        EventPermission.objects.create(\n            event=event,\n            invitation_email=email,\n            invitation_token=invitation_token,\n            is_orga=True,\n        )\n        invitation_text = _('''Hi!\n\nYou have been invited to the orga crew of {event} - Please click here to accept:\n\n    {invitation_link}\n\nSee you there,\nThe {event} orga crew (minus you)''').format(event=event.name, invitation_link=invitation_link)\n        mail_send_task.apply_async(args=(\n            [email],\n            _('You have been invited to the orga crew of {event}').format(event=request.event.name),\n            invitation_text,\n            request.event.email,\n            event.pk\n        ))\n        request.event.log_action('pretalx.event.invite.orga.send', person=request.user, orga=True)\n        messages.success(\n            request,\n            _('<{email}> has been invited to your team - more team members help distribute the workload, so \u2026 yay!').format(email=email)\n        )\n        return redirect(request.event.orga_urls.team_settings)\n\n\nclass EventTeamRetract(View):\n\n    def dispatch(self, request, event, pk):\n        EventPermission.objects.filter(event=request.event, pk=pk).delete()\n        request.event.log_action('pretalx.event.invite.orga.retract', person=request.user, orga=True)\n        return redirect(request.event.orga_urls.team_settings)\n\n\nclass EventTeamDelete(View):\n\n    def dispatch(self, request, event, pk):\n        EventPermission.objects.filter(event=request.event, user__id=pk).update(is_orga=False)\n        return redirect(request.event.orga_urls.team_settings)\n\n\nclass InvitationView(FormView):\n    template_name = 'orga/invitation.html'\n    form_class = UserForm\n\n    def get_context_data(self, *args, **kwargs):\n        ctx = super().get_context_data(*args, **kwargs)\n        ctx['invitation'] = EventPermission.objects.get(\n            invitation_token=self.kwargs.get('code'),\n        )\n        return ctx\n\n    def form_valid(self, form):\n        form.save()\n        permission = EventPermission.objects.get(invitation_token=self.kwargs.get('code'))\n        user = User.objects.get(pk=form.cleaned_data.get('user_id'))\n\n        permission.is_orga = True\n        permission.user = user\n        permission.save()\n        permission.event.log_action('pretalx.event.invite.orga.accept', person=user, orga=True)\n        login(self.request, user)\n        return redirect(permission.event.orga_urls.base)\n\n\nclass UserSettings(TemplateView):\n    form_class = LoginInfoForm\n    template_name = 'orga/user.html'\n\n    def get_success_url(self) -> str:\n        return reverse('orga:user.view')\n\n    @cached_property\n    def login_form(self):\n        return LoginInfoForm(user=self.request.user,\n                             data=(self.request.POST\n                                   if self.request.method == 'POST' and self.request.POST.get('form') == 'login'\n                                   else None))\n\n    @cached_property\n    def profile_form(self):\n        return OrgaProfileForm(instance=self.request.user,\n                               data=(self.request.POST\n                                     if self.request.method == 'POST' and self.request.POST.get('form') == 'profile'\n                                     else None))\n\n    def get_context_data(self, **kwargs):\n        ctx = super().get_context_data(**kwargs)\n        ctx['login_form'] = self.login_form\n        ctx['profile_form'] = self.profile_form\n        return ctx\n\n    def post(self, request, *args, **kwargs):\n        if self.login_form.is_bound:\n            if self.login_form.is_valid():\n                self.login_form.save()\n                messages.success(request, _('Your changes have been saved.'))\n                request.user.log_action('pretalx.user.password.update')\n                return redirect(self.get_success_url())\n        elif self.profile_form.is_bound:\n            if self.profile_form.is_valid():\n                self.profile_form.save()\n                messages.success(request, _('Your changes have been saved.'))\n                request.user.log_action('pretalx.user.profile.update')\n                return redirect(self.get_success_url())\n\n        messages.error(self.request, _('Oh :( We had trouble saving your input. See below for details.'))\n        return super().get(request, *args, **kwargs)\n\n\nclass RoomList(TemplateView):\n    template_name = 'orga/settings/room_list.html'\n\n\nclass RoomDelete(View):\n\n    def dispatch(self, request, event, pk):\n        try:\n            request.event.rooms.get(pk=pk).delete()\n            messages.success(self.request, _('Room deleted. Hopefully nobody was still in there \u2026'))\n        except ProtectedError:  # TODO: show which/how many talks are concerned\n            messages.error(request, _('There is or was a talk scheduled in this room. It cannot be deleted.'))\n\n        return redirect(request.event.orga_urls.room_settings)\n\n\nclass RoomDetail(ActionFromUrl, CreateOrUpdateView):\n    model = Room\n    form_class = RoomForm\n    template_name = 'orga/settings/room_form.html'\n\n    def get_object(self):\n        try:\n            return self.request.event.rooms.get(pk=self.kwargs['pk'])\n        except (Room.DoesNotExist, KeyError):\n            return\n\n    def get_success_url(self) -> str:\n        return self.request.event.orga_urls.room_settings\n\n    def form_valid(self, form):\n        created = not bool(form.instance.pk)\n        form.instance.event = self.request.event\n        ret = super().form_valid(form)\n        messages.success(self.request, _('Saved!'))\n        if created:\n            form.instance.log_action('pretalx.room.create', person=self.request.user, orga=True)\n        else:\n            form.instance.log_action('pretalx.event.update', person=self.request.user, orga=True)\n        return ret\n", "path": "src/pretalx/orga/views/settings.py"}]}