Example #1
0
class CourseEnrollmentViewset(DataApiViewSet):  # pylint: disable=too-many-ancestors
    """
    A viewset for viewing Course Enrollments.
    """
    serializer_class = CourseEnrollmentSerializer
    queryset = get_course_enrollment().objects.all()
    filter_class = CourseEnrollmentFilter
    # Microsite enforcement filter settings
    enforce_microsite_filter = True
    enforce_microsite_filter_lookup_field = "course__id__contains"
    enforce_microsite_filter_term = "org_in_course_id"
Example #2
0
 class Meta:
     """
     TODO: add me
     """
     model = get_course_enrollment()
     fields = [
         'id',
         'course_id',
         'created',
         'is_active',
         'mode',
         'site',
     ]
Example #3
0
    def run(self, data, *args, **kwargs):  # pylint: disable=unused-argument
        """
        This task receives a list with enrollments, and returns the same
        enrollments with grades data
        """

        enrollments_ids = [el["id"] for el in data]
        enrollments_queryset = get_course_enrollment().objects.filter(
            id__in=enrollments_ids)

        serializer = CourseEnrollmentWithGradesSerializer(enrollments_queryset,
                                                          many=True)

        return serializer.data
Example #4
0
class CourseEnrollmentWithGradesViewset(DataApiViewSet):  # pylint: disable=too-many-ancestors
    """
    A viewset for viewing Course Enrollments with grades data.
    This view will create a celery task to fetch grades data for
    enrollments in the background, and will return the id of the
    celery task
    """
    serializer_class = CourseEnrollmentSerializer
    queryset = get_course_enrollment().objects.all()
    filter_class = CourseEnrollmentFilter
    # Microsite enforcement filter settings
    enforce_microsite_filter = True
    enforce_microsite_filter_lookup_field = "course__id__contains"
    enforce_microsite_filter_term = "org_in_course_id"

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)

        now_date = datetime.now()
        string_now_date = now_date.strftime("%Y-%m-%d-%H-%M-%S")
        randnum = random.randint(100, 999)
        task_id = "data_api-" + string_now_date + "-" + str(randnum)

        named_args = {
            "data": serializer.data,
        }

        task = EnrollmentsGrades().apply_async(
            kwargs=named_args,
            task_id=task_id,
            routing_key=settings.GRADES_DOWNLOAD_ROUTING_KEY
        )

        url_task_status = request.build_absolute_uri(
            reverse("eox-core:eox-data-api:celery-data-api-tasks", kwargs={"task_id": task_id})
        )
        data_response = {
            "task_id": task.id,
            "task_url": url_task_status,
        }
        return Response(data_response, status=status.HTTP_202_ACCEPTED)