Skip to content

Commit

Permalink
feat!: add badgr settings, make badges and courses independent incase…
Browse files Browse the repository at this point in the history
… of programs
  • Loading branch information
Muhammad Faraz Maqsood authored and Muhammad Faraz Maqsood committed Dec 22, 2023
1 parent f497c7b commit fcf1978
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions lms/djangoapps/badges/events/course_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions lms/djangoapps/certificates/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit fcf1978

Please sign in to comment.