'Creates a course grade in the database.
Returns a PersistedCourseGrade object.'

@classmethod
def update_or_create(cls, user_id, course_id, **kwargs):

    passed = kwargs.pop('passed')
    if (kwargs.get('course_version', None) is None):
        kwargs['course_version'] = ''
    (grade, _) = cls.objects.update_or_create(user_id=user_id, course_id=course_id, defaults=kwargs)
    if (passed and (not grade.passed_timestamp)):
        grade.passed_timestamp = now()
        grade.save()
    cls._emit_grade_calculated_event(grade)
    return grade
