From fcf197800ef5fc9a45b079f0f87900a16655cf34 Mon Sep 17 00:00:00 2001 From: Muhammad Faraz Maqsood Date: Fri, 22 Dec 2023 14:10:53 +0500 Subject: [PATCH] feat!: add badgr settings, make badges and courses independent incase of programs --- lms/djangoapps/badges/events/course_meta.py | 10 +++++----- lms/djangoapps/certificates/models.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lms/djangoapps/badges/events/course_meta.py b/lms/djangoapps/badges/events/course_meta.py index bef7b8dd79c2..c5fbbefce5cb 100644 --- a/lms/djangoapps/badges/events/course_meta.py +++ b/lms/djangoapps/badges/events/course_meta.py @@ -62,16 +62,16 @@ def course_group_check(user, course_key): """ Awards a badge if a user has completed every course in a defined set. """ - from lms.djangoapps.certificates.data import CertificateStatuses + from lms.djangoapps.grades.models import PersistentCourseGrade config = CourseEventBadgesConfiguration.current().course_group_settings awards = [] for slug, keys in config.items(): if course_key in keys: - certs = user.generatedcertificate_set.filter( - status__in=CertificateStatuses.PASSED_STATUSES, + passed_courses = PersistentCourseGrade.objects.filter( + passed_timestamp__isnull=False, course_id__in=keys, - ) - if len(certs) == len(keys): + ).count() + if passed_courses == len(keys): awards.append(slug) for slug in awards: diff --git a/lms/djangoapps/certificates/models.py b/lms/djangoapps/certificates/models.py index 34c705a7c7ac..9d2e2967c7ad 100644 --- a/lms/djangoapps/certificates/models.py +++ b/lms/djangoapps/certificates/models.py @@ -1252,12 +1252,12 @@ def create_completion_badge(sender, user, course_key, status, **kwargs): # pyli completion_check(user) -@receiver(COURSE_CERT_AWARDED, sender=GeneratedCertificate) -def create_course_group_badge(sender, user, course_key, status, **kwargs): # pylint: disable=unused-argument +@receiver(COURSE_GRADE_NOW_PASSED, dispatch_uid="new_passing_learner") +def create_course_group_badge(sender, user, course_id, **kwargs): # pylint: disable=unused-argument """ Standard signal hook to create badges when a user has completed a prespecified set of courses. """ - course_group_check(user, course_key) + course_group_check(user, course_id) class CertificateGenerationCommandConfiguration(ConfigurationModel):