def get_completion_badge(course_id, user):
 from student.models import CourseEnrollment
 badge_classes = CourseEnrollment.objects.filter(user=user, course_id=course_id).order_by('-is_active')
 if (not badge_classes):
  return None
 mode = badge_classes[0].mode
 course = modulestore().get_course(course_id)
 if (not course.issue_badges):
  return None
 return BadgeClass.get_badge_class(slug=course_slug(course_id, mode), issuing_component='', criteria=criteria(course_id), description=badge_description(course, mode), course_id=course_id, mode=mode, display_name=course.display_name, image_file_handle=CourseCompleteImageConfiguration.image_for_mode(mode))

def get_completion_badge ( course_id , user ) : from student . models import CourseEnrollment badge_classes = CourseEnrollment . objects . filter ( user = user , course_id = course_id ) . order_by ( '-is_active' ) if ( not badge_classes ) : return None mode = badge_classes [ 0 ] . mode course = modulestore ( ) . get_course ( course_id ) if ( not course . issue_badges ) : return None return BadgeClass . get_badge_class ( slug = course_slug ( course_id , mode ) , issuing_component = '' , criteria = criteria ( course_id ) , description = badge_description ( course , mode ) , course_id = course_id , mode = mode , display_name = course . display_name , image_file_handle = CourseCompleteImageConfiguration . image_for_mode ( mode ) )
given a course key and a user .