signals.py 1.05 KB
Newer Older
1 2 3 4
"""
Signal handlers for the gating djangoapp
"""
from django.dispatch import receiver
5 6

from gating import api as gating_api
7
from lms.djangoapps.grades.signals.signals import PROBLEM_WEIGHTED_SCORE_CHANGED
8 9
from opaque_keys.edx.keys import CourseKey, UsageKey
from xmodule.modulestore.django import modulestore
10 11


12
@receiver(PROBLEM_WEIGHTED_SCORE_CHANGED)
13
def handle_score_changed(**kwargs):
14
    """
15
    Receives the PROBLEM_WEIGHTED_SCORE_CHANGED signal sent by LMS when a student's score has changed
16 17 18 19 20 21 22 23 24
    for a given component and triggers the evaluation of any milestone relationships
    which are attached to the updated content.

    Arguments:
        kwargs (dict): Contains user ID, course key, and content usage key

    Returns:
        None
    """
25
    course = modulestore().get_course(CourseKey.from_string(kwargs.get('course_id')))
26
    block = modulestore().get_item(UsageKey.from_string(kwargs.get('usage_id')))
27
    gating_api.evaluate_prerequisite(course, block, kwargs.get('user_id'))
28
    gating_api.evaluate_entrance_exam(course, block, kwargs.get('user_id'))