Repository: hedyorg/hedy

Issue:
[UI idea] Frequently made mistakes page needs an update
Not only the content (which I will take care of myself) but also the lay-out of this page needs an update. Right now, somehow most mistakes are mentioned twice and the indentation with the bulletpoints looks very messy. 

Maybe @TiBiBa can take a look at it and maybe add some buttons, so that the teachers can select the level of which they want to see the frequently made mistakes? Because now it's just a long messy list. 
Maybe you or @Felienne have some other ideas as well about how we can make it more structured and look more clear?


Discussion:
> Not only the content (which I will take care of myself) but also the lay-out of this page needs an update. Right now, somehow most mistakes are mentioned twice and the indentation with the bulletpoints looks very messy.
> 
> Maybe @TiBiBa can take a look at it and maybe add some buttons, so that the teachers can select the level of which they want to see the frequently made mistakes? Because now it's just a long messy list. Maybe you or @Felienne have some other ideas as well about how we can make it more structured and look more clear?

Agree! The problem is that we are pretty limited on styling the page due to the code structure with which we use .md-files for our texts. We are unable to clearly "see" the content and therefore style accordingly. I would propose to re-structure the page to use *.yaml files, enabling us to better structure (and adjust to) the content. We can combine this with the earlier proposed issue of #1014. What do you think @Felienne?
I will make an attempt today with re-structuring the file using *.yaml structure, creating a dedicated file for the for-teachers page (as it will probably become a large file on the long-run).
That would be great, because it would also make translation easier!

Felienne

On Mon, 29 Nov 2021 at 09:57, Timon Bakker ***@***.***> wrote:

> I will make an attempt today with re-structuring the file using *.yaml
> structure, creating a dedicated file for the for-teachers page (as it will
> probably become a large file on the long-run).
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/Felienne/hedy/issues/1389#issuecomment-981415306>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAHVBJK6PO57AENNPHFZJWLUOM6AXANCNFSM5IZHU6CA>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
>


Resolving patch:
diff --git a/app.py b/app.py
--- a/app.py
+++ b/app.py
@@ -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'
 
@@ -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)
 
@@ -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(
diff --git a/hedyweb.py b/hedyweb.py
--- a/hedyweb.py
+++ b/hedyweb.py
@@ -30,6 +30,19 @@ def get_translations(self, language, section):
     d.update(**self.data.get(language, {}).get(section, {}))
     return d
 
+class PageTranslations:
+  def __init__(self, page):
+    self.data = {}
+    translations = glob.glob('coursedata/pages/' + page + '/*.yaml')
+    for file in translations:
+      lang = path.splitext(path.basename(file))[0]
+      self.data[lang] = YamlFile.for_file(file)
+
+  def get_page_translations(self, language):
+    d = collections.defaultdict(lambda: 'Unknown Exception')
+    d.update(**self.data.get('en', {}))
+    d.update(**self.data.get(language, {}))
+    return d
 
 def render_code_editor_with_tabs(level_defaults, max_level, level_number, translations, version, loaded_program, adventures, restrictions, adventure_name):
   user = current_user()


Test patch: