Skip to content

Commit

Permalink
Classes overview in Teachers Page (hedyorg#694)
Browse files Browse the repository at this point in the history
* Move classes overview to For Teachers page; hide For Teachers page from main menu unless the user is a teacher.
* Change class overview to link to student's programs
  • Loading branch information
fpereiro authored Sep 9, 2021
1 parent 1ba0895 commit 1567dc4
Show file tree
Hide file tree
Showing 38 changed files with 292 additions and 2,359 deletions.
49 changes: 41 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ def programs_page (request):

from_user = request.args.get('user') or None
if from_user and not is_admin (request):
return "unauthorized", 403
if not is_teacher (request):
return "unauthorized", 403
students = DATABASE.get_teacher_students (username)
if from_user not in students:
return "unauthorized", 403

texts=TRANSLATIONS.get_translations (requested_lang (), 'Programs')
ui=TRANSLATIONS.get_translations (requested_lang (), 'ui')
Expand All @@ -421,7 +425,7 @@ def programs_page (request):

programs.append ({'id': item ['id'], 'code': item ['code'], 'date': texts ['ago-1'] + ' ' + str (date) + ' ' + measure + ' ' + texts ['ago-2'], 'level': item ['level'], 'name': item ['name'], 'adventure_name': item.get ('adventure_name'), 'public': item.get ('public')})

return render_template('programs.html', lang=requested_lang(), menu=render_main_menu('programs'), texts=texts, ui=ui, auth=TRANSLATIONS.get_translations (requested_lang (), 'Auth'), programs=programs, username=username, current_page='programs', from_user=from_user, adventures=adventures)
return render_template('programs.html', lang=requested_lang(), menu=render_main_menu('programs'), texts=texts, ui=ui, auth=TRANSLATIONS.get_translations (requested_lang (), 'Auth'), programs=programs, username=username, is_teacher=is_teacher (request), current_page='programs', from_user=from_user, adventures=adventures)

@app.route('/quiz/start/<level>', methods=['GET'])
def get_quiz_start(level):
Expand All @@ -436,7 +440,7 @@ def get_quiz_start(level):
session['correct_answer'] = 0
return render_template('startquiz.html', level=level, next_assignment=1, menu=render_main_menu('adventures'),
lang=lang,
username=current_user(request)['username'],
username=current_user(request)['username'], is_teacher=is_teacher (request),
auth=TRANSLATIONS.get_translations (requested_lang(), 'Auth'))


Expand Down Expand Up @@ -473,13 +477,15 @@ def get_quiz(level_source, question_nr):
char_array=char_array,
menu=render_main_menu('adventures'), lang=lang,
username=current_user(request)['username'],
is_teacher=is_teacher(request),
auth=TRANSLATIONS.get_translations (requested_lang(), 'Auth'))
else:
return render_template('endquiz.html', correct=session.get('correct_answer'),
total_score=session.get('total_score'),
menu=render_main_menu('adventures'), lang=lang,
quiz=quiz_data, level=int(level_source) + 1, questions=quiz_data['questions'],
next_assignment=1, username=current_user(request)['username'],
is_teacher=is_teacher(request),
auth=TRANSLATIONS.get_translations (requested_lang(), 'Auth'))


Expand Down Expand Up @@ -520,14 +526,15 @@ def submit_answer(level_source, question_nr):
index_option=index_option,
menu=render_main_menu('adventures'), lang=lang,
username=current_user(request)['username'],
is_teacher=is_teacher(request),
auth=TRANSLATIONS.get_translations (requested_lang(), 'Auth'))
else: # show a different page for after the last question
return 'No end quiz page!', 404

# Adventure mode
@app.route('/hedy/adventures', methods=['GET'])
def adventures_list():
return render_template('adventures.html', lang=lang, adventures=load_adventure_for_language (requested_lang ()), menu=render_main_menu('adventures'), username=current_user(request) ['username'], auth=TRANSLATIONS.get_translations (requested_lang (), 'Auth'))
return render_template('adventures.html', lang=lang, adventures=load_adventure_for_language (requested_lang ()), menu=render_main_menu('adventures'), username=current_user(request) ['username'], is_teacher=is_teacher(request), auth=TRANSLATIONS.get_translations (requested_lang (), 'Auth'))

