Skip to content

Commit

Permalink
fix: Use correct level name limit for next level URL (#1722)
Browse files Browse the repository at this point in the history
* fix: Use correct level name limit for next level URL

* Use correct value

* Fix test
  • Loading branch information
faucomte97 authored Sep 4, 2024
1 parent 0ad757b commit dded4c6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion game/tests/test_level_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def test_next_level_for_locked_levels(self):
level1014, student.new_user, False, True
)

assert next_level_url == f"/pythonden/15/"
assert next_level_url == f"/pythonden/16/"

prev_level_url = _prev_level_url(
level1016, student.new_user, False, True
Expand Down
42 changes: 31 additions & 11 deletions game/views/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def _prev_level_url(level, user, night_mode, from_python_den):
if is_prev_level_locked:
while is_prev_level_locked and int(prev_level.name) > 1:
prev_level = prev_level.prev_level.all()[0]
is_prev_level_locked = klass in prev_level.locked_for_class.all()
is_prev_level_locked = (
klass in prev_level.locked_for_class.all()
)

return _level_url(prev_level, night_mode, from_python_den)

Expand Down Expand Up @@ -107,10 +109,12 @@ def _next_level_url(level, user, night_mode, from_python_den):

if is_next_level_locked:
while is_next_level_locked and (
int(next_level.name) < 60 if from_python_den else 80
int(next_level.name) < 1050 if from_python_den else 80
):
next_level = next_level.next_level
is_next_level_locked = klass in next_level.locked_for_class.all()
is_next_level_locked = (
klass in next_level.locked_for_class.all()
)

return _level_url(next_level, night_mode, from_python_den)

Expand All @@ -131,7 +135,9 @@ def _level_url(level, night_mode, from_python_den):


def _default_level_url(level, from_python_den):
viewname = "play_python_default_level" if from_python_den else "play_default_level"
viewname = (
"play_python_default_level" if from_python_den else "play_default_level"
)

level_name = int(level.name) - 1000 if from_python_den else level.name

Expand Down Expand Up @@ -163,7 +169,9 @@ def play_level(request, level, from_editor=False, from_python_den=False):
"""

night_mode = (
False if not app_settings.NIGHT_MODE_FEATURE_ENABLED else "night" in request.GET
False
if not app_settings.NIGHT_MODE_FEATURE_ENABLED
else "night" in request.GET
)

if not permissions.can_play_level(
Expand All @@ -186,7 +194,9 @@ def play_level(request, level, from_editor=False, from_python_den=False):
)
commands_attr = "commands_level" + str(level.name)
commands = (
getattr(messages, commands_attr, None) if level.default else level.commands
getattr(messages, commands_attr, None)
if level.default
else level.commands
)
character = level.character
character_url = character.top_down
Expand All @@ -210,7 +220,9 @@ def play_level(request, level, from_editor=False, from_python_den=False):

workspace = None
python_workspace = None
if not request.user.is_anonymous and hasattr(request.user.userprofile, "student"):
if not request.user.is_anonymous and hasattr(
request.user.userprofile, "student"
):
student = request.user.userprofile.student
attempt = (
Attempt.objects.filter(
Expand Down Expand Up @@ -249,7 +261,9 @@ def play_level(request, level, from_editor=False, from_python_den=False):
return_view = (
"level_editor"
if from_editor
else "python_levels" if from_python_den else "levels"
else "python_levels"
if from_python_den
else "levels"
)

temp_block_data = []
Expand Down Expand Up @@ -294,7 +308,9 @@ def play_level(request, level, from_editor=False, from_python_den=False):
"next_level_url": _next_level_url(
level, request.user, night_mode, from_python_den
),
"flip_night_mode_url": _level_url(level, not night_mode, from_python_den),
"flip_night_mode_url": _level_url(
level, not night_mode, from_python_den
),
"available_language_dict": language_code_dict,
},
)
Expand Down Expand Up @@ -383,7 +399,9 @@ def close_and_reset(attempt):
def load_list_of_workspaces(request):
workspaces_owned = []
if permissions.can_create_workspace(request.user):
workspaces_owned = Workspace.objects.filter(owner=request.user.userprofile)
workspaces_owned = Workspace.objects.filter(
owner=request.user.userprofile
)

workspaces = [
{
Expand Down Expand Up @@ -423,7 +441,9 @@ def save_workspace(request, workspaceID=None):
"python_enabled",
"pythonViewEnabled",
]
missing_params = [param for param in request_params if param not in request.POST]
missing_params = [
param for param in request_params if param not in request.POST
]
if missing_params != []:
raise Exception(
"Request missing the following required parameters", missing_params
Expand Down

0 comments on commit dded4c6

Please sign in to comment.