Skip to content

Commit

Permalink
[FEATURE] Enables teachers to create their own adventures (hedyorg#1812)
Browse files Browse the repository at this point in the history
* Fixes hedyorg#1515
  • Loading branch information
TiBiBa authored Feb 4, 2022
1 parent e834d62 commit 3312229
Show file tree
Hide file tree
Showing 40 changed files with 599 additions and 120 deletions.
16 changes: 11 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,8 +1106,9 @@ def index(level, step):
if 'adventure_name' in result:
adventure_name = result['adventure_name']

adventures, restrictions = DATABASE.get_student_restrictions(load_adventures_per_level(g.lang, level),
adventures, teacher_adventures, restrictions = DATABASE.get_student_restrictions(load_adventures_per_level(g.lang, level),
current_user()['username'], level)

level_defaults_for_lang = LEVEL_DEFAULTS[g.lang]

if level not in level_defaults_for_lang.levels or restrictions['hide_level']:
Expand All @@ -1121,6 +1122,7 @@ def index(level, step):
level_number=level,
version=version(),
adventures=adventures,
teacher_adventures=teacher_adventures,
restrictions=restrictions,
loaded_program=loaded_program,
adventure_name=adventure_name)
Expand Down Expand Up @@ -1230,16 +1232,20 @@ def main_page(page):

if page == 'for-teachers':
for_teacher_translations = hedyweb.PageTranslations(page).get_page_translations(g.lang)
print(for_teacher_translations)
if is_teacher(user):
welcome_teacher = session.get('welcome-teacher') or False
session.pop('welcome-teacher', None)
teacher_classes = [] if not current_user()['username'] else DATABASE.get_teacher_classes(
current_user()['username'], True)
teacher_classes = [] if not current_user()['username'] else DATABASE.get_teacher_classes(current_user()['username'], True)
adventures = []
for adventure in DATABASE.get_teacher_adventures(current_user()['username']):
adventures.append({'id': adventure.get('id'), 'name': adventure.get('name'),
'date': utils.datetotimeordate(utils.mstoisostring(adventure.get('date'))),
'level': adventure.get('level')})

return render_template('for-teachers.html', current_page='my-profile',
page_title=hedyweb.get_page_title(page),
content=for_teacher_translations, teacher_classes=teacher_classes,
welcome_teacher=welcome_teacher)
teacher_adventures=adventures, welcome_teacher=welcome_teacher)
else:
return utils.error_page(error=403, ui_message='not_teacher')

Expand Down
4 changes: 4 additions & 0 deletions build-tools/heroku/tailwind/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ body[dir='rtl'] .right-hand-shadow {
/* bottom */ inset 0px -4px 4px -1px rgba(0,0,0,0.1);
}

.teacher_tab {
@apply border-green-300;
}

