diff --git a/game/migrations/0087_workspace_python_view_enabled.py b/game/migrations/0087_workspace_python_view_enabled.py new file mode 100644 index 000000000..29b4cdd2e --- /dev/null +++ b/game/migrations/0087_workspace_python_view_enabled.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.23 on 2023-12-19 21:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('game', '0086_loop_levels'), + ] + + operations = [ + migrations.AddField( + model_name='workspace', + name='python_view_enabled', + field=models.BooleanField(default=False), + ), + ] diff --git a/game/models.py b/game/models.py index ffe474158..23d1f5ea9 100644 --- a/game/models.py +++ b/game/models.py @@ -226,6 +226,7 @@ class Workspace(models.Model): python_contents = models.TextField(default="") blockly_enabled = models.BooleanField(default=False) python_enabled = models.BooleanField(default=False) + python_view_enabled = models.BooleanField(default=False) def __str__(self): return str(self.name) diff --git a/game/static/game/js/level_editor.js b/game/static/game/js/level_editor.js index c177eff27..5309b0461 100644 --- a/game/static/game/js/level_editor.js +++ b/game/static/game/js/level_editor.js @@ -2331,8 +2331,10 @@ ocargo.LevelEditor = function(levelId) { } // Load in language data - var languageSelect = $('#languageSelect'); - if(state.blocklyEnabled && state.pythonEnabled) { + var languageSelect = $('#language_select'); + if (state.blocklyEnabled && state.pythonViewEnabled){ + languageSelect.val('blocklyWithPythonView'); + } else if(state.blocklyEnabled && state.pythonEnabled) { languageSelect.val('both'); } else if(state.pythonEnabled) { languageSelect.val('python'); diff --git a/game/tests/test_level_editor.py b/game/tests/test_level_editor.py index 6b5beea3b..8cbe90391 100644 --- a/game/tests/test_level_editor.py +++ b/game/tests/test_level_editor.py @@ -296,6 +296,45 @@ def test_no_character_set_defaults_to_van(self): new_level = Level.objects.get(name="abc") assert new_level.character.name == "Van" + def test_language_set_appropriately(self): + + email, password = signup_teacher_directly() + create_organisation_directly(email) + _, class_name, access_code = create_class_directly(email) + student_name, student_password, _ = create_school_student_directly(access_code) + + self.student_login(student_name, access_code, student_password) + url = reverse("save_level_for_editor") + data_with_split_language = { + "origin": '{"coordinate":[3,5],"direction":"S"}', + "pythonEnabled": False, + "decor": [], + "blocklyEnabled": True, + "blocks": [ + {"type": "move_forwards"}, + {"type": "turn_left"}, + {"type": "turn_right"}, + ], + "max_fuel": "50", + "pythonViewEnabled": True, + "name": "abc", + "theme": 1, + "anonymous": True, + "cows": "[]", + "path": '[{"coordinate":[3,5],"connectedNodes":[1]},{"coordinate":[3,4],' + '"connectedNodes":[0]}]', + "traffic_lights": "[]", + "destinations": "[[3,4]]", + } + response = self.client.post(url, {"data": json.dumps(data_with_split_language)}) + + assert response.status_code == 200 + new_level = Level.objects.get(name="abc") + + assert new_level.pythonViewEnabled + assert not new_level.pythonEnabled + assert new_level.blocklyEnabled + def test_level_loading(self): email1, password1 = signup_teacher_directly() diff --git a/game/views/level.py b/game/views/level.py index 4bc222cc6..865edc7b2 100644 --- a/game/views/level.py +++ b/game/views/level.py @@ -365,6 +365,7 @@ def save_workspace(request, workspaceID=None): python_contents = request.POST.get("python_contents") blockly_enabled = json.loads(request.POST.get("blockly_enabled")) python_enabled = json.loads(request.POST.get("python_enabled")) + python_view_enabled = json.loads(request.POST.get("pythonViewEnabled")) workspace = None if workspaceID: @@ -378,6 +379,7 @@ def save_workspace(request, workspaceID=None): workspace.python_contents = python_contents workspace.blockly_enabled = blockly_enabled workspace.python_enabled = python_enabled + workspace.python_view_enabled = python_view_enabled workspace.save() return load_list_of_workspaces(request)