Skip to content

Commit

Permalink
fix: ocadotechnology#1436: load custom level should set correct language
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb Palmer committed Oct 6, 2023
1 parent c0a33b7 commit fe1fe61
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
18 changes: 18 additions & 0 deletions game/migrations/0083_workspace_python_view_enabled.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.20 on 2023-10-06 11:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('game', '0082_level_43_solution'),
]

operations = [
migrations.AddField(
model_name='workspace',
name='python_view_enabled',
field=models.BooleanField(default=False),
),
]
1 change: 1 addition & 0 deletions game/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,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)
Expand Down
6 changes: 4 additions & 2 deletions game/static/game/js/level_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
39 changes: 39 additions & 0 deletions game/tests/test_level_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 is True
assert new_level.pythonEnabled is False
assert new_level.blocklyEnabled is True

def test_level_loading(self):
email1, password1 = signup_teacher_directly()

Expand Down
2 changes: 2 additions & 0 deletions game/views/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,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:
Expand All @@ -382,6 +383,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)
Expand Down

0 comments on commit fe1fe61

Please sign in to comment.