Skip to content

Commit

Permalink
[FEATURE] Implements Parsons with syntax highlighting (hedyorg#2761)
Browse files Browse the repository at this point in the history
Co-authored-by: C.L.M. Marosvölgyi <[email protected]>
Co-authored-by: xxxpokemon <[email protected]>
Co-authored-by: Felienne <[email protected]>
  • Loading branch information
4 people authored May 19, 2022
1 parent e428159 commit 78b2afd
Show file tree
Hide file tree
Showing 38 changed files with 4,663 additions and 181 deletions.
34 changes: 30 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# coding=utf-8
import random

from website import auth
from website import statistics
from website import quiz
Expand All @@ -17,7 +19,7 @@
import hedyweb
import hedy_content
from flask_babel import gettext
from flask_babel import Babel, refresh
from flask_babel import Babel
from flask_compress import Compress
from flask_helpers import render_template
from flask import Flask, request, jsonify, session, abort, g, redirect, Response, make_response, Markup
Expand All @@ -26,7 +28,6 @@
from babel import Locale
from flask_commonmark import Commonmark
import traceback
import re
import logging
import json
import hedy
Expand Down Expand Up @@ -58,6 +59,10 @@
for lang in ALL_LANGUAGES.keys():
ADVENTURES[lang] = hedy_content.Adventures(lang)

PARSONS = collections.defaultdict()
for lang in ALL_LANGUAGES.keys():
PARSONS[lang] = hedy_content.ParsonsProblem(lang)

QUIZZES = collections.defaultdict(hedy_content.NoSuchQuiz)
for lang in ALL_LANGUAGES.keys():
QUIZZES[lang] = hedy_content.Quizzes(lang)
Expand Down Expand Up @@ -97,6 +102,25 @@ def int(s):
""")


def load_parsons_per_level(level):
all_parsons = []
parsons = PARSONS[g.lang].get_parsons(g.keyword_lang)
for short_name, parson in parsons.items():
if level not in parson['levels']:
continue
level_parson = parson['levels'].get(level)
current_parson = {
'short_name': short_name,
'name': parson['name'],
'text': level_parson['text'],
'example': level_parson['example'],
'story': level_parson['story'],
# We use this overly complex line to shuffle the dict items in one go
'code_lines': {i: level_parson['code_lines'][i] for i in list(set(level_parson['code_lines']))}
}
all_parsons.append(current_parson)
return all_parsons

def load_adventures_per_level(level):
loaded_programs = {}
# If user is logged in, we iterate their programs that belong to the current level. Out of these, we keep the latest created program for both the level mode(no adventure) and for each of the adventures.
Expand Down Expand Up @@ -788,8 +812,7 @@ def index(level, program_id):
adventures = load_adventures_per_level(level)
customizations = {}
if current_user()['username']:
customizations = DATABASE.get_student_class_customizations(current_user()[
'username'])
customizations = DATABASE.get_student_class_customizations(current_user()['username'])

if 'levels' in customizations:
available_levels = customizations['levels']
Expand All @@ -804,6 +827,8 @@ def index(level, program_id):
if 'levels' in customizations and level not in available_levels:
return utils.error_page(error=403, ui_message=gettext('level_not_class'))

parsons = load_parsons_per_level(level)
print(parsons)
commands = COMMANDS[g.lang].get_commands_for_level(level, g.keyword_lang)

teacher_adventures = []
Expand Down Expand Up @@ -831,6 +856,7 @@ def index(level, program_id):
version=version(),
quiz=quiz,
adventures=adventures,
parsons=parsons,
customizations=customizations,
hide_cheatsheet=hide_cheatsheet,
enforce_developers_mode=enforce_developers_mode,
Expand Down
5 changes: 5 additions & 0 deletions build-tools/heroku/tailwind/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ body[dir='rtl'] .right-hand-shadow {
.teacher_tab {
@apply border-green-300;
}

.parsons_tab {
@apply border-blue-300;
}

.money_tab {
@apply border-green-600 bg-green-400 text-white font-semibold;
}
Expand Down
168 changes: 168 additions & 0 deletions content/parsons/ar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
parsons:
dragging:
name: "Dragging"
levels:
1:
text: |
## Drag the code in the correct order
example: |
## What is my code supposed to do?
story: |
You're a customer at bakery Hedy.
You want into the bakery and are welcomed by the baker.
He asks what type of pie you want to order.
Your order is being prepared.
code_lines:
A: |
{print} Welcome to bakery Hedy!
B: |
{ask} What type of pie do you want to order?
C: |
{echo} So you want
D: |
{print} Your order is being prepared!
2:
text: |
## Drag the code in the correct order
example: |
## What is my code supposed to do?
story: |
You and your friends are going to watch some Netflix.
Show which movie you're about to watch and wish the viewers lot of fun!
code_lines:
A: |
{print} It is time for an evening of Netflix
B: |
film {is} Sonic the Hedgehog 2
C: |
{print} We're going to the movies
D: |
{print} Have lot of fun!
3:
text: |
## Drag the code in the correct order
example: |
## What is my code supposed to do?
story: |
The new school year at Hogwarts is starting!
It is the job of the sorting hat to sort you into one of the houses.
Which house will you be sorted into?
Are you a Gryffindor, Hufflepuf, Ravenclaw or Slytherin.
Let the program wait a short period before revealing your house.
code_lines:
A: |
{print} The new school year at Hogwarts is starting!
B: |
{print} The sorting hat is ready to sort you into one of the houses.
C: |
houses {is} Gryffindor, Hufflepuf, Ravenclaw, Slytherin
D: |
{sleep} 2
E: |
{print} And it is houses {at} {random}
4:
text: |
## Drag the code in the correct order
example: |
## What is my code supposed to do?
story: |
You are the newest Pokémon trainer from Pallet Town!
Make a program that selects your first Pokémon.
Let the program wait a minute before revealing your first pokémon.
code_lines:
A: |
pokemons {is} Pikachu, Charmander, Bulbasaur, Squirtle
B: |
{print} 'This is going to be your first pokémon!'
C: |
{sleep}
D: |
{print} pokemons {at} {random}
5:
text: |
## Drag the code in the correct order
example: |
## What is my code supposed to do?
story: |
Make a program that checks if your favourite movie is already in the list of the computer.
If so, print that you have great taste, otherwise add the movie to the list.
code_lines:
A: |
favoriete_movies {is} Batman, Spiderman, The Avengers, Jurassic Park
B: |
movie {is} {ask} 'What is your favourite movie?'
C: |
{if} movie {in} favoriete_movies {print} 'You have great taste!'
D: |
{else} {print} 'Such a shame that your favourite movie is not in the list, we will add it right away!'
E: |
{add} movie {to_list} favoriete_movies
6:
text: |
## Drag the code in the correct order
example: |
## What is my code supposed to do?
story: |
Make a program that calculates how old you are in dog and cat years.
First ask the age of the user and start calculating.
First calculate the dogyears then the catyears.
Show the user the different ages.
code_lines:
A: |
age = {ask} 'How old are you?'
B: |
dog_age = age * 7
C: |
cat_age = age * 5
D: |
{print} 'In dogyears you are ' dog_age ' years old.'
E: |
{print} 'In catyears you are ' cat_age ' years old.'
7:
text: |
## Drag the code in the correct order
example: |
## What is my code supposed to do?
story: |
In a chess tournament there are three players left.
Create a program that decides which two players first play against each other.
First print the two players who play the first match, then print against which player the winner will play.
code_lines:
A: |
players = Liam, Noah, Sophie
B: |
player1 = players {at} {random}
C: |
player2 = players {at} {random}
D: |
{print} player1 ' first plays against ' player2
E: |
{remove} player1 {from} players
F: |
{remove} player2 {from} players
G: |
{print} 'The winner plays against ' players {at} {random}
8:
text: |
## Drag the code in the correct order
example: |
## What is my code supposed to do?
story: |
You and your friends are playing Pokémon Go! Create a program that decides in which team you will be selected.
Either red, yellow or blue!
code_lines:
A: |
teams = red, yellow, blue
B: |
{print} 'Red of Blue?'
C: |
{print} 'You are selected in team '
D: |
{repeat} 5 {times}
E: |
{print} teams {at} {random}
F: |
sleep 2
G: |
{print} teams {at} random '!'
Loading

0 comments on commit 78b2afd

Please sign in to comment.