Commit 010f7eb5 by Nimisha Asthagiri Committed by GitHub

Merge pull request #13684 from edx/student_cleanup/decoupled_dependencies

Decouple student's dependency on badges with django signals
parents 2112e7f8 1717e0c4
...@@ -47,7 +47,6 @@ from simple_history.models import HistoricalRecords ...@@ -47,7 +47,6 @@ from simple_history.models import HistoricalRecords
from track import contexts from track import contexts
from openedx.core.djangoapps.xmodule_django.models import CourseKeyField, NoneToEmptyManager from openedx.core.djangoapps.xmodule_django.models import CourseKeyField, NoneToEmptyManager
from lms.djangoapps.badges.utils import badges_enabled
from certificates.models import GeneratedCertificate from certificates.models import GeneratedCertificate
from course_modes.models import CourseMode from course_modes.models import CourseMode
from enrollment.api import _default_course_mode from enrollment.api import _default_course_mode
...@@ -1297,9 +1296,7 @@ class CourseEnrollment(models.Model): ...@@ -1297,9 +1296,7 @@ class CourseEnrollment(models.Model):
# User is allowed to enroll if they've reached this point. # User is allowed to enroll if they've reached this point.
enrollment = cls.get_or_create_enrollment(user, course_key) enrollment = cls.get_or_create_enrollment(user, course_key)
enrollment.update_enrollment(is_active=True, mode=mode) enrollment.update_enrollment(is_active=True, mode=mode)
if badges_enabled(): enrollment.send_signal(EnrollStatusChange.enroll)
from lms.djangoapps.badges.events.course_meta import award_enrollment_badge
award_enrollment_badge(user)
return enrollment return enrollment
......
...@@ -1079,8 +1079,7 @@ def change_enrollment(request, check_access=True): ...@@ -1079,8 +1079,7 @@ def change_enrollment(request, check_access=True):
try: try:
enroll_mode = CourseMode.auto_enroll_mode(course_id, available_modes) enroll_mode = CourseMode.auto_enroll_mode(course_id, available_modes)
if enroll_mode: if enroll_mode:
enrollment = CourseEnrollment.enroll(user, course_id, check_access=check_access, mode=enroll_mode) CourseEnrollment.enroll(user, course_id, check_access=check_access, mode=enroll_mode)
enrollment.send_signal(EnrollStatusChange.enroll)
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
return HttpResponseBadRequest(_("Could not enroll")) return HttpResponseBadRequest(_("Could not enroll"))
......
"""
Badges Application Configuration
Signal handlers are connected here.
"""
from django.apps import AppConfig
class BadgesConfig(AppConfig):
"""
Application Configuration for Badges.
"""
name = u'badges'
def ready(self):
"""
Connect signal handlers.
"""
from . import handlers # pylint: disable=unused-variable
"""
Badges related signal handlers.
"""
from django.dispatch import receiver
from lms.djangoapps.badges.events.course_meta import award_enrollment_badge
from lms.djangoapps.badges.utils import badges_enabled
from student.models import ENROLL_STATUS_CHANGE, EnrollStatusChange
@receiver(ENROLL_STATUS_CHANGE)
def award_badge_on_enrollment(sender, event=None, user=None, **kwargs): # pylint: disable=unused-argument
"""
Awards enrollment badge to the given user on new enrollments.
"""
if badges_enabled and event == EnrollStatusChange.enroll:
award_enrollment_badge(user)
...@@ -2093,7 +2093,7 @@ INSTALLED_APPS = ( ...@@ -2093,7 +2093,7 @@ INSTALLED_APPS = (
'learner_dashboard', 'learner_dashboard',
# Needed whether or not enabled, due to migrations # Needed whether or not enabled, due to migrations
'badges', 'badges.apps.BadgesConfig',
# Enables default site and redirects # Enables default site and redirects
'django_sites_extensions', 'django_sites_extensions',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment