'Update the user\'s credit eligibility for a course.
A user is eligible for credit when the user has satisfied
all requirements for credit in the course.
Arguments:
requirements (Queryset): Queryset of `CreditRequirement`s to check.
username (str): Identifier of the user being updated.
course_key (CourseKey): Identifier of the course.
Returns: tuple'

@classmethod
def update_eligibility(cls, requirements, username, course_key):

    status_by_req = defaultdict((lambda : False))
    for status in CreditRequirementStatus.get_statuses(requirements, username):
        status_by_req[status.requirement.id] = status.status
    is_eligible = all(((status_by_req[req.id] == 'satisfied') for req in requirements))
    if is_eligible:
        try:
            CreditEligibility.objects.create(username=username, course=CreditCourse.objects.get(course_key=course_key))
            return (is_eligible, True)
        except IntegrityError:
            return (is_eligible, False)
    else:
        return (is_eligible, False)
