Skip to content

Commit

Permalink
fix: #1436: load custom level should set correct language (#1491)
Browse files Browse the repository at this point in the history
* fix: #1436: load custom level should set correct language

* Merge branch 'master' into 1436-bugfix-set-language

* fix: #1436: load custom level should set correct language

* Merge branch 'master' of github.com:ocadotechnology/rapid-router into 1436-bugfix-set-language

* fix-test

* fix-test

* fix: migration

* fix: migration

Co-Authored-By: Seb Palmer <[email protected]>
  • Loading branch information
sebp999 and Seb Palmer authored Dec 20, 2023
1 parent 3c26016 commit cad596b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
18 changes: 18 additions & 0 deletions game/migrations/0087_workspace_python_view_enabled.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
1 change: 1 addition & 0 deletions game/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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
assert not new_level.pythonEnabled
assert new_level.blocklyEnabled

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 @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit cad596b

Please sign in to comment.