Skip to content

Commit

Permalink
[FIX] Replace file structure of for-teachers page from .md to .yaml f…
Browse files Browse the repository at this point in the history
…iles (hedyorg#1419)




Co-authored-by: Rico Huijbers <[email protected]>
Co-authored-by: Felienne <[email protected]>
  • Loading branch information
3 people authored Dec 2, 2021
1 parent 740bb56 commit 927c242
Show file tree
Hide file tree
Showing 8 changed files with 437 additions and 72 deletions.
41 changes: 15 additions & 26 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,21 @@ def main_page(page):
else:
return utils.page_403(TRANSLATIONS, current_user()['username'], g.lang, TRANSLATIONS.get_translations(g.lang, 'ui').get('not_user'))

user = current_user()

if page == 'for-teachers':
for_teacher_translations = hedyweb.PageTranslations(page).get_page_translations(g.lang);
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)
return render_template('for-teachers.html', auth=TRANSLATIONS.get_translations(g.lang, 'Auth'), content=for_teacher_translations, teacher_classes=teacher_classes, welcome_teacher=welcome_teacher)
else:
return utils.page_403(TRANSLATIONS, current_user()['username'], g.lang,
TRANSLATIONS.get_translations(g.lang, 'ui').get('not_teacher'))


# Default to English if requested language is not available
effective_lang = g.lang if path.isfile(f'main/{page}-{g.lang}.md') else 'en'

Expand All @@ -944,18 +959,7 @@ def main_page(page):

front_matter, markdown = split_markdown_front_matter(contents)

user = current_user()

if page == 'for-teachers':
if is_teacher(user):
welcome_teacher = session.get('welcome-teacher') or False
session['welcome-teacher'] = False
teacher_classes =[] if not current_user()['username'] else DATABASE.get_teacher_classes(current_user()['username'], True)
return render_template('for-teachers.html', sections=split_teacher_docs(contents),
auth=TRANSLATIONS.get_translations(g.lang, 'Auth'), teacher_classes=teacher_classes,
welcome_teacher=welcome_teacher, **front_matter)
else:
return utils.page_403 (TRANSLATIONS, current_user()['username'], g.lang, TRANSLATIONS.get_translations (g.lang, 'ui').get ('not_teacher'))

return render_template('main-page.html', mkd=markdown, auth=TRANSLATIONS.get_translations(g.lang, 'Auth'), **front_matter)

Expand Down Expand Up @@ -1058,21 +1062,6 @@ 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(
Expand Down
91 changes: 91 additions & 0 deletions coursedata/pages/for-teachers/en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
title: "Hedy documentation"
sections:
1:
title: "Introduction"
subsections:
1:
title: "What's Hedy?"
text: |
<Todo>
2:
title: "Target audience"
text: |
<Todo>
3:
title: "How does Hedy work?"
text: |
<Todo>
4:
title: "Teaching with Hedy"
text: |
<Todo>
5:
title: "Devices"
text: |
<Todo>
2:
title: "Preparations"
subsections:
1:
title: "Storing programs"
text: |
<Todo>
3:
title: "Teaching with Hedy"
subsections:
1:
title: ""
text: |
<Todo>
2:
title: "Introduction"
text: |
<Todo>
3:
title: "Introduction of new concepts and commands"
text: |
<Todo>
4:
title: "Practice of new commands"
text: |
<Todo>
5:
title: "Getting started"
text: |
<Todo>
6:
title: "Quiz"
text: |
<Todo>
7:
title: "Evaluation"
text: |
<Todo>
4:
title: "Frequently made mistakes"
subsections:
1:
title: ""
text: |
<Todo>
2:
title: "Common mistakes in level 1"
text: |
<Todo>
3:
title: "Common mistakes in level 2"
text: |
<Todo>
4:
title: "Common mistakes in level 3"
text: |
<Todo>
5:
title: "Common mistakes in level 4"
text: |
<Todo>
6:
title: "Common mistakes in level 5"
text: |
<Todo>
Loading

0 comments on commit 927c242

Please sign in to comment.