Skip to content

Commit

Permalink
fix: worksheet index (#1763)
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos authored Jan 17, 2025
1 parent b1e5451 commit 8fc40cb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
12 changes: 6 additions & 6 deletions game/templates/game/python_den_level_selection.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ <h4>Introduction to Python</h4>
<p class="text--warning">In order to access the full content for this course, please log in.</p>
{% endif %}
<div class="col-sm-10 python-den-level">
<a class="disabled">{{episode.name}}{% if episode.worksheets|length > 1 %} pt. {{ forloop.counter }}{% endif %}</a>
<a class="disabled">{{episode.name}}{% if episode.worksheets|length > 1 %} pt. {{ worksheet.index }}{% endif %}</a>
</div>
<div class="col-sm-2 python-den-level">
<a class="button button--level button--icon disabled">
Worksheet<span class="iconify" data-icon="mdi:open-in-new"></span></a>
</div>
{% else %}
<div class="col-sm-7 python-den-level">
<a href="https://editor.raspberrypi.org/en/projects/blank-python-starter" target="_blank">{{episode.name}}{% if episode.worksheets|length > 1 %} pt. {{ forloop.counter }}{% endif %}</a>
<a href="https://editor.raspberrypi.org/en/projects/blank-python-starter" target="_blank">{{episode.name}}{% if episode.worksheets|length > 1 %} pt. {{ worksheet.index }}{% endif %}</a>
</div>
{% if user|is_logged_in_as_teacher %}
<div class="col-sm-3 python-den-level">
Expand Down Expand Up @@ -161,15 +161,15 @@ <h4>Introduction to Python</h4>
<p class="text--warning">In order to access the full content for this course, please log in.</p>
{% endif %}
<div class="col-sm-10 python-den-level">
<a class="disabled">{{episode.name}}{% if episode.worksheets|length > 1 %} pt. {{ forloop.counter }}{% endif %}</a>
<a class="disabled">{{episode.name}}{% if episode.worksheets|length > 1 %} pt. {{ worksheet.index }}{% endif %}</a>
</div>
<div class="col-sm-2 python-den-level">
<a class="button button--level button--icon disabled">
Worksheet<span class="iconify" data-icon="mdi:open-in-new"></span></a>
</div>
{% else %}
<div class="col-sm-7 python-den-level">
<a href="https://editor.raspberrypi.org/en/projects/blank-python-starter" target="_blank">{{episode.name}}{% if episode.worksheets|length > 1 %} pt. {{ forloop.counter }}{% endif %}</a>
<a href="https://editor.raspberrypi.org/en/projects/blank-python-starter" target="_blank">{{episode.name}}{% if episode.worksheets|length > 1 %} pt. {{ worksheet.index }}{% endif %}</a>
</div>
{% if user|is_logged_in_as_teacher %}
<div class="col-sm-3 python-den-level">
Expand Down Expand Up @@ -234,15 +234,15 @@ <h4>Introduction to Python</h4>
<p class="text--warning">In order to access the full content for this course, please log in.</p>
{% endif %}
<div class="col-sm-10 python-den-level">
<a class="disabled">{{episode.name}}{% if episode.worksheets|length > 1 %} pt. {{ forloop.counter }}{% endif %}</a>
<a class="disabled">{{episode.name}}{% if episode.worksheets|length > 1 %} pt. {{ worksheet.index }}{% endif %}</a>
</div>
<div class="col-sm-2 python-den-level">
<a class="button button--level button--icon disabled">
Worksheet<span class="iconify" data-icon="mdi:open-in-new"></span></a>
</div>
{% else %}
<div class="col-sm-7 python-den-level">
<a href="https://editor.raspberrypi.org/en/projects/blank-python-starter" target="_blank">{{episode.name}}{% if episode.worksheets|length > 1 %} pt. {{ forloop.counter }}{% endif %}</a>
<a href="https://editor.raspberrypi.org/en/projects/blank-python-starter" target="_blank">{{episode.name}}{% if episode.worksheets|length > 1 %} pt. {{ worksheet.index }}{% endif %}</a>
</div>
{% if user|is_logged_in_as_teacher %}
<div class="col-sm-3 python-den-level">
Expand Down
70 changes: 48 additions & 22 deletions game/views/level_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,55 @@ def fetch_episode_data(early_access, start=1, end=12):
data = fetch_episode_data_from_database(early_access, start, end)
cache.set(key, data)

return [
dict(
episode,
name=messages.get_episode_title(episode["id"]),
levels=[
dict(level, title=get_level_title(level["name"]))
for level in episode["levels"]
],
worksheets=[
{
"id": worksheet.id,
"before_level": worksheet.before_level_id,
"lesson_plan_link": worksheet.lesson_plan_link,
"slides_link": worksheet.slides_link,
"student_worksheet_link": worksheet.student_worksheet_link,
"indy_worksheet_link": worksheet.indy_worksheet_link,
"video_link": worksheet.video_link,
}
for worksheet in Worksheet.objects.filter(episode=episode["id"]).order_by("-before_level")
],
def worksheet_to_dict(index, worksheet):
return {
"id": worksheet.id,
"index": index,
"before_level": worksheet.before_level_id,
"lesson_plan_link": worksheet.lesson_plan_link,
"slides_link": worksheet.slides_link,
"student_worksheet_link": worksheet.student_worksheet_link,
"indy_worksheet_link": worksheet.indy_worksheet_link,
"video_link": worksheet.video_link,
}

episodes = []
for episode in data:
worksheets = [
worksheet_to_dict(index, worksheet)
for index, worksheet in enumerate(
Worksheet.objects.filter(
episode=episode["id"],
before_level__isnull=False,
).order_by("before_level"),
start=1,
)
]

worksheets += [
worksheet_to_dict(index, worksheet)
for index, worksheet in enumerate(
Worksheet.objects.filter(
episode=episode["id"],
before_level__isnull=True,
),
start=1 + len(worksheets),
)
]

episodes.append(
dict(
episode,
name=messages.get_episode_title(episode["id"]),
levels=[
dict(level, title=get_level_title(level["name"]))
for level in episode["levels"]
],
worksheets=worksheets,
)
)
for episode in data
]

return episodes


def get_level_title(i):
Expand Down

0 comments on commit 8fc40cb

Please sign in to comment.