Repository: hedyorg/hedy

Issue:
Move quiz to tab
Hi @fpereiro!

I would like a cosmetic change to how we do quizzes. Rather than having the button below, I would like to have the quiz button in a special adventure, called End/Eind, like this:

![image](https://user-images.githubusercontent.com/1003685/132873239-30e34a12-8d25-4d80-912b-cf6e5b53c0a1.png)

I see this as a normal adventure in the adventure-yaml, but with special command in the story text that means "place quiz button here", f.e. ###QUIZ###

Example:

```
story_text: |
        ## Closing remarks level 1
        Now that you have seen level 1, you know how to make small stories and program's. Tie to test your Hedy 
        knowledge!

        ###QUIZ###
```

If this quiz button is pressed, I want the quiz to be shown in the tab, like this:

![image](https://user-images.githubusercontent.com/1003685/132873915-a029d60e-b434-44da-8703-8fad2e2c5008.png)

---
Rationale: This structure helps kids and teachers see the quiz as a step in the teaching sequence which is better didactically. After the quiz, they do the "vooruitblik" and then move on.



Discussion:
Hi @Felienne . Understood! The feature looks well scoped. I'm sure a couple of questions will arise during implementation, but overall it looks clear.
> Hi @Felienne . Understood! The feature looks well scoped. I'm sure a couple of questions will arise during implementation, but overall it looks clear.

Great! Let me know if you need help. I would say this has higher prio than some of the other things on your list (like the default text on modal) We can discuss Thursday.

Resolving patch:
diff --git a/app.py b/app.py
--- a/app.py
+++ b/app.py
@@ -102,6 +102,10 @@ def load_adventures_per_level(lang, level):
     for short_name, adventure in adventures.items ():
         if not level in adventure['levels']:
             continue
+        # end adventure is the quiz
+        # if quizzes are not enabled, do not load it
+        if short_name == 'end' and not config['quiz-enabled']:
+            continue
         all_adventures.append({
             'short_name': short_name,
             'name': adventure['name'],
@@ -217,7 +221,7 @@ def after_request_log_status(response):
 def set_security_headers(response):
     security_headers = {
         'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
-        'X-Frame-Options': 'DENY',
+        'X-Frame-Options': None if re.match ('.*/quiz', request.url) else 'DENY',
         'X-XSS-Protection': '1; mode=block',
     }
     response.headers.update(security_headers)
@@ -495,7 +499,7 @@ def get_quiz(level_source, question_nr, attempt):
                                    is_teacher=is_teacher(request),
                                    auth=TRANSLATIONS.get_translations (requested_lang(), 'Auth'))
 
-@app.route('/submit_answer/<level_source>/<question_nr>/<attempt>', methods=["POST"])
+@app.route('/quiz/submit_answer/<level_source>/<question_nr>/<attempt>', methods=["POST"])
 def submit_answer(level_source, question_nr, attempt):
     if not config.get('quiz-enabled') and g.lang != 'nl':
         return 'Hedy quiz disabled!', 404
diff --git a/hedyweb.py b/hedyweb.py
--- a/hedyweb.py
+++ b/hedyweb.py
@@ -40,12 +40,6 @@ def get_translations(self, language, section):
 
 def render_code_editor_with_tabs(request, course, level_number, menu, translations, version, loaded_program, adventures, adventure_name):
 
-  if os.path.isfile(f'coursedata/quiz/quiz_questions_lvl{level_number}.yaml'):
-    quiz_data = utils.load_yaml(f'coursedata/quiz/quiz_questions_lvl{level_number}.yaml')
-    quiz_data_level = quiz_data['level']
-  else:
-    quiz_data_level = 0
-
   sublevel = None
   if isinstance (level_number, str) and re.match ('\d+-\d+', level_number):
     sublevel     = int (level_number [level_number.index ('-') + 1])
@@ -79,8 +73,6 @@ def render_code_editor_with_tabs(request, course, level_number, menu, translatio
   arguments_dict['loaded_program'] = loaded_program
   arguments_dict['adventures'] = adventures
   arguments_dict['adventure_name'] = adventure_name
-  arguments_dict['quiz_data_level'] = quiz_data_level
-  arguments_dict['quiz_enabled'] = config['quiz-enabled'] and course.language == 'nl'
 
   # Translations
   arguments_dict.update(**translations.get_translations(course.language, 'ui'))


Test patch: