[IMP] website_slides_survey: keep challenge category updated
Purpose of this commit is to ensure challenge linked to surveys linked to
slides have ``slides`` category, while challenge linked to surveys not
linked to slides (if changing survey_id for example) have ``certification``
category.
With this patch challenges are correctly categorized, allowing to accurately
filter them based on their category.
Task ID : 1961053
PR #32594
This commit is contained in:
committed by
Thibault Delavallée
parent
be3f074a91
commit
21cdbd82e9
@@ -705,6 +705,8 @@ class Survey(models.Model):
|
||||
# ------------------------------------------------------------
|
||||
# GAMIFICATION / BADGES
|
||||
# ------------------------------------------------------------
|
||||
def _prepare_challenge_category(self):
|
||||
return 'certification'
|
||||
|
||||
def _create_certification_badge_trigger(self):
|
||||
self.ensure_one()
|
||||
@@ -725,7 +727,7 @@ class Survey(models.Model):
|
||||
'reward_id': self.certification_badge_id.id,
|
||||
'state': 'inprogress',
|
||||
'period': 'once',
|
||||
'challenge_category': 'certification',
|
||||
'challenge_category': self._prepare_challenge_category(),
|
||||
'reward_realtime': True,
|
||||
'report_message_frequency': 'never',
|
||||
'user_domain': [('karma', '>', 0)],
|
||||
|
||||
@@ -57,8 +57,34 @@ class Slide(models.Model):
|
||||
rec = super(Slide, self).create(values)
|
||||
if rec.survey_id:
|
||||
rec.slide_type = 'certification'
|
||||
if 'survey_id' in values:
|
||||
rec._ensure_challenge_category()
|
||||
return rec
|
||||
|
||||
def write(self, values):
|
||||
old_surveys = self.mapped('survey_id')
|
||||
result = super(Slide, self).write(values)
|
||||
if 'survey_id' in values:
|
||||
self._ensure_challenge_category(old_surveys=old_surveys - self.mapped('survey_id'))
|
||||
return result
|
||||
|
||||
def unlink(self):
|
||||
old_surveys = self.mapped('survey_id')
|
||||
result = super(Slide, self).unlink()
|
||||
self._ensure_challenge_category(old_surveys=old_surveys, unlink=True)
|
||||
return result
|
||||
|
||||
def _ensure_challenge_category(self, old_surveys=None, unlink=False):
|
||||
""" If a slide is linked to a survey that gives a badge, the challenge category of this badge must be
|
||||
set to 'slides' in order to appear under the certification badge list on ranks_badges page.
|
||||
If the survey is unlinked from the slide, the challenge category must be reset to 'certification'"""
|
||||
if old_surveys:
|
||||
old_certification_challenges = old_surveys.mapped('certification_badge_id').challenge_ids
|
||||
old_certification_challenges.write({'challenge_category': 'certification'})
|
||||
if not unlink:
|
||||
certification_challenges = self.mapped('survey_id').mapped('certification_badge_id').challenge_ids
|
||||
certification_challenges.write({'challenge_category': 'slides'})
|
||||
|
||||
def _generate_certification_url(self):
|
||||
""" get a map of certification url for certification slide from `self`. The url will come from the survey user input:
|
||||
1/ existing and not done user_input for member of the course
|
||||
|
||||
@@ -14,3 +14,7 @@ class Survey(models.Model):
|
||||
return True
|
||||
|
||||
return super(Survey, self)._check_answer_creation(user, partner, email, test_entry=test_entry, check_attempts=check_attempts, invite_token=invite_token)
|
||||
|
||||
def _prepare_challenge_category(self):
|
||||
slide_survey = self.env['slide.slide'].search([('survey_id', '=', self.id)])
|
||||
return 'slides' if slide_survey else 'certification'
|
||||
|
||||
Reference in New Issue
Block a user