@app.route('/hedy/adventures/<adventure_name>', methods=['GET'], defaults={'level': 1})
@app.route('/hedy/adventures/<adventure_name>/<level>', methods=['GET'])
Expand Down Expand Up @@ -662,6 +669,7 @@ def view_program(id):
arguments_dict['menu'] = render_main_menu('view')
arguments_dict['auth'] = TRANSLATIONS.get_translations(lang, 'Auth')
arguments_dict['username'] = current_user(request) ['username'] or None
arguments_dict['is_teacher'] = is_teacher(request)
arguments_dict.update(**TRANSLATIONS.get_translations(lang, 'ui'))

return render_template("view-program-page.html", **arguments_dict)
Expand Down Expand Up @@ -715,10 +723,12 @@ def space_eu(level, step):
def client_messages():
error_messages = TRANSLATIONS.get_translations(requested_lang(), "ClientErrorMessages")
ui_messages = TRANSLATIONS.get_translations(requested_lang(), "ui")
auth_messages = TRANSLATIONS.get_translations(requested_lang(), "Auth")

response = make_response(render_template("client_messages.js",
error_messages=json.dumps(error_messages),
ui_messages=json.dumps(ui_messages)))
ui_messages=json.dumps(ui_messages),
auth_messages=json.dumps(auth_messages)))

if not is_debug_mode():
# Cache for longer when not devving
Expand Down Expand Up @@ -764,7 +774,11 @@ def main_page(page):
front_matter, markdown = split_markdown_front_matter(contents)

menu = render_main_menu(page)
return render_template('main-page.html', mkd=markdown, lang=lang, menu=menu, username=current_user(request) ['username'], auth=TRANSLATIONS.get_translations (lang, 'Auth'), **front_matter)
if page == 'for-teachers':
teacher_classes = [] if not current_user (request) ['username'] else DATABASE.get_teacher_classes (current_user (request) ['username'], True)
return render_template('for-teachers.html', sections=split_teacher_docs (contents), lang=lang, menu=menu, username=current_user(request) ['username'], is_teacher=is_teacher(request), auth=TRANSLATIONS.get_translations (lang, 'Auth'), teacher_classes=teacher_classes, **front_matter)

return render_template('main-page.html', mkd=markdown, lang=lang, menu=menu, username=current_user(request) ['username'], is_teacher=is_teacher(request), auth=TRANSLATIONS.get_translations (lang, 'Auth'), **front_matter)


def session_id():
Expand Down Expand Up @@ -814,7 +828,10 @@ def localize_link(url):
lang = requested_lang()
if not lang:
return url
return url + '?lang=' + lang
if '?' in url:
return url + '&lang=' + lang
else:
return url + '?lang=' + lang

def make_lang_obj(lang):
"""Make a language object for a given language."""
Expand Down Expand Up @@ -851,14 +868,30 @@ def split_markdown_front_matter(md):

return front_matter, parts[1]

def split_teacher_docs (contents):
tags = utils.markdown_to_html_tags (contents)
sections = []
for tag in tags:
# Sections are divided by h2 tags
if re.match ('^<h2>', str (tag)):
tag = tag.contents [0]
# We strip `page_title: ` from the first title
if len (sections) == 0:
tag = tag.replace ('page_title: ', '')
sections.append ({'title': tag, 'content': ''})
else:
sections [-1] ['content'] += str (tag)

return sections

def render_main_menu(current_page):
"""Render a list of (caption, href, selected, color) from the main menu."""
return [dict(
caption=item.get(requested_lang(), item.get('en', '???')),
href='/' + item['_'],
selected=(current_page == item['_']),
accent_color=item.get('accent_color', 'white')
accent_color=item.get('accent_color', 'white'),
short_name=item['_']
) for item in main_menu_json['nav']]

