Skip to content

Commit

Permalink
fix: Updates for Python Den (#2338)
Browse files Browse the repository at this point in the history
* Rename level name param in URL

* Remove Python levels from level control form

* Update student dashboards to only pull data from Blockly levels
  • Loading branch information
faucomte97 authored Aug 23, 2024
1 parent ed50438 commit 9f19fc3
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 65 deletions.
2 changes: 1 addition & 1 deletion portal/forms/teach.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class ClassLevelControlForm(forms.Form):
def __init__(self, *args, **kwargs):
super(ClassLevelControlForm, self).__init__(*args, **kwargs)

episodes = Episode.objects.all()
episodes = Episode.objects.filter(pk__in=range(1, 10))

for episode in episodes:
levels = []
Expand Down
52 changes: 1 addition & 51 deletions portal/templates/portal/teach/teacher_edit_class.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ <h5>Rapid Router access settings</h5>

<div id="episodes">
<div class="panel-intro d-flex align-items-center justify-content-between">
<h6>Blockly levels</h6>
<h6>Rapid Router levels</h6>
<label class="pr-5 mb-0 mr-5">
<input type="checkbox" id="select-all-blockly-levels">
</label>
Expand Down Expand Up @@ -140,56 +140,6 @@ <h6>Blockly levels</h6>
</div>
</div>
{% endfor %}

<div class="panel-intro d-flex align-items-center justify-content-between">
<h6>Python levels</h6>
<label class="pr-5 mb-0 mr-5">
<input type="checkbox" id="select-all-python-levels">
</label>
</div>
{% for episode in python_episodes %}
<div
class="panel"
{% if "coming soon" in episode.name %}
style="pointer-events:none;"
{% endif %}
>
<div class="panel-header bg--{{ episode.difficulty }}" id="episode-{{episode.id}}">
<div class="d-flex align-items-center justify-content-end" data-toggle="collapse"
data-target="#collapse-{{episode.id}}" aria-expanded="false"
aria-controls="collapse-{{episode.id}}" data-parent="#episodes">
<p class="episode-title flex-grow-1">{{episode.name}}</p>
<span>Levels {{episode.first_level}}-{{episode.last_level}}</span>
<div class="episode_range_text collapsed d-flex align-items-center justify-content-end"
data-toggle="collapse" data-target="#collapse-{{episode.id}}"
aria-expanded="false" aria-controls="collapse-{{episode.id}}" data-parent="#episodes">
{% if "coming soon" not in episode.name %}
<label id="episode-label-{{ episode.id }}" class="mb-0" for="select-all-episode-levels">
<input type="checkbox" value="{{ episode.name }}" id="select-all-python-levels-{{ episode.id }}">
</label>
{% endif %}
</div>
</div>
</div>

<div id="collapse-{{episode.id}}" aria-labelledby="episode-{{episode.id}}" class="collapse">
<div class="panel-body d-flex justify-content-between">
<div class="d-flex flex-grow-1 flex-column justify-content-between">
{% for level in episode.levels %}
<p>{{level.name}}: {{level.title.strip | safe}}</p>
{% endfor %}
</div>
<div class="form__checkbox flex-column justify-content-between p-0">
{% for input in level_control_form|get_dict_item:episode.name %}
<div class="form__checkbox-input p-0">
{{ input }}
</div>
{% endfor %}
</div>
</div>
</div>
</div>
{% endfor %}
</div>

<div class="button-group">
Expand Down
48 changes: 48 additions & 0 deletions portal/tests/snapshots/snap_test_partials.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,51 @@
</div>
</div>
'''

snapshots['test_benefits 1'] = '''
<div class="grid-benefits col-sm-8 col-center">
<h5 class="grid-benefits__title grid-benefits__title1">Test title</h5>
<h5 class="grid-benefits__title grid-benefits__title2">Test title</h5>
<h5 class="grid-benefits__title grid-benefits__title3">Test title</h5>
<p class="grid-benefits__text1">Test text</p>
<p class="grid-benefits__text2">Test text</p>
<p class="grid-benefits__text3">Test text</p>
<div class="grid-benefits__button grid-benefits__button1">
<a href="/" class="button button--secondary button--secondary--dark">Test button</a>
</div>
<div class="grid-benefits__button grid-benefits__button2">
<a href="/" class="button button--secondary button--secondary--dark">Test button</a>
</div>
<div class="grid-benefits__button grid-benefits__button3">
<a href="/" class="button button--secondary button--secondary--dark">Test button</a>
</div>
</div>
'''

snapshots['test_headline 1'] = '''<section>
<h4>Test title</h4>
</section>
<p class="container">Test description</p>
'''
6 changes: 3 additions & 3 deletions portal/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,15 +563,15 @@ def test_student_dashboard_view(self):
"num_completed": 0,
"num_top_scores": 0,
"total_score": 0,
"total_available_score": 2040,
"total_available_score": 1450,
}

# Expected context data when a student has attempted some RR levels
EXPECTED_DATA_WITH_ATTEMPTS = {
"num_completed": 2,
"num_top_scores": 1,
"total_score": 39,
"total_available_score": 2040,
"total_available_score": 1450,
}

# Expected context data when a student has also attempted some custom RR
Expand All @@ -580,7 +580,7 @@ def test_student_dashboard_view(self):
"num_completed": 2,
"num_top_scores": 1,
"total_score": 39,
"total_available_score": 2040,
"total_available_score": 1450,
"total_custom_score": 10,
"total_custom_available_score": 20,
}
Expand Down
2 changes: 1 addition & 1 deletion portal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
url(r"^i18n/", include("django.conf.urls.i18n")),
url(r"^jsi18n/$", JavaScriptCatalog.as_view(), js_info_dict),
url(
r"^(?P<levelName>[A-Z0-9]+)/$",
r"^(?P<level_name>[A-Z0-9]+)/$",
play_default_level,
name="play_default_level",
),
Expand Down
4 changes: 2 additions & 2 deletions portal/views/student/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
the student's scores for any levels shared with them by their teacher.
"""
# Get score data for all original levels
levels = Level.objects.sorted_levels()
levels = Level.objects.filter(episode__pk__in=range(1, 10))
student = self.request.user.new_student

context_data = _compute_rapid_router_scores(student, levels)
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_func(self) -> Optional[bool]:
return logged_in_as_independent_student(self.request.user)

def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
levels = Level.objects.sorted_levels()
levels = Level.objects.filter(episode__pk__in=range(1, 10))
student = self.request.user.new_student

return _compute_rapid_router_scores(
Expand Down
10 changes: 3 additions & 7 deletions portal/views/teacher/teach.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from django.urls import reverse, reverse_lazy
from django.utils import timezone
from django.views.decorators.http import require_POST
from game.views.level_selection import get_blockly_episodes, get_python_episodes
from game.views.level_selection import get_blockly_episodes
from portal.views.registration import handle_reset_password_tracking
from reportlab.lib.colors import black, red
from reportlab.lib.pagesizes import A4
Expand Down Expand Up @@ -256,7 +256,6 @@ def teacher_edit_class(request, access_code):
external_requests_message = klass.get_requests_message()

blockly_episodes = get_blockly_episodes(request)
python_episodes = get_python_episodes(request)

locked_levels = klass.locked_levels.all()
locked_levels_ids = [locked_level.id for locked_level in locked_levels]
Expand All @@ -273,7 +272,7 @@ def teacher_edit_class(request, access_code):
elif "level_control_submit" in request.POST:
level_control_form = ClassLevelControlForm(request.POST)
if level_control_form.is_valid():
return process_level_control_form(request, klass, blockly_episodes, python_episodes)
return process_level_control_form(request, klass, blockly_episodes)
elif "class_move_submit" in request.POST:
class_move_form = ClassMoveForm(other_teachers, request.POST)
if class_move_form.is_valid():
Expand All @@ -287,7 +286,6 @@ def teacher_edit_class(request, access_code):
"class_move_form": class_move_form,
"level_control_form": level_control_form,
"blockly_episodes": blockly_episodes,
"python_episodes": python_episodes,
"locked_levels": locked_levels_ids,
"class": klass,
"external_requests_message": external_requests_message,
Expand Down Expand Up @@ -338,19 +336,17 @@ def process_edit_class_form(request, klass, form):
return HttpResponseRedirect(reverse_lazy("view_class", kwargs={"access_code": klass.access_code}))


def process_level_control_form(request, klass, blockly_episodes, python_episodes):
def process_level_control_form(request, klass, blockly_episodes):
"""
Find the levels that the user wants to lock and lock them for the specific class.
:param request: The request sent by the user submitting the form.
:param klass: The class for which the levels are being locked / unlocked.
:param blockly_episodes: The set of Blockly Episodes in the game.
:param python_episodes: The set of Python Episodes in the game.
:return: A redirect to the teacher dashboard with a success message.
"""
levels_to_lock_ids = []

mark_levels_to_lock_in_episodes(request, blockly_episodes, levels_to_lock_ids)
mark_levels_to_lock_in_episodes(request, python_episodes, levels_to_lock_ids)

klass.locked_levels.clear()
[klass.locked_levels.add(levels_to_lock_id) for levels_to_lock_id in levels_to_lock_ids]
Expand Down

0 comments on commit 9f19fc3

Please sign in to comment.