@receiver(COURSE_GRADE_CHANGED)
def listen_for_grade_calculation(sender, user, course_grade, course_key, deadline, **kwargs):
 from openedx.core.djangoapps.credit import api
 course_id = CourseKey.from_string(unicode(course_key))
 is_credit = api.is_credit_course(course_id)
 if is_credit:
  requirements = api.get_credit_requirements(course_id, namespace='grade')
  if requirements:
   criteria = requirements[0].get('criteria')
   if criteria:
    min_grade = criteria.get('min_grade')
    passing_grade = (course_grade.percent >= min_grade)
    now = timezone.now()
    status = None
    reason = None
    if ((deadline and (now < deadline)) or (not deadline)):
     if passing_grade:
      status = 'satisfied'
      reason = {'final_grade': course_grade.percent}
    elif passing_grade:
     status = 'failed'
     reason = {'current_date': now, 'deadline': deadline}
    else:
     status = 'failed'
     reason = {'final_grade': course_grade.percent, 'minimum_grade': min_grade}
    if (status and reason):
     api.set_credit_requirement_status(user, course_id, 'grade', 'grade', status=status, reason=reason)

@ receiver ( COURSE_GRADE_CHANGED ) def listen_for_grade_calculation ( sender , user , course_grade , course_key , deadline , ** kwargs ) : from openedx . core . djangoapps . credit import api course_id = CourseKey . from_string ( unicode ( course_key ) ) is_credit = api . is_credit_course ( course_id ) if is_credit : requirements = api . get_credit_requirements ( course_id , namespace = 'grade' ) if requirements : criteria = requirements [ 0 ] . get ( 'criteria' ) if criteria : min_grade = criteria . get ( 'min_grade' ) passing_grade = ( course_grade . percent >= min_grade ) now = timezone . now ( ) status = None reason = None if ( ( deadline and ( now < deadline ) ) or ( not deadline ) ) : if passing_grade : status = 'satisfied' reason = { 'final_grade' : course_grade . percent } elif passing_grade : status = 'failed' reason = { 'current_date' : now , 'deadline' : deadline } else : status = 'failed' reason = { 'final_grade' : course_grade . percent , 'minimum_grade' : min_grade } if ( status and reason ) : api . set_credit_requirement_status ( user , course_id , 'grade' , 'grade' , status = status , reason = reason )
receive min_grade_requirement_status signal and update minimum grade requirement status .