Exemplo n.º 1
0
    def update_assignment_grades(cls, compair_assignment):
        from compair.models import CourseRole, AssignmentGrade
        from compair.tasks.lti_outcomes import update_lti_assignment_grades

        lti_resource_links = compair_assignment.lti_resource_links.all()

        # nothing to update if assignment not linked to any lti resources
        if len(lti_resource_links) == 0:
            return

        assignment_grades = AssignmentGrade.query \
            .filter_by(assignment_id=compair_assignment.id) \
            .all()

        # nothing to update if assignment doesn't have any grades
        if len(assignment_grades) == 0:
            return

        user_grades = {
            assignment_grade.user_id: assignment_grade.id \
                for assignment_grade in assignment_grades
        }

        # generate requests
        for lti_resource_link in lti_resource_links:
            lti_consumer = lti_resource_link.lti_consumer
            resource_link_grades = []
            if not lti_consumer.lis_outcome_service_url:
                continue

            lti_user_resource_links = lti_resource_link.lti_user_resource_links.all()
            for lti_user_resource_link in lti_user_resource_links:
                if (not lti_user_resource_link.lis_result_sourcedid or
                        lti_user_resource_link.course_role != CourseRole.student):
                    continue

                lis_result_sourcedid = lti_user_resource_link.lis_result_sourcedid
                assignment_grade_id = user_grades.get(lti_user_resource_link.compair_user_id)

                resource_link_grades.append((lis_result_sourcedid, assignment_grade_id))

            if len(resource_link_grades) == 0:
                continue

            update_lti_assignment_grades.delay(lti_consumer.id, resource_link_grades)
Exemplo n.º 2
0
    def update_user_assignment_grade(cls, compair_assignment, compair_user):
        from compair.models import CourseRole, AssignmentGrade, LTIUser
        from compair.tasks.lti_outcomes import update_lti_assignment_grades

        lti_resource_links = compair_assignment.lti_resource_links.all()

        # nothing to update if assignment not linked to any lti resources
        if len(lti_resource_links) == 0:
            return

        assignment_grade = AssignmentGrade.query \
            .filter_by(
                user_id=compair_user.id,
                assignment_id=compair_assignment.id
            ) \
            .one_or_none()

        # generate requests
        for lti_resource_link in lti_resource_links:
            lti_consumer = lti_resource_link.lti_consumer
            resource_link_grades = []
            if not lti_consumer.lis_outcome_service_url:
                continue

            lti_user_resource_links = lti_resource_link.lti_user_resource_links \
                .join("lti_user") \
                .filter(LTIUser.compair_user_id == compair_user.id) \
                .all()

            for lti_user_resource_link in lti_user_resource_links:
                if (not lti_user_resource_link.lis_result_sourcedid or
                        lti_user_resource_link.course_role != CourseRole.student):
                    continue

                lis_result_sourcedid = lti_user_resource_link.lis_result_sourcedid
                assignment_grade_id = assignment_grade.id if assignment_grade else None

                resource_link_grades.append((lis_result_sourcedid, assignment_grade_id))

            if len(resource_link_grades) == 0:
                continue

            update_lti_assignment_grades.delay(lti_consumer.id, resource_link_grades)