Skip to content

Commit

Permalink
Certificates can now be created for every level (hedyorg#3985)
Browse files Browse the repository at this point in the history
Certificates page can now be rendered for everyone giving some fun statistics including the highest completed level.
  • Loading branch information
Mark-Giesen authored Jan 27, 2023
1 parent a3ee0bf commit b17905b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 10 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,20 +1220,28 @@ def get_certificate_page(username):
if progress_data is None:
return utils.error_page(error=404, ui_message=gettext('no_certificate'))
achievements = progress_data.get('achieved', None)
if achievements is None or 'hedy_certificate' not in achievements:
if achievements is None:
return utils.error_page(error=404, ui_message=gettext('no_certificate'))
if 'run_programs' in progress_data:
count_programs = progress_data['run_programs']
else:
count_programs = 0
quiz_score = get_highest_quiz_score(username)
quiz_level = get_highest_quiz_level(username)
longest_program = get_longest_program(username)

number_achievements = len(achievements)
congrats_message = safe_format(gettext('congrats_message'), username=username)
return render_template("certificate.html", count_programs=count_programs, quiz_score=quiz_score,
longest_program=longest_program, number_achievements=number_achievements,
congrats_message=congrats_message)
quiz_level=quiz_level, congrats_message=congrats_message)


def get_highest_quiz_level(username):
quiz_scores = DATABASE.get_quiz_stats([username])
# Verify if the user did finish any quiz before getting the max() of the finished levels
finished_quizzes = any("finished" in x for x in quiz_scores)
return max([x.get("level") for x in quiz_scores if x.get("finished")]) if finished_quizzes else "-"


def get_highest_quiz_score(username):
Expand Down
5 changes: 3 additions & 2 deletions templates/certificate.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ <h2 class="text-black text-4xl font-sans font-light mb-8">{{congrats_message}}
<h2 class="text-black text-2xl font-sans font-light mb-8">{{_('fun_statistics_msg')}}</h2>
<div class="bg-white w-full h-auto shadow-md px-12 py-4 text-lg">
<div class="flex flex-col gap-2 my-4 pb-4 border-b-2 border-gray-500">
<h2 class="my-0 py-0">{{_('number_programs')}} 💻: {{count_programs}}</h2>
<h2 class="my-0 py-0">{{_('highest_level_reached')}} : {{quiz_level}}</h2>
<h2 class="my-0 py-0">{{_('highest_quiz_score')}} ✅: {{quiz_score}}</h2>
<h2 class="my-0 py-0">{{_('number_programs')}} 💻: {{count_programs}}</h2>
<h2 class="my-0 py-0">{{_('longest_program')}} 👩‍💻: {{longest_program}}</h2>
<h2 class="my-0 py-0">{{_('number_achievements')}} 🏆: {{number_achievements}}</h2>
</div>
Expand All @@ -39,4 +40,4 @@ <h2 class="my-0 py-0">{{_('number_achievements')}} 🏆: {{number_achievements}}
<script src="{{static('/vendor/ext-rtl.js')}}" type="text/javascript" charset="utf-8" crossorigin="anonymous"></script>
<script src="{{static('/js/appbundle.js')}}" type="text/javascript" crossorigin="anonymous"></script>
</body>
</html>
</html>

0 comments on commit b17905b

Please sign in to comment.