# *** PROGRAMS ***
Expand Down
2 changes: 1 addition & 1 deletion build-tools/validate-e2e
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pids=""
trap 'kill $pids' EXIT

export PORT=5050
env HEROKU_APP_NAME=localhost SECRET_KEY=TheSecret python app.py > e2e-server.log 2>&1 &
env HEROKU_APP_NAME=localhost BASE_URL=http://localhost:$PORT SECRET_KEY=TheSecret python app.py > e2e-server.log 2>&1 &
pids="$pids $!"

endpoint=http://localhost:$PORT
Expand Down
3 changes: 3 additions & 0 deletions coursedata/texts/cs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,15 @@ Auth:
student_classes: "My classes"
teacher_classes: "My classes"
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
class_overview: "Class overview"
class_join_confirmation: "You have successfully joined the class"
class_already_joined: "You are already part of the class"
goto_profile: "Go to my profile"
last_login: "Last login"
highest_level_reached: "Highest level reached"
number_programs: "Number of programs"
Expand Down
3 changes: 3 additions & 0 deletions coursedata/texts/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,15 @@ Auth:
student_classes: "My classes"
teacher_classes: "My classes"
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
class_overview: "Class overview"
class_join_confirmation: "You have successfully joined the class"
class_already_joined: "You are already part of the class"
goto_profile: "Go to my profile"
last_login: "Last login"
highest_level_reached: "Highest level reached"
number_programs: "Number of programs"
Expand Down
3 changes: 3 additions & 0 deletions coursedata/texts/el.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,15 @@ Auth:
student_classes: "My classes"
teacher_classes: "My classes"
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
class_overview: "Class overview"
class_join_confirmation: "You have successfully joined the class"
class_already_joined: "You are already part of the class"
goto_profile: "Go to my profile"
last_login: "Last login"
highest_level_reached: "Highest level reached"
number_programs: "Number of programs"
Expand Down
5 changes: 5 additions & 0 deletions coursedata/texts/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,17 @@ Auth:
remove_student_prompt: "Are you sure you want to remove the student from the class?"
student_classes: "My classes"
teacher_classes: "My classes"
name: "Name"
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
class_overview: "Class overview"
class_join_confirmation: "You have successfully joined the class"
class_already_joined: "You are already part of the class"
goto_profile: "Go to my profile"
last_login: "Last login"
highest_level_reached: "Highest level reached"
number_programs: "Number of programs"
Expand All @@ -166,6 +170,7 @@ Auth:
students: "students"
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: "Programs"