@screen lg {
.tab {
@apply px-2;
Expand Down
8 changes: 8 additions & 0 deletions coursedata/pages/pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
"en": "Hedy - Customize class",
"nl": "Hedy - Klas personaliseren"
},
"customize adventure": {
"en": "Hedy - Customize adventure",
"nl": "Hedy - Avontuur personaliseren"
},
"view adventure": {
"en": "Hedy - View adventure",
"nl": "Hedy - Avontuur bekijken"
},
"class statistics": {
"en": "Hedy - Class statistics",
"nl": "Hedy - Klas statistieken"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/bg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Auth:
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
back_to_class_list: "Go back to list of classes"
back_to_teachers_page: "Go back to teachers page"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/cs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Auth:
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
back_to_class_list: "Go back to list of classes"
back_to_teachers_page: "Go back to teachers page"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Auth:
create_class: "Erstelle eine neue Klasse"
rename_class: "Klasse umbenennen"
delete_class: "Klasse löschen"
back_to_class_list: "Zurück zur Klassenliste"
back_to_teachers_page: "Go back to teachers page"
class_link: "Link um der Klasse beizutreten"
prompt_join_class: "Willst du dieser Klasse beitreten?"
join_class: "Klasse beitreten"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/el.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Auth:
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
back_to_class_list: "Go back to list of classes"
back_to_teachers_page: "Go back to teachers page"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
Expand Down
32 changes: 31 additions & 1 deletion coursedata/texts/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ Auth:
favourite_program_invalid: "Your favourite program is invalid"
ajax_error: "There was an error, please try again."

#other validations
adventure_id_invalid: "This adventure id is invalid"
adventure_name_invalid: "This adventure name is invalid"
level_invalid: "This Hedy level in invalid"
content_invalid: "This adventure is invalid"
public_invalid: "This agreement selection is invalid"
adventure_length: "Your adventure has to be at least 20 characters"
adventure_duplicate: "You already have an adventure with this name"
adventure_updated: "The adventure has been updated!"

please_username_email: "Please enter an username or email."
profile_updated: "Profile updated."
public_profile_updated: "Public profile updated."
Expand Down Expand Up @@ -267,7 +277,13 @@ Auth:
sent_by: "This invitation is sent by"
my_messages: "My messages"
delete_invite: "Delete invitation"
back_to_class_list: "Go back to list of classes"
create_adventure: "Create adventure"
adventure_prompt: "Please enter the name of the adventure"
username_empty: "You didn't enter an username!"
adventure_empty: "You didn't enter an adventure name!"
update_adventure_prompt: "Are you sure you want to update this adventure?"
delete_adventure_prompt: "Are you sure you want to remove this adventure?"
back_to_teachers_page: "Go back to teachers page"
back_to_class: "Go back to class"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
Expand Down Expand Up @@ -301,6 +317,20 @@ Auth:
programs: "Programs"
page: "page"
class_stats: "Show class statistics"
#Adventure customizations
customize_adventure: "Customize adventure"
general_settings: "General settings"
adventure: "Adventure"
my_adventures: "My adventures"
level: "Level"
adventure_terms: "I agree that my adventure might be made publicly available on Hedy."
preview: "Preview"
adventure_exp_1: "Type your adventure of choice on the right-hand side. After creating your adventure you can include it in one of your classes under \"customizations\". If you want to include a command in your adventure please use code anchors like this:"
adventure_exp_2: "If you want to show actual code snippets, for example to give student a template or example of the code. Please use pre anchors like this:"
adventure_exp_3: "You can use the \"preview\" button to view a styled version of your adventure. To view the adventure on a dedicated page, select \"view\" from the teachers page."
template_code: "This is the explanation of my adventure!\n\nThis way I can show a command: <code>print</code>\n\nBut sometimes I might want to show a piece of code, like this:\n<pre>\nask What's your name?\necho so your name is \n</pre>"
last_update: "Last update"
view: "View"
Programs:
recent: "My recent programs"
level: "Level"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Auth:
create_class: "Crear nueva clase"
rename_class: "Renombrar clase"
delete_class: "Borrar clase permanentemente"
back_to_class_list: "Volver a la lista de clases"
back_to_teachers_page: "Go back to teachers page"
class_link: "Enlace para unirse a la clase"
prompt_join_class: "Deseas unirte a la clase?"
join_class: "Unirse a la clase"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Auth:
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
back_to_class_list: "Go back to list of classes"
back_to_teachers_page: "Go back to teachers page"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/fy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Auth:
create_class: "Nij klas meitsje"
rename_class: "Klas omneame"
delete_class: "Klas fuortsmite"
back_to_class_list: "Werom nei de list mei klassen"
back_to_teachers_page: "Go back to teachers page"
class_link: "Link om oan de klas mei te dwaan"
prompt_join_class: "Wolst oan dizze klas meidwaan?"
join_class: "Meidwaan mei klas"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/hu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Auth:
create_class: "Új osztály létrehozása"
rename_class: "Osztály átnevezése"
delete_class: "Osztály végleges törlése "
back_to_class_list: "Vissza az osztályok listájához"
back_to_teachers_page: "Go back to teachers page"
class_link: "Link az osztályhoz"
prompt_join_class: "Ehhez az osztályhoz akarsz csatlakozni?"
join_class: "Belépés az osztályba"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Auth:
create_class: Buat kelas baru
rename_class: Beri nama baru untuk kelas
delete_class: Hapus kelas secara permanen
back_to_class_list: Kembali ke daftar kelas
back_to_teachers_page: "Go back to teachers page"
class_link: Tautan untuk bergabung dalam kelas
prompt_join_class: Apakah kamu ingin bergabung dengan kelas ini?
join_class: Gabung kelas
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Auth:
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
back_to_class_list: "Go back to list of classes"
back_to_teachers_page: "Go back to teachers page"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
Expand Down
33 changes: 31 additions & 2 deletions coursedata/texts/nl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ Auth:
favourite_program_invalid: "Jouw favoriete programma is ongeldig"
ajax_error: "Er is een fout opgetreden, probeer het nog eens."

#other validations
adventure_id_invalid: "Dit avontuur id is ongeldig"
adventure_name_invalid: "Deze avontuur naam is ongeldig"
level_invalid: "Dit Hedy level is ongeldig"
content_invalid: "Dit avontuur is ongeldig"
public_invalid: "Deze waarde voor het beschikbaar maken van je avontuur is ongeldig"
adventure_length: "Jouw avontuur moet minimaal 20 karakters zijn"
adventure_duplicate: "Je hebt al een avontuur met deze naam"
adventure_updated: "Jouw avontuur is bijgewerkt!"

please_username_email: "Vul een gebruikersnaam of email adres in."
profile_updated: "Je profiel is aangepast."
public_profile_updated: "Je openbare profiel is aangepast"
Expand Down Expand Up @@ -260,7 +270,13 @@ Auth:
sent_by: "Deze uitnodiging is verstuurd door"
my_messages: "Mijn berichten"
delete_invite: "Uitnodiging verwijderen"
back_to_class_list: "Ga terug naar klassen overzicht"
create_adventure: "Maak nieuw avontuur"
adventure_prompt: "Geef je nieuwe avontuur een naam"
username_empty: "Je hebt geen gebruikersnaam ingevuld!"
adventure_empty: "Je hebt geen avonturen naam ingevuld!"
update_adventure_prompt: "Weet je zeker dat je dit avontuur wilt bijwerken?"
delete_adventure_prompt: "Weet je zeker dat je dit avontuur wilt verwijderen?"
back_to_teachers_page: "Ga terug naar lerarenpagina"
back_to_class: "Ga terug naar klas"
class_link: "Link voor inschrijven klas"
prompt_join_class: "Wil je je inschrijven voor deze klas?"
Expand Down Expand Up @@ -292,7 +308,20 @@ Auth:
reset: "Reset level"
programs: "Programma's"
page: "pagina"

#Adventure customizations
customize_adventure: "Avontuur aanpassen"
general_settings: "Algemene instellingen"
adventure: "Avontuur"
my_adventures: "Mijn avonturen"
level: "Level"
adventure_terms: "I ga ermee akkoord dat mijn avontuur mogelijk beschikbaar komt op Hedy."
preview: "Voorbeeld"
adventure_exp_1: "Typ jouw avontuur hier aan de rechterkant. Na het maken van een avontuur kun je deze toevoegen aan een klas via \"personaliseren\". Als je een commando aan jouw avontuur wilt toevoegen kun je code blokjes gebruiken zoals dit:"
adventure_exp_2: "Als je stukjes code wilt toevoegen, bijvoorbeeld als template of voorbeeld voor je leerlingen. Dit kun je doen met pre blokjes zoals dit:"
adventure_exp_3: "Je kunt de \"voorbeeld\" knop gebruiken om de opgemaakt versie van jouw avontuur te zien. Om jouw avontuur op een speciale pagina te zien kies je \"bekijk\" op de lerarenpagina."
template_code: "Dit is de uitleg van mijn avontuur!\n\nOp deze manier laat ik een commando zien: <code>print</code>\n\nMaar soms wil ik een stukje code laten zien, dat doe ik zo:\n<pre>\nask Wat is jouw naam?\necho dus jouw naam is \n</pre>"
last_update: "Laatste update"
view: "Bekijk"
Programs:
recent: "Mijn programma's"
level: "Level"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/pt_br.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Auth:
create_class: "Criar nova turma"
rename_class: "Renomear turma"
delete_class: "Excluir a turma permanentemente"
back_to_class_list: "De volta à lista de turmas"
back_to_teachers_page: "Go back to teachers page"
class_link: "Link para entrar na turma"
prompt_join_class: "Você quer entrar nesta turma?"
join_class: "Entrar na turma"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/pt_pt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Auth:
latest_shared_program: "Latest shared program"
remove_student: "Remove student"
students: "students"
back_to_class_list: "Go back to list of classes"
back_to_teachers_page: "Go back to teachers page"
copy_class_link: "Copy link to join class"
join_prompt: "You need to have an account to join a class. Would you like to login now?"
Programs:
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/sw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Auth:
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
back_to_class_list: "Go back to list of classes"
back_to_teachers_page: "Go back to teachers page"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/zh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Auth:
latest_shared_program: "Latest shared program"
remove_student: "Remove student"
students: "students"
back_to_class_list: "Go back to list of classes"
back_to_teachers_page: "Go back to teachers page"
copy_class_link: "Copy link to join class"
join_prompt: "You need to have an account to join a class. Would you like to login now?"
Programs:
Expand Down
3 changes: 2 additions & 1 deletion hedyweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_page_title(current_page):
return page_titles_json['start'].get("en")


def render_code_editor_with_tabs(level_defaults, max_level, level_number, version, loaded_program, adventures, restrictions, adventure_name):
def render_code_editor_with_tabs(level_defaults, max_level, level_number, version, loaded_program, adventures, teacher_adventures, restrictions, adventure_name):
user = current_user()

if not level_defaults:
Expand All @@ -101,6 +101,7 @@ def render_code_editor_with_tabs(level_defaults, max_level, level_number, versio
arguments_dict['is_teacher'] = is_teacher(user)
arguments_dict['loaded_program'] = loaded_program
arguments_dict['adventures'] = adventures
arguments_dict['teacher_adventures'] = teacher_adventures
arguments_dict['adventure_name'] = adventure_name

# Merge level defaults into adventures so it is rendered as the first tab
Expand Down
Loading

0 comments on commit 3312229

Please sign in to comment.