[FIX] website_slides: various fixes

Display
 * improve color of trophy displayed on top of course main page (success if
   course done, warning while working on it);
 * correctly fetch and display karma/xp points on course lesson list. It is
   either gain of next try, either awarded points depending on slide
   completion;
 * fix control buttons in course main page (prev, next, set done,
   set completed, fullscren), notably correctly set them disabled;

Linting / Code
 * put demo in no update;
 * rename some parameter in website_slides_survey to avoid conflict between
   quiz (on a slide) and certification (a survey);

 Commit linked to task ID 1941250 and PR #31697.

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Thibault Delavallée
2019-03-08 11:15:07 +00:00
parent 523c1276a1
commit 7afd23e56c
10 changed files with 36 additions and 28 deletions
+1 -1
View File
@@ -434,7 +434,7 @@ class WebsiteSlides(WebsiteProfile):
}]
values['slide_promoted'] = request.env['slide.slide'].sudo().search(domain, limit=1, order=order)
values['category_data'] = category_data
values['channel_progress'] = self._get_channel_progress(channel)
values['channel_progress'] = self._get_channel_progress(channel, include_quiz=True)
values = self._prepare_additional_channel_values(values, **kw)
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo><data noupdate="0">
<odoo><data noupdate="1">
<record id="website_slides.channel_public" model="slide.channel">
<field name="name">Basics of Gardening</field>
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo><data noupdate="0">
<odoo><data noupdate="1">
<!-- CHANNEL 0: Basics of Gardening -->
<!-- ================================================== -->
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo><data noupdate="0">
<odoo><data noupdate="1">
<!-- CHANNEL 0: Basics of Gardening -->
<!-- ================================================== -->
@@ -346,7 +346,10 @@
<span t-esc="slide.name"/>
</span>
<t t-if="slide.question_ids">
<span class="badge badge-warning text-white font-weight-bold"><i class="fa fa-flag"></i><t t-esc="channel_progress[slide.id].get('quiz_gain', slide.quiz_first_attempt_reward)"/> xp</span>
<span t-att-class="'badge text-white font-weight-bold %s' % ('badge-success' if channel_progress[slide.id].get('completed') else 'badge-warning')">
<i class="fa fa-flag mr-2"></i>
<t t-esc="channel_progress[slide.id].get('quiz_karma_won', 0) if channel_progress[slide.id].get('completed') else channel_progress[slide.id].get('quiz_karma_gain', 0)"/> xp
</span>
</t>
<span class="badge badge-info ml-2" t-if="slide.is_preview">Free preview</span>
<div t-if="channel.is_member or channel.can_publish" class="pt-2 pb-2 border-left ml-2 mr-2 pl-2 d-flex align-items-center o_wslides_slides_list_slide_controls">
@@ -26,7 +26,7 @@
<span><t t-esc="slide.channel_id.completion"/> %</span>
</div>
</div>
<i t-att-class="'fa fa-trophy m-0 ml-2 p-0 %s' % ('text-warning' if slide.channel_id.completed else 'text-light')"></i>
<i t-att-class="'fa fa-trophy m-0 ml-2 p-0 %s' % ('text-success' if slide.channel_id.completed else 'text-warning')"></i>
</div>
</div>
</div>
@@ -146,7 +146,7 @@
<span t-esc="aside_slide.name" t-att-class="'mr-2 %s' % ('text-800' if aside_slide == slide else 'text-600')"/>
<span t-if="aside_slide.question_ids"
t-att-class="'ml-auto badge badge-pill %s' % ('badge-success' if channel_progress[aside_slide.id].get('completed') else 'badge-light text-600')">
<t t-esc="channel_progress[aside_slide.id].get('quiz_karma_max')"/>
<t t-esc="channel_progress[aside_slide.id].get('quiz_karma_won') if channel_progress[aside_slide.id].get('completed') else channel_progress[aside_slide.id].get('quiz_karma_gain')"/> xp
</span>
</a>
<ul t-if="aside_slide.link_ids or aside_slide.question_ids" class="list-group ml-5 list-unstyled">
@@ -186,20 +186,24 @@
</span>
</div>
<div class="ml-auto">
<a class="btn btn-light border" role="button"
t-att-disabled="'disabled' if not previous_slide else None"
t-att-href="'/slides/slide/%s' % (slug(previous_slide)) if previous_slide else '#'"><i class="fa fa-chevron-left mr-2"></i> Prev</a>
<a class="btn btn-primary border text-white" role="button"
t-att-disabled="'disabled' if slide.question_ids or channel_progress[slide.id].get('completed') else None"
t-att-href="None if (channel_progress[slide.id].get('completed') or slide.question_ids) else '/slides/slide/%s/set_completed?%s' % (slide.id, 'next_slide_id=%s' % (next_slide.id) if next_slide else '')">
<a t-att-class="'btn btn-light border %s' % ('disabled' if not previous_slide else '')"
role="button" t-att-aria-disabled="'disabled' if not previous_slide else None"
t-att-href="'/slides/slide/%s' % (slug(previous_slide)) if previous_slide else '#'">
<i class="fa fa-chevron-left mr-2"></i> Prev
</a>
<a t-att-class="'btn btn-primary border text-white %s' % ('disabled' if slide.question_ids or channel_progress[slide.id].get('completed') else '')"
role="button" t-att-aria-disabled="'true' if slide.question_ids or channel_progress[slide.id].get('completed') else None"
t-att-href="'#' if slide.question_ids or channel_progress[slide.id].get('completed') else '/slides/slide/%s/set_completed?%s' % (slide.id, 'next_slide_id=%s' % (next_slide.id) if next_slide else '')">
Set Done
</a>
<a class="btn btn-light border" role="button"
t-att-disabled="'disabled' if not next_slide else None"
t-att-href="'/slides/slide/%s' % (slug(next_slide)) if next_slide else '#'">Next <i class="fa fa-chevron-right ml-2"></i></a>
<a class="btn btn-light border ml-2" role="button"
t-att-disabled="'disabled' if slide.channel_id.channel_type != 'training' else None"
t-att-href="'/slides/slide/%s?fullscreen=1' % (slug(slide))"><i class="fa fa-desktop mr-2"></i> Fullscreen</a>
<a t-att-class="'btn btn-light border %s' % ('disabled' if not next_slide else '')"
role="button" t-att-aria-disabled="'disabled' if not next_slide else None"
t-att-href="'/slides/slide/%s' % (slug(next_slide)) if next_slide else '#'">
Next <i class="fa fa-chevron-right ml-2"></i>
</a>
<a t-att-class="'btn btn-light border ml-2 %s' % ('disabled' if slide.channel_id.channel_type != 'training' else '')"
role="button" t-att-aria-disabled="'disabled' if slide.channel_id.channel_type != 'training' else None"
t-att-href="'/slides/slide/%s?fullscreen=1' % (slug(slide)) if slide.channel_id.channel_type == 'training' else '#'"><i class="fa fa-desktop mr-2"></i> Fullscreen</a>
</div>
</div>
<div t-if="slide.tag_ids" class="col">
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo><data noupdate="0">
<odoo><data noupdate="1">
<record id="forum_forum_demo_channel_0" model="forum.forum">
<field name="name">Basics of Gardening</field>
@@ -7,6 +7,7 @@ from odoo.http import request
class WebsiteSlides(WebsiteSlides):
def _get_valid_slide_post_values(self):
result = super(WebsiteSlides, self)._get_valid_slide_post_values()
result.append('survey_id')
@@ -24,10 +25,12 @@ class WebsiteSlides(WebsiteSlides):
This is used in the context of a website_publisher designing a course."""
result = super(WebsiteSlides, self)._get_slide_detail(slide)
if not request.env.user._is_public() and slide.slide_type == 'certification' and slide.survey_id:
result['certification_test_entry'] = not slide.channel_id.is_member
result['certification_done'] = False
if slide.channel_id.is_member:
user_membership_id_sudo = slide.user_membership_id.sudo()
quizz_passed = user_membership_id_sudo.survey_quizz_passed
result['quizz_passed'] = quizz_passed
result['certification_done'] = quizz_passed
result['survey_id'] = slide.survey_id.id
if not quizz_passed:
last_user_input = next(user_input for user_input in user_membership_id_sudo.user_input_ids.sorted(
@@ -35,8 +38,6 @@ class WebsiteSlides(WebsiteSlides):
))
result['certification_url'] = last_user_input._get_survey_url()
else:
result['quizz_passed'] = False
result['test_entry'] = True
user_input = slide.survey_id._create_answer(
partner=request.env.user.partner_id,
check_attempts=False,
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo><data noupdate="0">
<odoo><data noupdate="1">
<!-- CHANNEL 5: Basics of Furniture Creation -->
<!-- ======================================= -->
@@ -3,9 +3,9 @@
<data>
<template id="slide_content_detailed" inherit_id="website_slides.slide_content_detailed">
<xpath expr="//div[hasclass('o_wslides_lesson_content_type')]" position="inside">
<t t-if="not test_entry" t-set="begin_certification_label" t-value="'Begin certification'" />
<t t-if="test_entry" t-set="begin_certification_label" t-value="'Test certification'" />
<div t-if="slide.slide_type == 'certification' and not quizz_passed" class="mb8">
<t t-if="not certification_test_entry" t-set="begin_certification_label" t-value="'Begin certification'" />
<t t-if="certification_test_entry" t-set="begin_certification_label" t-value="'Test certification'" />
<div t-if="slide.slide_type == 'certification' and not certification_done" class="col mt32 mb8 d-flex justify-content-center">
<a role="button"
class="btn btn-primary btn-lg"
t-att-href="certification_url">
@@ -13,7 +13,7 @@
<t t-esc="begin_certification_label" />
</a>
</div>
<div t-if="slide.slide_type == 'certification' and quizz_passed" class="mb8">
<div t-if="slide.slide_type == 'certification' and certification_done" class="col mt32 mb8 d-flex justify-content-center">
<a role="button"
t-att-data-survey_id="survey_id"
class="btn btn-primary btn-lg o_wslides_survey_download_certification"