Programs:
recent: "My recent programs"
Expand Down
38 changes: 21 additions & 17 deletions coursedata/texts/es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,27 @@ Auth:
class_name_prompt: "Please enter the name of the class"
delete_class_prompt: "Are you sure you want to delete the class?"
remove_student_prompt: "Are you sure you want to remove the student from the class?"
student_classes: "My classes"
teacher_classes: "My classes"
create_class: "Create new class"
delete_class: "Delete class permanently"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
class_overview: "Class overview"
class_join_confirmation: "You have successfully joined the class"
last_login: "Last login"
highest_level_reached: "Highest level reached"
number_programs: "Number of programs"
latest_shared_program: "Latest shared program"
remove_student: "Remove student"
students: "students"
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?"
student_classes: "Mis clases"
teacher_classes: "Mis clases"
name: "Nombre"
create_class: "Crear nueva clase"
rename_class: "Renombrar clase"
delete_class: "Borrar clase permanentemente"
class_link: "Enlace para unirse a la clase"
prompt_join_class: "Deseas unirte a la clase?"
join_class: "Unirse a la clase"
class_overview: "Vista general de la clase"
class_join_confirmation: "Te has unido a la clase exitosamente"
class_already_joined: "Ya eres parte de la clase"
goto_profile: "Ir a mi perfil"
last_login: "Último ingreso"
highest_level_reached: "Nivel más alto alcanzado"
number_programs: "Número de programas"
latest_shared_program: "Último programa compartido"
remove_student: "Quitar estudiante"
students: "estudiantes"
copy_class_link: "Copiar enlace para unirse a la clase"
join_prompt: "Debes estar registrado para unirte a una clase. ¿Deseas entrar a tu cuenta?"
Programs:
recent: "Mis programas recientes"
level: "Nivel"
Expand Down
3 changes: 3 additions & 0 deletions coursedata/texts/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,15 @@ Auth:
student_classes: "My classes"
teacher_classes: "My classes"
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
class_overview: "Class overview"
class_join_confirmation: "You have successfully joined the class"
class_already_joined: "You are already part of the class"
goto_profile: "Go to my profile"
last_login: "Last login"
highest_level_reached: "Highest level reached"
number_programs: "Number of programs"
Expand Down
3 changes: 3 additions & 0 deletions coursedata/texts/hu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,15 @@ Auth:
student_classes: "My classes"
teacher_classes: "My classes"
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
class_overview: "Class overview"
class_join_confirmation: "You have successfully joined the class"
class_already_joined: "You are already part of the class"
goto_profile: "Go to my profile"
last_login: "Last login"
highest_level_reached: "Highest level reached"
number_programs: "Number of programs"
Expand Down
3 changes: 3 additions & 0 deletions coursedata/texts/it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,15 @@ Auth:
student_classes: "My classes"
teacher_classes: "My classes"
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
class_overview: "Class overview"
class_join_confirmation: "You have successfully joined the class"
class_already_joined: "You are already part of the class"
goto_profile: "Go to my profile"
last_login: "Last login"
highest_level_reached: "Highest level reached"
number_programs: "Number of programs"
Expand Down
4 changes: 4 additions & 0 deletions coursedata/texts/nl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,17 @@ Auth:
remove_student_prompt: "Are you sure you want to remove the student from the class?"
student_classes: "My classes"
teacher_classes: "My classes"
name: "Naam"
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
class_overview: "Class overview"
class_join_confirmation: "You have successfully joined the class"
class_already_joined: "You are already part of the class"
goto_profile: "Go to my profile"
last_login: "Last login"
highest_level_reached: "Highest level reached"
number_programs: "Number of programs"
Expand Down
3 changes: 3 additions & 0 deletions coursedata/texts/pt_br.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,15 @@ Auth:
student_classes: "Minhas Turmas"
teacher_classes: "Minhas Turmas"
create_class: "Criar nova turma"
rename_class: "Renomear turma"
delete_class: "Excluir a turma permanentemente"
class_link: "Link para entrar na turma"
prompt_join_class: "Você quer entrar nesta turma?"
join_class: "Entrar na turma"
class_overview: "Visão geral da turma"
class_join_confirmation: "Você entrou na turma com sucesso"
class_already_joined: "Você ja faz parte da turma"
goto_profile: "Go to my profile"
last_login: "Último login"
highest_level_reached: "Nível mais alto alcançado"
number_programs: "Número de programas"
Expand Down
3 changes: 3 additions & 0 deletions coursedata/texts/pt_pt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,15 @@ Auth:
student_classes: "My classes"
teacher_classes: "My classes"
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
class_overview: "Class overview"
class_join_confirmation: "You have successfully joined the class"
class_already_joined: "You are already part of the class"
goto_profile: "Go to my profile"
last_login: "Last login"
highest_level_reached: "Highest level reached"
number_programs: "Number of programs"
Expand Down
3 changes: 3 additions & 0 deletions coursedata/texts/sw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,15 @@ Auth:
student_classes: "My classes"
teacher_classes: "My classes"
create_class: "Create new class"
rename_class: "Rename class"
delete_class: "Delete class permanently"
class_link: "Link to join class"
prompt_join_class: "Do you want to join this class?"
join_class: "Join class"
class_overview: "Class overview"
class_join_confirmation: "You have successfully joined the class"
class_already_joined: "You are already part of the class"
goto_profile: "Go to my profile"
last_login: "Last login"
highest_level_reached: "Highest level reached"
number_programs: "Number of programs"
Expand Down
Loading

0 comments on commit 1567dc4

Please sign in to comment.