Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -141,7 +141,7 @@
night_mode = False if not app_settings.NIGHT_MODE_FEATURE_ENABLED else "night" in request.GET

if not permissions.can_play_level(request.user, level, app_settings.EARLY_ACCESS_FUNCTION(request)):
return renderError(request, messages.no_permission_title(), messages.not_shared_level())

Check warning on line 144 in game/views/level.py

View check run for this annotation

Codecov / codecov/patch

game/views/level.py#L144

Added line #L144 was not covered by tests

# Set default level description/hint lookups
lesson = "description_level_default"
Expand Down Expand Up @@ -283,7 +283,7 @@
if not request.user.is_anonymous and request.method == "POST" and hasattr(request.user.userprofile, "student"):
level = get_object_or_404(Level, id=request.POST.get("level", 1))
student = request.user.userprofile.student
attempt = Attempt.objects.filter(level=level, student=student, finish_time__isnull=True).first()

Check warning on line 286 in game/views/level.py

View check run for this annotation

Codecov / codecov/patch

game/views/level.py#L286

Added line #L286 was not covered by tests
if attempt:
attempt.score = float(request.POST.get("score"))
attempt.workspace = request.POST.get("workspace")
Expand Down Expand Up @@ -365,6 +365,7 @@
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"))

Check warning on line 368 in game/views/level.py

View check run for this annotation

Codecov / codecov/patch

game/views/level.py#L368

Added line #L368 was not covered by tests

workspace = None
if workspaceID:
Expand All @@ -378,6 +379,7 @@
workspace.python_contents = python_contents
workspace.blockly_enabled = blockly_enabled
workspace.python_enabled = python_enabled
workspace.python_view_enabled = python_view_enabled

Check warning on line 382 in game/views/level.py

View check run for this annotation

Codecov / codecov/patch

game/views/level.py#L382

Added line #L382 was not covered by tests
workspace.save()

return load_list_of_workspaces(request)
Expand Down
Loading