Repository: learningequality/kolibri

Issue:
Setup wizard is broken
## Summary

* Submitting the setup wizard returns `{language_code: ["This field is required."]}`

## System information

 - Version: 0.6

## How to reproduce

1. Go through setup wizard

## Real-life consequences

Sadness


Discussion:

Resolving patch:
diff --git a/kolibri/core/device/migrations/0001_initial.py b/kolibri/core/device/migrations/0001_initial.py
--- a/kolibri/core/device/migrations/0001_initial.py
+++ b/kolibri/core/device/migrations/0001_initial.py
@@ -29,7 +29,7 @@ class Migration(migrations.Migration):
             fields=[
                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                 ('is_provisioned', models.BooleanField(default=False)),
-                ('language_code', models.CharField(default='en', max_length=15)),
+                ('language_id', models.CharField(default='en', max_length=15)),
             ],
         ),
     ]
diff --git a/kolibri/core/device/models.py b/kolibri/core/device/models.py
--- a/kolibri/core/device/models.py
+++ b/kolibri/core/device/models.py
@@ -23,7 +23,7 @@ class DeviceSettings(models.Model):
     """
 
     is_provisioned = models.BooleanField(default=False)
-    language_code = models.CharField(max_length=15, default=settings.LANGUAGE_CODE)
+    language_id = models.CharField(max_length=15, default=settings.LANGUAGE_CODE)
 
     def save(self, *args, **kwargs):
         self.pk = 1
diff --git a/kolibri/core/device/serializers.py b/kolibri/core/device/serializers.py
--- a/kolibri/core/device/serializers.py
+++ b/kolibri/core/device/serializers.py
@@ -28,18 +28,18 @@ class DeviceProvisionSerializer(serializers.Serializer):
     facility = FacilitySerializer()
     preset = serializers.ChoiceField(choices=choices)
     superuser = NoFacilityFacilityUserSerializer()
-    language_code = serializers.CharField(max_length=15)
+    language_id = serializers.CharField(max_length=15)
 
     class Meta:
-        fields = ('facility', 'dataset', 'superuser', 'language_code')
+        fields = ('facility', 'dataset', 'superuser', 'language_id')
 
-    def validate_language_code(self, language_code):
+    def validate_language_id(self, language_id):
         """
-        Check that the language_code is supported by Kolibri
+        Check that the language_id is supported by Kolibri
         """
-        if not check_for_language(language_code):
+        if not check_for_language(language_id):
             raise serializers.ValidationError(_("Language is not supported by Kolibri"))
-        return language_code
+        return language_id
 
     def create(self, validated_data):
         """
@@ -62,14 +62,14 @@ def create(self, validated_data):
             superuser = FacilityUserSerializer(data=superuser_data).create(superuser_data)
             facility.add_role(superuser, ADMIN)
             DevicePermissions.objects.create(user=superuser, is_superuser=True)
-            language_code = validated_data.pop('language_code')
+            language_id = validated_data.pop('language_id')
             device_settings, created = DeviceSettings.objects.get_or_create()
             device_settings.is_provisioned = True
-            device_settings.language_code = language_code
+            device_settings.language_id = language_id
             device_settings.save()
             return {
                 "facility": facility,
                 "preset": preset,
                 "superuser": superuser,
-                "language_code": language_code
+                "language_id": language_id
             }


Test patch:
diff --git a/kolibri/core/device/test/test_api.py b/kolibri/core/device/test/test_api.py
--- a/kolibri/core/device/test/test_api.py
+++ b/kolibri/core/device/test/test_api.py
@@ -22,7 +22,7 @@ class DeviceProvisionTestCase(APITestCase):
         "learner_can_login_with_no_password": False,
     }
 
-    language_code = "en"
+    language_id = "en"
 
     def test_cannot_post_if_provisioned(self):
         provision_device()
@@ -30,7 +30,7 @@ def test_cannot_post_if_provisioned(self):
             "superuser": self.superuser_data,
             "facility": self.facility_data,
             "preset": self.preset_data,
-            "language_code": self.language_code,
+            "language_id": self.language_id,
         }
         response = self.client.post(reverse('deviceprovision'), data, format="json")
         self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
@@ -40,7 +40,7 @@ def test_superuser_created(self):
             "superuser": self.superuser_data,
             "facility": self.facility_data,
             "preset": self.preset_data,
-            "language_code": self.language_code,
+            "language_id": self.language_id,
         }
         self.client.post(reverse('deviceprovision'), data, format="json")
         self.assertEqual(FacilityUser.objects.get().username, self.superuser_data["username"])
@@ -50,7 +50,7 @@ def test_superuser_device_permissions_created(self):
             "superuser": self.superuser_data,
             "facility": self.facility_data,
             "preset": self.preset_data,
-            "language_code": self.language_code,
+            "language_id": self.language_id,
         }
         self.client.post(reverse('deviceprovision'), data, format="json")
         self.assertEqual(DevicePermissions.objects.get(), FacilityUser.objects.get().devicepermissions)
@@ -60,7 +60,7 @@ def test_facility_created(self):
             "superuser": self.superuser_data,
             "facility": self.facility_data,
             "preset": self.preset_data,
-            "language_code": self.language_code,
+            "language_id": self.language_id,
         }
         self.client.post(reverse('deviceprovision'), data, format="json")
         self.assertEqual(Facility.objects.get().name, self.facility_data["name"])
@@ -70,7 +70,7 @@ def test_admin_role_created(self):
             "superuser": self.superuser_data,
             "facility": self.facility_data,
             "preset": self.preset_data,
-            "language_code": self.language_code,
+            "language_id": self.language_id,
         }
         self.client.post(reverse('deviceprovision'), data, format="json")
         self.assertEqual(Role.objects.get().kind, ADMIN)
@@ -80,7 +80,7 @@ def test_facility_role_created(self):
             "superuser": self.superuser_data,
             "facility": self.facility_data,
             "preset": self.preset_data,
-            "language_code": self.language_code,
+            "language_id": self.language_id,
         }
         self.client.post(reverse('deviceprovision'), data, format="json")
         self.assertEqual(Role.objects.get().collection.name, self.facility_data["name"])
@@ -90,7 +90,7 @@ def test_dataset_set_created(self):
             "superuser": self.superuser_data,
             "facility": self.facility_data,
             "preset": self.preset_data,
-            "language_code": self.language_code,
+            "language_id": self.language_id,
         }
         self.client.post(reverse('deviceprovision'), data, format="json")
         self.assertEqual(FacilityDataset.objects.get().learner_can_edit_username, self.dataset_data["learner_can_edit_username"])