'Looks at the currently active configuration model to determine whether
the persistent grades feature is available.
If the flag is not enabled, the feature is not available.
If the flag is enabled and the provided course_id is for an course
with persistent grades enabled, the feature is available.
If the flag is enabled and no course ID is given,
we return True since the global setting is enabled.'

@classmethod
@request_cached
def feature_enabled(cls, course_id=None):

    if settings.FEATURES.get('PERSISTENT_GRADES_ENABLED_FOR_ALL_TESTS'):
        return True
    if (not PersistentGradesEnabledFlag.is_enabled()):
        return False
    elif ((not PersistentGradesEnabledFlag.current().enabled_for_all_courses) and course_id):
        effective = CoursePersistentGradesFlag.objects.filter(course_id=course_id).order_by('-change_date').first()
        return (effective.enabled if (effective is not None) else False)
    return True
