prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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
  
  </issue>
  <code>
  [start of kolibri/core/device/serializers.py]
  1 from django.db import transaction
  2 from django.utils.translation import check_for_language, ugettext_lazy as _
  3 from kolibri.auth.constants.facility_presets import choices, mappings
  4 from kolibri.auth.constants.role_kinds import ADMIN
  5 from kolibri.auth.models import Facility, FacilityUser
  6 from kolibri.auth.serializers import FacilitySerializer, FacilityUserSerializer
  7 from rest_framework import serializers
  8 
  9 from .models import DevicePermissions, DeviceSettings
  10 
  11 
  12 class DevicePermissionsSerializer(serializers.ModelSerializer):
  13 
  14     class Meta:
  15         model = DevicePermissions
  16         fields = (
  17             'user', 'is_superuser', 'can_manage_content',
  18         )
  19 
  20 class NoFacilityFacilityUserSerializer(FacilityUserSerializer):
  21 
  22     class Meta:
  23         model = FacilityUser
  24         fields = ('id', 'username', 'full_name', 'password', )
  25 
  26 
  27 class DeviceProvisionSerializer(serializers.Serializer):
  28     facility = FacilitySerializer()
  29     preset = serializers.ChoiceField(choices=choices)
  30     superuser = NoFacilityFacilityUserSerializer()
  31     language_code = serializers.CharField(max_length=15)
  32 
  33     class Meta:
  34         fields = ('facility', 'dataset', 'superuser', 'language_code')
  35 
  36     def validate_language_code(self, language_code):
  37         """
  38         Check that the language_code is supported by Kolibri
  39         """
  40         if not check_for_language(language_code):
  41             raise serializers.ValidationError(_("Language is not supported by Kolibri"))
  42         return language_code
  43 
  44     def create(self, validated_data):
  45         """
  46         Endpoint for initial setup of a device.
  47         Expects a value for:
  48         default language - the default language of this Kolibri device
  49         facility - the required fields for setting up a facility
  50         facilitydataset - facility configuration options
  51         superuser - the required fields for a facilityuser who will be set as the super user for this device
  52         """
  53         with transaction.atomic():
  54             facility = Facility.objects.create(**validated_data.pop('facility'))
  55             preset = validated_data.pop('preset')
  56             dataset_data = mappings[preset]
  57             for key, value in dataset_data.items():
  58                 setattr(facility.dataset, key, value)
  59             facility.dataset.save()
  60             superuser_data = validated_data.pop('superuser')
  61             superuser_data['facility'] = facility
  62             superuser = FacilityUserSerializer(data=superuser_data).create(superuser_data)
  63             facility.add_role(superuser, ADMIN)
  64             DevicePermissions.objects.create(user=superuser, is_superuser=True)
  65             language_code = validated_data.pop('language_code')
  66             device_settings, created = DeviceSettings.objects.get_or_create()
  67             device_settings.is_provisioned = True
  68             device_settings.language_code = language_code
  69             device_settings.save()
  70             return {
  71                 "facility": facility,
  72                 "preset": preset,
  73                 "superuser": superuser,
  74                 "language_code": language_code
  75             }
  76
  [end of kolibri/core/device/serializers.py]
  [start of kolibri/core/device/models.py]
  1 from django.conf import settings
  2 from django.db import models
  3 from kolibri.auth.models import FacilityUser
  4 
  5 from .permissions import UserCanManageDevicePermissions
  6 
  7 
  8 class DevicePermissions(models.Model):
  9     """
  10     This class stores metadata about device permissions for FacilityUsers.
  11     """
  12 
  13     permissions = UserCanManageDevicePermissions()
  14 
  15     user = models.OneToOneField(FacilityUser, on_delete=models.CASCADE, related_name='devicepermissions', blank=False, null=False, primary_key=True)
  16     is_superuser = models.BooleanField(default=False)
  17     can_manage_content = models.BooleanField(default=False)
  18 
  19 
  20 class DeviceSettings(models.Model):
  21     """
  22     This class stores data about settings particular to this device
  23     """
  24 
  25     is_provisioned = models.BooleanField(default=False)
  26     language_code = models.CharField(max_length=15, default=settings.LANGUAGE_CODE)
  27 
  28     def save(self, *args, **kwargs):
  29         self.pk = 1
  30         super(DeviceSettings, self).save(*args, **kwargs)
  31
  [end of kolibri/core/device/models.py]
  [start of kolibri/core/device/migrations/0001_initial.py]
  1 # -*- coding: utf-8 -*-
  2 # Generated by Django 1.9.7 on 2017-08-16 23:05
  3 from __future__ import unicode_literals
  4 
  5 import django.db.models.deletion
  6 from django.conf import settings
  7 from django.db import migrations, models
  8 
  9 
  10 class Migration(migrations.Migration):
  11 
  12     initial = True
  13 
  14     dependencies = [
  15         ('kolibriauth', '0003_auto_20170621_0958'),
  16     ]
  17 
  18     operations = [
  19         migrations.CreateModel(
  20             name='DevicePermissions',
  21             fields=[
  22                 ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='devicepermissions', serialize=False, to=settings.AUTH_USER_MODEL)),
  23                 ('is_superuser', models.BooleanField(default=False)),
  24                 ('can_manage_content', models.BooleanField(default=False)),
  25             ],
  26         ),
  27         migrations.CreateModel(
  28             name='DeviceSettings',
  29             fields=[
  30                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
  31                 ('is_provisioned', models.BooleanField(default=False)),
  32                 ('language_code', models.CharField(default='en', max_length=15)),
  33             ],
  34         ),
  35     ]
  36
  [end of kolibri/core/device/migrations/0001_initial.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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 @@
               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 @@
       """
   
       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 @@
       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 @@
               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
               }
  
verification_info: {"golden_diff": "diff --git a/kolibri/core/device/migrations/0001_initial.py b/kolibri/core/device/migrations/0001_initial.py\n--- a/kolibri/core/device/migrations/0001_initial.py\n+++ b/kolibri/core/device/migrations/0001_initial.py\n@@ -29,7 +29,7 @@\n             fields=[\n                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n                 ('is_provisioned', models.BooleanField(default=False)),\n-                ('language_code', models.CharField(default='en', max_length=15)),\n+                ('language_id', models.CharField(default='en', max_length=15)),\n             ],\n         ),\n     ]\ndiff --git a/kolibri/core/device/models.py b/kolibri/core/device/models.py\n--- a/kolibri/core/device/models.py\n+++ b/kolibri/core/device/models.py\n@@ -23,7 +23,7 @@\n     \"\"\"\n \n     is_provisioned = models.BooleanField(default=False)\n-    language_code = models.CharField(max_length=15, default=settings.LANGUAGE_CODE)\n+    language_id = models.CharField(max_length=15, default=settings.LANGUAGE_CODE)\n \n     def save(self, *args, **kwargs):\n         self.pk = 1\ndiff --git a/kolibri/core/device/serializers.py b/kolibri/core/device/serializers.py\n--- a/kolibri/core/device/serializers.py\n+++ b/kolibri/core/device/serializers.py\n@@ -28,18 +28,18 @@\n     facility = FacilitySerializer()\n     preset = serializers.ChoiceField(choices=choices)\n     superuser = NoFacilityFacilityUserSerializer()\n-    language_code = serializers.CharField(max_length=15)\n+    language_id = serializers.CharField(max_length=15)\n \n     class Meta:\n-        fields = ('facility', 'dataset', 'superuser', 'language_code')\n+        fields = ('facility', 'dataset', 'superuser', 'language_id')\n \n-    def validate_language_code(self, language_code):\n+    def validate_language_id(self, language_id):\n         \"\"\"\n-        Check that the language_code is supported by Kolibri\n+        Check that the language_id is supported by Kolibri\n         \"\"\"\n-        if not check_for_language(language_code):\n+        if not check_for_language(language_id):\n             raise serializers.ValidationError(_(\"Language is not supported by Kolibri\"))\n-        return language_code\n+        return language_id\n \n     def create(self, validated_data):\n         \"\"\"\n@@ -62,14 +62,14 @@\n             superuser = FacilityUserSerializer(data=superuser_data).create(superuser_data)\n             facility.add_role(superuser, ADMIN)\n             DevicePermissions.objects.create(user=superuser, is_superuser=True)\n-            language_code = validated_data.pop('language_code')\n+            language_id = validated_data.pop('language_id')\n             device_settings, created = DeviceSettings.objects.get_or_create()\n             device_settings.is_provisioned = True\n-            device_settings.language_code = language_code\n+            device_settings.language_id = language_id\n             device_settings.save()\n             return {\n                 \"facility\": facility,\n                 \"preset\": preset,\n                 \"superuser\": superuser,\n-                \"language_code\": language_code\n+                \"language_id\": language_id\n             }\n", "issue": "Setup wizard is broken\n## Summary\r\n\r\n* Submitting the setup wizard returns `{language_code: [\"This field is required.\"]}`\r\n\r\n## System information\r\n\r\n - Version: 0.6\r\n\r\n## How to reproduce\r\n\r\n1. Go through setup wizard\r\n\r\n## Real-life consequences\r\n\r\nSadness\n", "before_files": [{"content": "from django.db import transaction\nfrom django.utils.translation import check_for_language, ugettext_lazy as _\nfrom kolibri.auth.constants.facility_presets import choices, mappings\nfrom kolibri.auth.constants.role_kinds import ADMIN\nfrom kolibri.auth.models import Facility, FacilityUser\nfrom kolibri.auth.serializers import FacilitySerializer, FacilityUserSerializer\nfrom rest_framework import serializers\n\nfrom .models import DevicePermissions, DeviceSettings\n\n\nclass DevicePermissionsSerializer(serializers.ModelSerializer):\n\n    class Meta:\n        model = DevicePermissions\n        fields = (\n            'user', 'is_superuser', 'can_manage_content',\n        )\n\nclass NoFacilityFacilityUserSerializer(FacilityUserSerializer):\n\n    class Meta:\n        model = FacilityUser\n        fields = ('id', 'username', 'full_name', 'password', )\n\n\nclass DeviceProvisionSerializer(serializers.Serializer):\n    facility = FacilitySerializer()\n    preset = serializers.ChoiceField(choices=choices)\n    superuser = NoFacilityFacilityUserSerializer()\n    language_code = serializers.CharField(max_length=15)\n\n    class Meta:\n        fields = ('facility', 'dataset', 'superuser', 'language_code')\n\n    def validate_language_code(self, language_code):\n        \"\"\"\n        Check that the language_code is supported by Kolibri\n        \"\"\"\n        if not check_for_language(language_code):\n            raise serializers.ValidationError(_(\"Language is not supported by Kolibri\"))\n        return language_code\n\n    def create(self, validated_data):\n        \"\"\"\n        Endpoint for initial setup of a device.\n        Expects a value for:\n        default language - the default language of this Kolibri device\n        facility - the required fields for setting up a facility\n        facilitydataset - facility configuration options\n        superuser - the required fields for a facilityuser who will be set as the super user for this device\n        \"\"\"\n        with transaction.atomic():\n            facility = Facility.objects.create(**validated_data.pop('facility'))\n            preset = validated_data.pop('preset')\n            dataset_data = mappings[preset]\n            for key, value in dataset_data.items():\n                setattr(facility.dataset, key, value)\n            facility.dataset.save()\n            superuser_data = validated_data.pop('superuser')\n            superuser_data['facility'] = facility\n            superuser = FacilityUserSerializer(data=superuser_data).create(superuser_data)\n            facility.add_role(superuser, ADMIN)\n            DevicePermissions.objects.create(user=superuser, is_superuser=True)\n            language_code = validated_data.pop('language_code')\n            device_settings, created = DeviceSettings.objects.get_or_create()\n            device_settings.is_provisioned = True\n            device_settings.language_code = language_code\n            device_settings.save()\n            return {\n                \"facility\": facility,\n                \"preset\": preset,\n                \"superuser\": superuser,\n                \"language_code\": language_code\n            }\n", "path": "kolibri/core/device/serializers.py"}, {"content": "from django.conf import settings\nfrom django.db import models\nfrom kolibri.auth.models import FacilityUser\n\nfrom .permissions import UserCanManageDevicePermissions\n\n\nclass DevicePermissions(models.Model):\n    \"\"\"\n    This class stores metadata about device permissions for FacilityUsers.\n    \"\"\"\n\n    permissions = UserCanManageDevicePermissions()\n\n    user = models.OneToOneField(FacilityUser, on_delete=models.CASCADE, related_name='devicepermissions', blank=False, null=False, primary_key=True)\n    is_superuser = models.BooleanField(default=False)\n    can_manage_content = models.BooleanField(default=False)\n\n\nclass DeviceSettings(models.Model):\n    \"\"\"\n    This class stores data about settings particular to this device\n    \"\"\"\n\n    is_provisioned = models.BooleanField(default=False)\n    language_code = models.CharField(max_length=15, default=settings.LANGUAGE_CODE)\n\n    def save(self, *args, **kwargs):\n        self.pk = 1\n        super(DeviceSettings, self).save(*args, **kwargs)\n", "path": "kolibri/core/device/models.py"}, {"content": "# -*- coding: utf-8 -*-\n# Generated by Django 1.9.7 on 2017-08-16 23:05\nfrom __future__ import unicode_literals\n\nimport django.db.models.deletion\nfrom django.conf import settings\nfrom django.db import migrations, models\n\n\nclass Migration(migrations.Migration):\n\n    initial = True\n\n    dependencies = [\n        ('kolibriauth', '0003_auto_20170621_0958'),\n    ]\n\n    operations = [\n        migrations.CreateModel(\n            name='DevicePermissions',\n            fields=[\n                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='devicepermissions', serialize=False, to=settings.AUTH_USER_MODEL)),\n                ('is_superuser', models.BooleanField(default=False)),\n                ('can_manage_content', models.BooleanField(default=False)),\n            ],\n        ),\n        migrations.CreateModel(\n            name='DeviceSettings',\n            fields=[\n                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n                ('is_provisioned', models.BooleanField(default=False)),\n                ('language_code', models.CharField(default='en', max_length=15)),\n            ],\n        ),\n    ]\n", "path": "kolibri/core/device/migrations/0001_initial.py"}]}