Example #1
0
    def put(self, request, *args, **kwargs):
        """
        Update whitelistings on edxapp
        """
        serializer = EdxappCoursePreEnrollmentSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        data = serializer.validated_data
        email = data.get('email')
        course_id = data.get('course_id')
        auto_enroll = data.pop('auto_enroll', False)

        pre_enrollment_query = {
            'email': email,
            'course_id': course_id,
        }

        pre_enrollment = get_pre_enrollment(**pre_enrollment_query)
        update_query = {
            'pre_enrollment': pre_enrollment,
            'auto_enroll': auto_enroll,
        }
        updated_pre_enrollment = update_pre_enrollment(**update_query)
        response = EdxappCoursePreEnrollmentSerializer(
            updated_pre_enrollment).data
        return Response(response)
Example #2
0
    def delete(self, request, *args, **kwargs):
        """
        Delete whitelistings on edxapp
        """
        query_params = request.query_params
        if not query_params:
            query_params = request.data

        serializer = EdxappCoursePreEnrollmentSerializer(data=query_params)
        serializer.is_valid(raise_exception=True)
        data = serializer.validated_data
        email = data.get('email')
        course_id = data.get('course_id')

        pre_enrollment_query = {
            'email': email,
            'course_id': course_id,
        }

        pre_enrollment = get_pre_enrollment(**pre_enrollment_query)
        delete_query = {
            'pre_enrollment': pre_enrollment,
        }
        delete_pre_enrollment(**delete_query)
        return Response(status=status.HTTP_204_NO_CONTENT)
Example #3
0
 def post(self, request, *args, **kwargs):
     """
     Create whitelistings on edxapp
     """
     serializer = EdxappCoursePreEnrollmentSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     data = serializer.validated_data
     course_id = data.pop('course_id', None)
     pre_enrollment, warning = create_pre_enrollment(course_id=course_id,
                                                     **data)
     response_data = EdxappCoursePreEnrollmentSerializer(
         pre_enrollment, context=warning).data
     return Response(response_data)
Example #4
0
    def get(self, request, *args, **kwargs):
        """
        Get whitelistings on edxapp
        """
        query_params = request.query_params
        if not query_params:
            query_params = request.data

        serializer = EdxappCoursePreEnrollmentSerializer(data=query_params)
        serializer.is_valid(raise_exception=True)
        data = serializer.validated_data
        pre_enrollment = get_pre_enrollment(**data)
        response = EdxappCoursePreEnrollmentSerializer(pre_enrollment).data
        return Response(response)