Ejemplo n.º 1
0
    def get_queryset(self):
        """
        Get all the course enrollments for the given course_id and/or given list of usernames.
        """
        form = CourseEnrollmentsApiListForm(self.request.query_params)

        if not form.is_valid():
            raise ValidationError(form.errors)

        queryset = CourseEnrollment.objects.all()
        course_id = form.cleaned_data.get('course_id')
        usernames = form.cleaned_data.get('username')

        if course_id:
            queryset = queryset.filter(course_id=course_id)
        if usernames:
            queryset = queryset.filter(user__username__in=usernames)
        return queryset
Ejemplo n.º 2
0
    def get_queryset(self):
        """
        Get all the course enrollments for the given course_id and/or given list of usernames.
        """
        form = CourseEnrollmentsApiListForm(self.request.query_params)

        if not form.is_valid():
            raise ValidationError(form.errors)

        queryset = CourseEnrollment.objects.all()
        course_id = form.cleaned_data.get('course_id')
        usernames = form.cleaned_data.get('username')

        if course_id:
            queryset = queryset.filter(course_id=course_id)
        if usernames:
            queryset = queryset.filter(user__username__in=usernames)
        return queryset