Skip to content

Commit

Permalink
fix: adds automatic redirect to exam survey
Browse files Browse the repository at this point in the history
  • Loading branch information
abhigyanghosh30 committed Dec 12, 2023
1 parent 1a419ab commit 4e0d952
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
18 changes: 18 additions & 0 deletions templates/credentials/exam.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@

document.addEventListener('click', refocusIframe);
document.addEventListener('keydown', refocusIframe);

// ping TruCredential every 1 minute to check if exam is over
async function checkExamStatus(){
fetch("/credentials/exam/{{assessment_id}}/status", {
method: "GET",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
}
})
.then((r)=>r.json())
.then((data)=>{
if(data.assessment.ended === true){
window.location.href = "/credentials/exit-survey";
}
});
}
setInterval(checkExamStatus, 1000);
</script>

{% endblock content%}
2 changes: 2 additions & 0 deletions webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
cred_beta_activation,
cred_cancel_exam,
cred_exam,
cred_exam_status,
cred_home,
cred_redeem_code,
cred_schedule,
Expand Down Expand Up @@ -866,6 +867,7 @@ def takeovers_index():
app.add_url_rule("/credentials/cancel-exam", view_func=cred_cancel_exam)
app.add_url_rule("/credentials/assessments", view_func=cred_assessments)
app.add_url_rule("/credentials/exam", view_func=cred_exam)
app.add_url_rule("/credentials/exam/<exam_id>/status", view_func=cred_exam_status)
app.add_url_rule(
"/credentials/<string:type>/products",
view_func=get_cue_products,
Expand Down
7 changes: 6 additions & 1 deletion webapp/shop/cred/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,13 @@ def cred_exam(trueability_api, **_):
return flask.abort(403)

url = trueability_api.get_assessment_redirect(assessment_id)
return flask.render_template("credentials/exam.html", url=url)
return flask.render_template("credentials/exam.html", url=url, assessment_id=assessment_id)

@shop_decorator(area="cred", permission="user", response="json")
def cred_exam_status(trueability_api, **kwargs):
assessment_id = kwargs.get("exam_id")
assessment = trueability_api.get_assessment(assessment_id)
return flask.jsonify(assessment)

@shop_decorator(area="cred", permission="user", response="html")
def cred_syllabus_data(**_):
Expand Down

0 comments on commit 4e0d952

Please sign in to comment.