Skip to content

Commit

Permalink
[BUG FIX] Quiz and parsons now use the correct keyword language when …
Browse files Browse the repository at this point in the history
…toggled (hedyorg#3888)

**Description**
We fix a bug where the keyword language wouldn't be correct for both the parsons and the quiz when using the UI toggle and we "force" the keyword language. This is due to the structure were we GET each question or exercise separately and depend on the `g.keyword_lang` value. However, this is incorrect when forcing the language! Therefore we now first check if there is a forced parameter in the url, if so: change the url and get the correct question / exercise.

**Fixes**
This PR fixes hedyorg#3884.

**How to test**
Make sure that both the parsons and quiz work when not logged in and using the keyword language toggle.
  • Loading branch information
TiBiBa authored Jan 2, 2023
1 parent 3f91449 commit 0f73352
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
10 changes: 9 additions & 1 deletion static/js/parsons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ interface ParsonsExercise {

export function loadParsonsExercise(level: number, exercise: number) {
$('#next_parson_button').hide();

// If we have a forced keyword language, sent this info to the back-end to get the correct exercise
let parameters = new URLSearchParams(window.location.search)
let url = "/parsons/get-exercise/" + level + '/' + exercise;
if (parameters.has('keyword_language')) {
url += "/" + parameters.get('keyword_language')
}

$.ajax({
type: 'GET',
url: '/parsons/get-exercise/' + level + '/' + exercise,
url: url,
dataType: 'json'
}).done(function(response: ParsonsExercise) {
$('#parsons_container').show();
Expand Down
9 changes: 8 additions & 1 deletion static/js/quiz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ export function loadQuizQuestion(level: number, question: number) {
// If we get the request from the feedback page -> always hide the feedback container
$('#quiz_feedback_container').hide();

// If we have a forced keyword language, sent this info to the back-end to get the correct question
let parameters = new URLSearchParams(window.location.search)
let url = "/quiz/get-question/" + level + '/' + question;
if (parameters.has('keyword_language')) {
url += "/" + parameters.get('keyword_language')
}

$.ajax({
type: 'GET',
url: '/quiz/get-question/' + level + '/' + question,
url: url,
dataType: 'json'
}).done(function(response: any) {
$('#quiz_container').show();
Expand Down
11 changes: 7 additions & 4 deletions website/parsons.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ def __init__(self, parsons):

self.parsons = parsons

@route("/get-exercise/<int:level>/<int:exercise>", methods=["GET"])
def get_parsons_exercise(self, level, exercise):
@route("/get-exercise/<int:level>/<int:exercise>", methods=["GET"], defaults={'keyword_lang': None})
@route("/get-exercise/<int:level>/<int:exercise>/<keyword_lang>", methods=["GET"])
def get_parsons_exercise(self, level, exercise, keyword_lang):
if exercise > self.parsons[g.lang].get_highest_exercise_level(level) or exercise < 1:
return gettext("exercise_doesnt_exist"), 400

exercise = self.parsons[g.lang].get_parsons_data_for_level_exercise(level, exercise, g.keyword_lang)
if keyword_lang:
exercise = self.parsons[g.lang].get_parsons_data_for_level_exercise(level, exercise, keyword_lang)
else:
exercise = self.parsons[g.lang].get_parsons_data_for_level_exercise(level, exercise, g.keyword_lang)
return jsonify(exercise), 200
10 changes: 7 additions & 3 deletions website/quiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ def initialize_user(self):

return jsonify({}), 200

@route("/get-question/<int:level>/<int:question>", methods=["GET"])
def get_quiz_question(self, level, question):
@route("/get-question/<int:level>/<int:question>", methods=["GET"], defaults={'keyword_lang': None})
@route("/get-question/<int:level>/<int:question>/<keyword_lang>", methods=["GET"])
def get_quiz_question(self, level, question, keyword_lang):
session["attempt"] = 0
if question > self.quizzes[g.lang].get_highest_question_level(level) or question < 1:
return gettext("question_doesnt_exist"), 400

question = self.quizzes[g.lang].get_quiz_data_for_level_question(level, question, g.keyword_lang)
if keyword_lang:
question = self.quizzes[g.lang].get_quiz_data_for_level_question(level, question, keyword_lang)
else:
question = self.quizzes[g.lang].get_quiz_data_for_level_question(level, question, g.keyword_lang)
return jsonify(question), 200

@route("/preview-question/<int:level>/<int:question>", methods=["GET"])
Expand Down

0 comments on commit 0f73352

Please sign in to comment.