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)
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)
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)
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)