We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Adding a speaker question does not pre-select "speaker question"
In the question list view, one can click "Add new question" either for speaker questions or for submission questions. In the following form, the question type is not preselected, which is unexpected.

--- 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/cfp.py`
Content:
```
1 from csp.decorators import csp_update
2 from django.contrib import messages
3 from django.db import transaction
4 from django.db.models.deletion import ProtectedError
5 from django.forms.models import inlineformset_factory
6 from django.shortcuts import redirect
7 from django.utils.decorators import method_decorator
8 from django.utils.functional import cached_property
9 from django.utils.translation import ugettext_lazy as _
10 from django.views.generic import ListView, TemplateView, UpdateView, View
11 
12 from pretalx.common.forms import I18nFormSet
13 from pretalx.common.views import ActionFromUrl, CreateOrUpdateView
14 from pretalx.orga.forms import CfPForm, QuestionForm, SubmissionTypeForm
15 from pretalx.orga.forms.cfp import AnswerOptionForm, CfPSettingsForm
16 from pretalx.submission.models import (
17     AnswerOption, CfP, Question, SubmissionType,
18 )
19 
20 
21 class CfPTextDetail(ActionFromUrl, UpdateView):
22     form_class = CfPForm
23     model = CfP
24     template_name = 'orga/cfp/text.html'
25 
26     def get_context_data(self, *args, **kwargs):
27         ctx = super().get_context_data(*args, **kwargs)
28         ctx['sform'] = self.sform
29         return ctx
30 
31     @cached_property
32     def sform(self):
33         return CfPSettingsForm(
34             read_only=(self._action == 'view'),
35             locales=self.request.event.locales,
36             obj=self.request.event,
37             attribute_name='settings',
38             data=self.request.POST if self.request.method == "POST" else None,
39             prefix='settings'
40         )
41 
42     def get_object(self):
43         return self.request.event.cfp
44 
45     def get_success_url(self) -> str:
46         return self.get_object().urls.text
47 
48     def form_valid(self, form):
49         if not self.sform.is_valid():
50             return self.form_invalid(form)
51         messages.success(self.request, 'The CfP update has been saved.')
52         form.instance.event = self.request.event
53         ret = super().form_valid(form)
54         if form.has_changed():
55             form.instance.log_action('pretalx.cfp.update', person=self.request.user, orga=True)
56         self.sform.save()
57         return ret
58 
59 
60 class CfPQuestionList(TemplateView):
61     template_name = 'orga/cfp/question_view.html'
62 
63     def get_context_data(self, *args, **kwargs):
64         ctx = super().get_context_data(*args, **kwargs)
65         ctx['speaker_questions'] = Question.all_objects.filter(event=self.request.event, target='speaker')
66         ctx['submission_questions'] = Question.all_objects.filter(event=self.request.event, target='submission')
67         return ctx
68 
69 
70 @method_decorator(csp_update(SCRIPT_SRC="'self' 'unsafe-inline'"), name='dispatch')
71 class CfPQuestionDetail(ActionFromUrl, CreateOrUpdateView):
72     model = Question
73     form_class = QuestionForm
74     template_name = 'orga/cfp/question_form.html'
75 
76     def get_object(self) -> Question:
77         return self.request.event.questions.filter(pk=self.kwargs.get('pk')).first()
78 
79     @cached_property
80     def formset(self):
81         formset_class = inlineformset_factory(
82             Question, AnswerOption, form=AnswerOptionForm, formset=I18nFormSet,
83             can_delete=True, extra=0,
84         )
85         return formset_class(
86             self.request.POST if self.request.method == 'POST' else None,
87             queryset=AnswerOption.objects.filter(question=self.get_object()) if self.get_object() else AnswerOption.objects.none(),
88             event=self.request.event
89         )
90 
91     def save_formset(self, obj):
92         if self.formset.is_valid():
93             for form in self.formset.initial_forms:
94                 if form in self.formset.deleted_forms:
95                     if not form.instance.pk:
96                         continue
97                     obj.log_action(
98                         'pretalx.event.question.option.deleted', person=self.request.user, orga=True, data={
99                             'id': form.instance.pk
100                         }
101                     )
102                     form.instance.delete()
103                     form.instance.pk = None
104                 elif form.has_changed():
105                     form.instance.question = obj
106                     form.save()
107                     change_data = {k: form.cleaned_data.get(k) for k in form.changed_data}
108                     change_data['id'] = form.instance.pk
109                     obj.log_action(
110                         'pretalx.event.question.option.changed',
111                         person=self.request.user, orga=True, data=change_data
112                     )
113 
114             for form in self.formset.extra_forms:
115                 if not form.has_changed():
116                     continue
117                 if self.formset._should_delete_form(form):
118                     continue
119                 form.instance.question = obj
120                 form.save()
121                 change_data = {k: form.cleaned_data.get(k) for k in form.changed_data}
122                 change_data['id'] = form.instance.pk
123                 obj.log_action(
124                     'pretalx.event.question.option.added',
125                     person=self.request.user, orga=True, data=change_data
126                 )
127 
128             return True
129         return False
130 
131     def get_context_data(self, *args, **kwargs):
132         ctx = super().get_context_data(*args, **kwargs)
133         ctx['formset'] = self.formset
134         return ctx
135 
136     def get_success_url(self) -> str:
137         obj = self.get_object() or self.instance
138         return obj.urls.base
139 
140     @transaction.atomic
141     def form_valid(self, form):
142         form.instance.event = self.request.event
143         self.instance = form.instance
144         ret = super().form_valid(form)
145         if form.cleaned_data.get('variant') in ('choices', 'multiple_choice'):
146             result = self.save_formset(self.instance)
147             if not result:
148                 return self.get(self.request, *self.args, **self.kwargs)
149         if form.has_changed():
150             action = 'pretalx.question.' + ('update' if self.object else 'create')
151             form.instance.log_action(action, person=self.request.user, orga=True)
152         messages.success(self.request, 'The question has been saved.')
153         return ret
154 
155 
156 class CfPQuestionDelete(View):
157 
158     def dispatch(self, request, *args, **kwargs):
159         super().dispatch(request, *args, **kwargs)
160         question = self.request.event.questions.get(pk=self.kwargs.get('pk'))
161 
162         try:
163             question.delete()
164             question.log_action('pretalx.question.delete', person=self.request.user, orga=True)
165             messages.success(request, _('The question has been deleted.'))
166         except ProtectedError:
167             question.active = False
168             question.save()
169             messages.error(request, _('You cannot delete a question that has already been answered. We have deactivated the question instead.'))
170         return redirect(self.request.event.cfp.urls.questions)
171 
172 
173 class SubmissionTypeList(ListView):
174     template_name = 'orga/cfp/submission_type_view.html'
175     context_object_name = 'types'
176 
177     def get_queryset(self):
178         return self.request.event.submission_types.all()
179 
180 
181 class SubmissionTypeDetail(ActionFromUrl, CreateOrUpdateView):
182     model = SubmissionType
183     form_class = SubmissionTypeForm
184     template_name = 'orga/cfp/submission_type_form.html'
185 
186     def get_success_url(self) -> str:
187         return self.request.event.cfp.urls.types
188 
189     def get_object(self):
190         return self.request.event.submission_types.get(pk=self.kwargs.get('pk'))
191 
192     def form_valid(self, form):
193         messages.success(self.request, 'The Submission Type has been saved.')
194         form.instance.event = self.request.event
195         ret = super().form_valid(form)
196         if form.has_changed():
197             action = 'pretalx.submission_type.' + ('update' if self.object else 'create')
198             form.instance.log_action(action, person=self.request.user, orga=True)
199         return ret
200 
201 
202 class SubmissionTypeDefault(View):
203 
204     def dispatch(self, request, *args, **kwargs):
205         super().dispatch(request, *args, **kwargs)
206 
207         submission_type = self.request.event.submission_types.get(pk=self.kwargs.get('pk'))
208         self.request.event.cfp.default_type = submission_type
209         self.request.event.cfp.save(update_fields=['default_type'])
210         submission_type.log_action('pretalx.submission_type.make_default', person=self.request.user, orga=True)
211         messages.success(request, _('The Submission Type has been made default.'))
212         return redirect(self.request.event.cfp.urls.types)
213 
214 
215 class SubmissionTypeDelete(View):
216 
217     def dispatch(self, request, *args, **kwargs):
218         super().dispatch(request, *args, **kwargs)
219         submission_type = self.request.event.submission_types.get(pk=self.kwargs.get('pk'))
220 
221         if request.event.submission_types.count() == 1:
222             messages.error(request, _('You cannot delete the only submission type. Try creating another one first!'))
223         elif request.event.cfp.default_type == submission_type:
224             messages.error(request, _('You cannot delete the default submission type. Make another type default first!'))
225         else:
226             try:
227                 submission_type.delete()
228                 request.event.log_action('pretalx.submission_type.delete', person=self.request.user, orga=True)
229                 messages.success(request, _('The Submission Type has been deleted.'))
230             except ProtectedError:  # TODO: show which/how many submissions are concerned
231                 messages.error(request, _('This Submission Type is in use in a submission and cannot be deleted.'))
232         return redirect(self.request.event.cfp.urls.types)
233
```
--- 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/cfp.py b/src/pretalx/orga/views/cfp.py
--- a/src/pretalx/orga/views/cfp.py
+++ b/src/pretalx/orga/views/cfp.py
@@ -133,6 +133,14 @@
         ctx['formset'] = self.formset
         return ctx
 
+    def get_form_kwargs(self, *args, **kwargs):
+        kwargs = super().get_form_kwargs(*args, **kwargs)
+        if not self.get_object():
+            initial = kwargs['initial'] or dict()
+            initial['target'] = self.request.GET.get('type')
+            kwargs['initial'] = initial
+        return kwargs
+
     def get_success_url(self) -> str:
         obj = self.get_object() or self.instance
         return obj.urls.base

{"golden_diff": "diff --git a/src/pretalx/orga/views/cfp.py b/src/pretalx/orga/views/cfp.py\n--- a/src/pretalx/orga/views/cfp.py\n+++ b/src/pretalx/orga/views/cfp.py\n@@ -133,6 +133,14 @@\n         ctx['formset'] = self.formset\n         return ctx\n \n+    def get_form_kwargs(self, *args, **kwargs):\n+        kwargs = super().get_form_kwargs(*args, **kwargs)\n+        if not self.get_object():\n+            initial = kwargs['initial'] or dict()\n+            initial['target'] = self.request.GET.get('type')\n+            kwargs['initial'] = initial\n+        return kwargs\n+\n     def get_success_url(self) -> str:\n         obj = self.get_object() or self.instance\n         return obj.urls.base\n", "issue": "Adding a speaker question does not pre-select \"speaker question\"\nIn the question list view, one can click \"Add new question\" either for speaker questions or for submission questions. In the following form, the question type is not preselected, which is unexpected.\n", "before_files": [{"content": "from csp.decorators import csp_update\nfrom django.contrib import messages\nfrom django.db import transaction\nfrom django.db.models.deletion import ProtectedError\nfrom django.forms.models import inlineformset_factory\nfrom django.shortcuts import redirect\nfrom django.utils.decorators import method_decorator\nfrom django.utils.functional import cached_property\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.generic import ListView, TemplateView, UpdateView, View\n\nfrom pretalx.common.forms import I18nFormSet\nfrom pretalx.common.views import ActionFromUrl, CreateOrUpdateView\nfrom pretalx.orga.forms import CfPForm, QuestionForm, SubmissionTypeForm\nfrom pretalx.orga.forms.cfp import AnswerOptionForm, CfPSettingsForm\nfrom pretalx.submission.models import (\n    AnswerOption, CfP, Question, SubmissionType,\n)\n\n\nclass CfPTextDetail(ActionFromUrl, UpdateView):\n    form_class = CfPForm\n    model = CfP\n    template_name = 'orga/cfp/text.html'\n\n    def get_context_data(self, *args, **kwargs):\n        ctx = super().get_context_data(*args, **kwargs)\n        ctx['sform'] = self.sform\n        return ctx\n\n    @cached_property\n    def sform(self):\n        return CfPSettingsForm(\n            read_only=(self._action == 'view'),\n            locales=self.request.event.locales,\n            obj=self.request.event,\n            attribute_name='settings',\n            data=self.request.POST if self.request.method == \"POST\" else None,\n            prefix='settings'\n        )\n\n    def get_object(self):\n        return self.request.event.cfp\n\n    def get_success_url(self) -> str:\n        return self.get_object().urls.text\n\n    def form_valid(self, form):\n        if not self.sform.is_valid():\n            return self.form_invalid(form)\n        messages.success(self.request, 'The CfP update has been saved.')\n        form.instance.event = self.request.event\n        ret = super().form_valid(form)\n        if form.has_changed():\n            form.instance.log_action('pretalx.cfp.update', person=self.request.user, orga=True)\n        self.sform.save()\n        return ret\n\n\nclass CfPQuestionList(TemplateView):\n    template_name = 'orga/cfp/question_view.html'\n\n    def get_context_data(self, *args, **kwargs):\n        ctx = super().get_context_data(*args, **kwargs)\n        ctx['speaker_questions'] = Question.all_objects.filter(event=self.request.event, target='speaker')\n        ctx['submission_questions'] = Question.all_objects.filter(event=self.request.event, target='submission')\n        return ctx\n\n\n@method_decorator(csp_update(SCRIPT_SRC=\"'self' 'unsafe-inline'\"), name='dispatch')\nclass CfPQuestionDetail(ActionFromUrl, CreateOrUpdateView):\n    model = Question\n    form_class = QuestionForm\n    template_name = 'orga/cfp/question_form.html'\n\n    def get_object(self) -> Question:\n        return self.request.event.questions.filter(pk=self.kwargs.get('pk')).first()\n\n    @cached_property\n    def formset(self):\n        formset_class = inlineformset_factory(\n            Question, AnswerOption, form=AnswerOptionForm, formset=I18nFormSet,\n            can_delete=True, extra=0,\n        )\n        return formset_class(\n            self.request.POST if self.request.method == 'POST' else None,\n            queryset=AnswerOption.objects.filter(question=self.get_object()) if self.get_object() else AnswerOption.objects.none(),\n            event=self.request.event\n        )\n\n    def save_formset(self, obj):\n        if self.formset.is_valid():\n            for form in self.formset.initial_forms:\n                if form in self.formset.deleted_forms:\n                    if not form.instance.pk:\n                        continue\n                    obj.log_action(\n                        'pretalx.event.question.option.deleted', person=self.request.user, orga=True, data={\n                            'id': form.instance.pk\n                        }\n                    )\n                    form.instance.delete()\n                    form.instance.pk = None\n                elif form.has_changed():\n                    form.instance.question = obj\n                    form.save()\n                    change_data = {k: form.cleaned_data.get(k) for k in form.changed_data}\n                    change_data['id'] = form.instance.pk\n                    obj.log_action(\n                        'pretalx.event.question.option.changed',\n                        person=self.request.user, orga=True, data=change_data\n                    )\n\n            for form in self.formset.extra_forms:\n                if not form.has_changed():\n                    continue\n                if self.formset._should_delete_form(form):\n                    continue\n                form.instance.question = obj\n                form.save()\n                change_data = {k: form.cleaned_data.get(k) for k in form.changed_data}\n                change_data['id'] = form.instance.pk\n                obj.log_action(\n                    'pretalx.event.question.option.added',\n                    person=self.request.user, orga=True, data=change_data\n                )\n\n            return True\n        return False\n\n    def get_context_data(self, *args, **kwargs):\n        ctx = super().get_context_data(*args, **kwargs)\n        ctx['formset'] = self.formset\n        return ctx\n\n    def get_success_url(self) -> str:\n        obj = self.get_object() or self.instance\n        return obj.urls.base\n\n    @transaction.atomic\n    def form_valid(self, form):\n        form.instance.event = self.request.event\n        self.instance = form.instance\n        ret = super().form_valid(form)\n        if form.cleaned_data.get('variant') in ('choices', 'multiple_choice'):\n            result = self.save_formset(self.instance)\n            if not result:\n                return self.get(self.request, *self.args, **self.kwargs)\n        if form.has_changed():\n            action = 'pretalx.question.' + ('update' if self.object else 'create')\n            form.instance.log_action(action, person=self.request.user, orga=True)\n        messages.success(self.request, 'The question has been saved.')\n        return ret\n\n\nclass CfPQuestionDelete(View):\n\n    def dispatch(self, request, *args, **kwargs):\n        super().dispatch(request, *args, **kwargs)\n        question = self.request.event.questions.get(pk=self.kwargs.get('pk'))\n\n        try:\n            question.delete()\n            question.log_action('pretalx.question.delete', person=self.request.user, orga=True)\n            messages.success(request, _('The question has been deleted.'))\n        except ProtectedError:\n            question.active = False\n            question.save()\n            messages.error(request, _('You cannot delete a question that has already been answered. We have deactivated the question instead.'))\n        return redirect(self.request.event.cfp.urls.questions)\n\n\nclass SubmissionTypeList(ListView):\n    template_name = 'orga/cfp/submission_type_view.html'\n    context_object_name = 'types'\n\n    def get_queryset(self):\n        return self.request.event.submission_types.all()\n\n\nclass SubmissionTypeDetail(ActionFromUrl, CreateOrUpdateView):\n    model = SubmissionType\n    form_class = SubmissionTypeForm\n    template_name = 'orga/cfp/submission_type_form.html'\n\n    def get_success_url(self) -> str:\n        return self.request.event.cfp.urls.types\n\n    def get_object(self):\n        return self.request.event.submission_types.get(pk=self.kwargs.get('pk'))\n\n    def form_valid(self, form):\n        messages.success(self.request, 'The Submission Type has been saved.')\n        form.instance.event = self.request.event\n        ret = super().form_valid(form)\n        if form.has_changed():\n            action = 'pretalx.submission_type.' + ('update' if self.object else 'create')\n            form.instance.log_action(action, person=self.request.user, orga=True)\n        return ret\n\n\nclass SubmissionTypeDefault(View):\n\n    def dispatch(self, request, *args, **kwargs):\n        super().dispatch(request, *args, **kwargs)\n\n        submission_type = self.request.event.submission_types.get(pk=self.kwargs.get('pk'))\n        self.request.event.cfp.default_type = submission_type\n        self.request.event.cfp.save(update_fields=['default_type'])\n        submission_type.log_action('pretalx.submission_type.make_default', person=self.request.user, orga=True)\n        messages.success(request, _('The Submission Type has been made default.'))\n        return redirect(self.request.event.cfp.urls.types)\n\n\nclass SubmissionTypeDelete(View):\n\n    def dispatch(self, request, *args, **kwargs):\n        super().dispatch(request, *args, **kwargs)\n        submission_type = self.request.event.submission_types.get(pk=self.kwargs.get('pk'))\n\n        if request.event.submission_types.count() == 1:\n            messages.error(request, _('You cannot delete the only submission type. Try creating another one first!'))\n        elif request.event.cfp.default_type == submission_type:\n            messages.error(request, _('You cannot delete the default submission type. Make another type default first!'))\n        else:\n            try:\n                submission_type.delete()\n                request.event.log_action('pretalx.submission_type.delete', person=self.request.user, orga=True)\n                messages.success(request, _('The Submission Type has been deleted.'))\n            except ProtectedError:  # TODO: show which/how many submissions are concerned\n                messages.error(request, _('This Submission Type is in use in a submission and cannot be deleted.'))\n        return redirect(self.request.event.cfp.urls.types)\n", "path": "src/pretalx/orga/views/cfp.py"}], "after_files": [{"content": "from csp.decorators import csp_update\nfrom django.contrib import messages\nfrom django.db import transaction\nfrom django.db.models.deletion import ProtectedError\nfrom django.forms.models import inlineformset_factory\nfrom django.shortcuts import redirect\nfrom django.utils.decorators import method_decorator\nfrom django.utils.functional import cached_property\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.generic import ListView, TemplateView, UpdateView, View\n\nfrom pretalx.common.forms import I18nFormSet\nfrom pretalx.common.views import ActionFromUrl, CreateOrUpdateView\nfrom pretalx.orga.forms import CfPForm, QuestionForm, SubmissionTypeForm\nfrom pretalx.orga.forms.cfp import AnswerOptionForm, CfPSettingsForm\nfrom pretalx.submission.models import (\n    AnswerOption, CfP, Question, SubmissionType,\n)\n\n\nclass CfPTextDetail(ActionFromUrl, UpdateView):\n    form_class = CfPForm\n    model = CfP\n    template_name = 'orga/cfp/text.html'\n\n    def get_context_data(self, *args, **kwargs):\n        ctx = super().get_context_data(*args, **kwargs)\n        ctx['sform'] = self.sform\n        return ctx\n\n    @cached_property\n    def sform(self):\n        return CfPSettingsForm(\n            read_only=(self._action == 'view'),\n            locales=self.request.event.locales,\n            obj=self.request.event,\n            attribute_name='settings',\n            data=self.request.POST if self.request.method == \"POST\" else None,\n            prefix='settings'\n        )\n\n    def get_object(self):\n        return self.request.event.cfp\n\n    def get_success_url(self) -> str:\n        return self.get_object().urls.text\n\n    def form_valid(self, form):\n        if not self.sform.is_valid():\n            return self.form_invalid(form)\n        messages.success(self.request, 'The CfP update has been saved.')\n        form.instance.event = self.request.event\n        ret = super().form_valid(form)\n        if form.has_changed():\n            form.instance.log_action('pretalx.cfp.update', person=self.request.user, orga=True)\n        self.sform.save()\n        return ret\n\n\nclass CfPQuestionList(TemplateView):\n    template_name = 'orga/cfp/question_view.html'\n\n    def get_context_data(self, *args, **kwargs):\n        ctx = super().get_context_data(*args, **kwargs)\n        ctx['speaker_questions'] = Question.all_objects.filter(event=self.request.event, target='speaker')\n        ctx['submission_questions'] = Question.all_objects.filter(event=self.request.event, target='submission')\n        return ctx\n\n\n@method_decorator(csp_update(SCRIPT_SRC=\"'self' 'unsafe-inline'\"), name='dispatch')\nclass CfPQuestionDetail(ActionFromUrl, CreateOrUpdateView):\n    model = Question\n    form_class = QuestionForm\n    template_name = 'orga/cfp/question_form.html'\n\n    def get_object(self) -> Question:\n        return self.request.event.questions.filter(pk=self.kwargs.get('pk')).first()\n\n    @cached_property\n    def formset(self):\n        formset_class = inlineformset_factory(\n            Question, AnswerOption, form=AnswerOptionForm, formset=I18nFormSet,\n            can_delete=True, extra=0,\n        )\n        return formset_class(\n            self.request.POST if self.request.method == 'POST' else None,\n            queryset=AnswerOption.objects.filter(question=self.get_object()) if self.get_object() else AnswerOption.objects.none(),\n            event=self.request.event\n        )\n\n    def save_formset(self, obj):\n        if self.formset.is_valid():\n            for form in self.formset.initial_forms:\n                if form in self.formset.deleted_forms:\n                    if not form.instance.pk:\n                        continue\n                    obj.log_action(\n                        'pretalx.event.question.option.deleted', person=self.request.user, orga=True, data={\n                            'id': form.instance.pk\n                        }\n                    )\n                    form.instance.delete()\n                    form.instance.pk = None\n                elif form.has_changed():\n                    form.instance.question = obj\n                    form.save()\n                    change_data = {k: form.cleaned_data.get(k) for k in form.changed_data}\n                    change_data['id'] = form.instance.pk\n                    obj.log_action(\n                        'pretalx.event.question.option.changed',\n                        person=self.request.user, orga=True, data=change_data\n                    )\n\n            for form in self.formset.extra_forms:\n                if not form.has_changed():\n                    continue\n                if self.formset._should_delete_form(form):\n                    continue\n                form.instance.question = obj\n                form.save()\n                change_data = {k: form.cleaned_data.get(k) for k in form.changed_data}\n                change_data['id'] = form.instance.pk\n                obj.log_action(\n                    'pretalx.event.question.option.added',\n                    person=self.request.user, orga=True, data=change_data\n                )\n\n            return True\n        return False\n\n    def get_context_data(self, *args, **kwargs):\n        ctx = super().get_context_data(*args, **kwargs)\n        ctx['formset'] = self.formset\n        return ctx\n\n    def get_form_kwargs(self, *args, **kwargs):\n        kwargs = super().get_form_kwargs(*args, **kwargs)\n        if not self.get_object():\n            initial = kwargs['initial'] or dict()\n            initial['target'] = self.request.GET.get('type')\n            kwargs['initial'] = initial\n        return kwargs\n\n    def get_success_url(self) -> str:\n        obj = self.get_object() or self.instance\n        return obj.urls.base\n\n    @transaction.atomic\n    def form_valid(self, form):\n        form.instance.event = self.request.event\n        self.instance = form.instance\n        ret = super().form_valid(form)\n        if form.cleaned_data.get('variant') in ('choices', 'multiple_choice'):\n            result = self.save_formset(self.instance)\n            if not result:\n                return self.get(self.request, *self.args, **self.kwargs)\n        if form.has_changed():\n            action = 'pretalx.question.' + ('update' if self.object else 'create')\n            form.instance.log_action(action, person=self.request.user, orga=True)\n        messages.success(self.request, 'The question has been saved.')\n        return ret\n\n\nclass CfPQuestionDelete(View):\n\n    def dispatch(self, request, *args, **kwargs):\n        super().dispatch(request, *args, **kwargs)\n        question = self.request.event.questions.get(pk=self.kwargs.get('pk'))\n\n        try:\n            question.delete()\n            question.log_action('pretalx.question.delete', person=self.request.user, orga=True)\n            messages.success(request, _('The question has been deleted.'))\n        except ProtectedError:\n            question.active = False\n            question.save()\n            messages.error(request, _('You cannot delete a question that has already been answered. We have deactivated the question instead.'))\n        return redirect(self.request.event.cfp.urls.questions)\n\n\nclass SubmissionTypeList(ListView):\n    template_name = 'orga/cfp/submission_type_view.html'\n    context_object_name = 'types'\n\n    def get_queryset(self):\n        return self.request.event.submission_types.all()\n\n\nclass SubmissionTypeDetail(ActionFromUrl, CreateOrUpdateView):\n    model = SubmissionType\n    form_class = SubmissionTypeForm\n    template_name = 'orga/cfp/submission_type_form.html'\n\n    def get_success_url(self) -> str:\n        return self.request.event.cfp.urls.types\n\n    def get_object(self):\n        return self.request.event.submission_types.get(pk=self.kwargs.get('pk'))\n\n    def form_valid(self, form):\n        messages.success(self.request, 'The Submission Type has been saved.')\n        form.instance.event = self.request.event\n        ret = super().form_valid(form)\n        if form.has_changed():\n            action = 'pretalx.submission_type.' + ('update' if self.object else 'create')\n            form.instance.log_action(action, person=self.request.user, orga=True)\n        return ret\n\n\nclass SubmissionTypeDefault(View):\n\n    def dispatch(self, request, *args, **kwargs):\n        super().dispatch(request, *args, **kwargs)\n\n        submission_type = self.request.event.submission_types.get(pk=self.kwargs.get('pk'))\n        self.request.event.cfp.default_type = submission_type\n        self.request.event.cfp.save(update_fields=['default_type'])\n        submission_type.log_action('pretalx.submission_type.make_default', person=self.request.user, orga=True)\n        messages.success(request, _('The Submission Type has been made default.'))\n        return redirect(self.request.event.cfp.urls.types)\n\n\nclass SubmissionTypeDelete(View):\n\n    def dispatch(self, request, *args, **kwargs):\n        super().dispatch(request, *args, **kwargs)\n        submission_type = self.request.event.submission_types.get(pk=self.kwargs.get('pk'))\n\n        if request.event.submission_types.count() == 1:\n            messages.error(request, _('You cannot delete the only submission type. Try creating another one first!'))\n        elif request.event.cfp.default_type == submission_type:\n            messages.error(request, _('You cannot delete the default submission type. Make another type default first!'))\n        else:\n            try:\n                submission_type.delete()\n                request.event.log_action('pretalx.submission_type.delete', person=self.request.user, orga=True)\n                messages.success(request, _('The Submission Type has been deleted.'))\n            except ProtectedError:  # TODO: show which/how many submissions are concerned\n                messages.error(request, _('This Submission Type is in use in a submission and cannot be deleted.'))\n        return redirect(self.request.event.cfp.urls.types)\n", "path": "src/pretalx/orga/views/cfp.py"}]}