Repository: pretalx/pretalx

Issue:
Having only one submission type shows all submission types
## Current Behavior
If an event only uses one submission type, the submission form shows submission types for ALL events


## Expected Behavior
Only submission types for the current conference should populate the dropdown. 
Added bonus: if only one, the field should be read-only/text. 

## Steps to Reproduce

1. https://pretalx.com/orga/event/[YOUREVENT]/cfp/types/
2. Enter only one type
3. Navigate to https://pretalx.com/[YOUREVENT]/submit/
4. Click the dropdown for "Submission type"

<img width="801" alt="Screen Shot 2019-03-30 at 5 35 39 pm" src="https://user-images.githubusercontent.com/813732/55272568-53aeeb80-5312-11e9-8de9-e101aa53034f.png">


### Work around

Enter more than one submission type. 

## Your Environment

Pretalx hosted environment

Having only one submission type shows all submission types
## Current Behavior
If an event only uses one submission type, the submission form shows submission types for ALL events


## Expected Behavior
Only submission types for the current conference should populate the dropdown. 
Added bonus: if only one, the field should be read-only/text. 

## Steps to Reproduce

1. https://pretalx.com/orga/event/[YOUREVENT]/cfp/types/
2. Enter only one type
3. Navigate to https://pretalx.com/[YOUREVENT]/submit/
4. Click the dropdown for "Submission type"

<img width="801" alt="Screen Shot 2019-03-30 at 5 35 39 pm" src="https://user-images.githubusercontent.com/813732/55272568-53aeeb80-5312-11e9-8de9-e101aa53034f.png">


### Work around

Enter more than one submission type. 

## Your Environment

Pretalx hosted environment



Discussion:

Resolving patch:
diff --git a/src/pretalx/submission/forms/submission.py b/src/pretalx/submission/forms/submission.py
--- a/src/pretalx/submission/forms/submission.py
+++ b/src/pretalx/submission/forms/submission.py
@@ -66,14 +66,12 @@ def _set_submission_types(self, instance=None):
         pks = set(types.values_list('pk', flat=True))
         if instance and instance.pk:
             pks |= {instance.submission_type.pk}
+        self.fields['submission_type'].queryset = self.event.submission_types.filter(
+            pk__in=pks
+        )
         if len(pks) == 1:
             self.fields['submission_type'].initial = self.event.submission_types.get(pk=pks.pop())
-            self.fields['content_locale'].widget = forms.HiddenInput()
-            self.fields['content_locale'].disabled = True
-        else:
-            self.fields['submission_type'].queryset = self.event.submission_types.filter(
-                pk__in=pks
-            )
+            self.fields['submission_type'].widget = forms.HiddenInput()
 
     def _set_locales(self):
         if len(self.event.locales) == 1:


Test patch:
diff --git a/src/tests/cfp/views/test_cfp_wizard.py b/src/tests/cfp/views/test_cfp_wizard.py
--- a/src/tests/cfp/views/test_cfp_wizard.py
+++ b/src/tests/cfp/views/test_cfp_wizard.py
@@ -1,10 +1,12 @@
 from datetime import timedelta
 
 import bs4
+import django.forms as forms
 import pytest
 from django.core import mail as djmail
 from django.utils.timezone import now
 
+from pretalx.submission.forms import InfoForm
 from pretalx.submission.models import Submission, SubmissionType
 
 
@@ -336,3 +338,24 @@ def test_wizard_cfp_closed(self, event, client, user):
         event.cfp.save()
         client.force_login(user)
         response, current_url = self.perform_init_wizard(client, success=False)
+
+
+@pytest.mark.django_db
+def test_infoform_set_submission_type(event, other_event):
+    # https://github.com/pretalx/pretalx/issues/642
+    f = InfoForm(event)
+    assert len(SubmissionType.objects.all()) > 1
+    assert len(event.submission_types.all()) == 1
+    assert len(f.fields['submission_type'].queryset) == 1
+    assert f.fields['submission_type'].initial == event.submission_types.all()[0]
+    assert isinstance(f.fields['submission_type'].widget, forms.HiddenInput)
+
+
+@pytest.mark.django_db
+def test_infoform_set_submission_type_2nd_event(event, other_event, submission_type):
+    # https://github.com/pretalx/pretalx/issues/642
+    f = InfoForm(event)
+    assert len(SubmissionType.objects.all()) > 1
+    assert len(event.submission_types.all()) == 2
+    assert len(f.fields['submission_type'].queryset) == 2
+    assert not isinstance(f.fields['submission_type'].widget, forms.HiddenInput)