コード例 #1
0
    def test_get_user_enrollments(self, course_modes, enrollment_mode):
        self._create_course_modes(course_modes)

        # Try to get enrollments before they exist.
        result = data.get_user_enrollments(self.course.id)
        self.assertFalse(result.exists())

        # Create 10 test users to enroll in the course
        users = []
        for i in xrange(10):
            users.append(
                UserFactory.create(username=self.USERNAME + str(i),
                                   email=self.EMAIL + str(i),
                                   password=self.PASSWORD + str(i)))

        # Create the original enrollments.
        created_enrollments = []
        for user in users:
            created_enrollments.append(
                data.create_course_enrollment(user.username,
                                              unicode(self.course.id),
                                              enrollment_mode, True))

        # Compare the created enrollments with the results
        # from the get user enrollments request.
        results = data.get_user_enrollments(self.course.id)
        self.assertTrue(result.exists())
        self.assertEqual(
            EdraakCourseEnrollmentSerializer(results,
                                             many=True,
                                             context={
                                                 'request':
                                                 get_request_or_stub()
                                             }).data, created_enrollments)
コード例 #2
0
    def _get_course_badge_progress(self, course_key):
        """

        """
        progress_response = []

        enrollments_in_course = enrollment_data.get_user_enrollments(
            course_key)

        paged_enrollments = self.paginator.paginate_queryset(
            enrollments_in_course, self.request, view=self)
        enrolled_users = (enrollment.user for enrollment in paged_enrollments)

        for user in enrolled_users:
            progress_response.append({
                "user_id":
                user.id,
                "user_name":
                user.username,
                "name":
                user.profile.name,
                "email":
                user.email,
                "progress":
                self._get_single_user_badge_progress(course_key, user.username)
            })

        return progress_response
コード例 #3
0
    def _iter_user_grades(self, course_key):
        """
        Args:
            course_key (CourseLocator): The course to retrieve grades for.

        Returns:
            An iterator of CourseGrade objects for users enrolled in the given course.
        """
        enrollments_in_course = enrollment_data.get_user_enrollments(course_key)

        paged_enrollments = self.paginate_queryset(enrollments_in_course)
        users = (enrollment.user for enrollment in paged_enrollments)
        grades = CourseGradeFactory().iter(users, course_key=course_key)

        for user, course_grade, exc in grades:
            yield user, course_grade, exc
コード例 #4
0
ファイル: views.py プロジェクト: hemant816/development
    def _get_user_grades(self, course_key):
        """
        Get paginated grades for users in a course.
        Args:
            course_key (CourseLocator): The course to retrieve user grades for.

        Returns:
            A serializable list of grade responses
        """
        enrollments_in_course = enrollment_data.get_user_enrollments(course_key)

        paged_enrollments = self.paginator.paginate_queryset(
            enrollments_in_course, self.request, view=self
        )
        users = (enrollment.user for enrollment in paged_enrollments)
        grades = CourseGradeFactory().iter(users, course_key=course_key)

        grade_responses = []
        for user, course_grade, exc in grades:
            if not exc:
                grade_responses.append(self._make_grade_response(user, course_key, course_grade))

        return Response(grade_responses)