From 26f028f27eede3de109e7c227fa9b2df8cea85c1 Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Wed, 27 Nov 2024 12:57:20 +0500 Subject: [PATCH] fixing issue with of delete action --- lms/djangoapps/instructor/views/api.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index 741ee517b1c4..e576a34bc580 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -14,6 +14,7 @@ import random import re + import dateutil import pytz import edx_api_doc_tools as apidocs @@ -22,7 +23,7 @@ from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist, PermissionDenied, ValidationError from django.core.validators import validate_email from django.db import IntegrityError, transaction -from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotFound +from django.http import QueryDict, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotFound from django.shortcuts import redirect from django.urls import reverse from django.utils.decorators import method_decorator @@ -3335,6 +3336,7 @@ def _handle_certificate_exception(self, request, course_id, action): """ Handles adding or removing certificate exceptions. """ + breakpoint() course_key = CourseKey.from_string(course_id) try: data = request.data @@ -3367,6 +3369,13 @@ def _get_and_validate_user(self, raw_data): """ Extracts the user data from the request and validates the student. """ + if isinstance(raw_data, QueryDict): # its only happening in case of delete from front-end + raw_data = list(raw_data.keys())[0] + try: + raw_data = json.loads(raw_data) + except Exception as error: # pylint: disable=broad-except + return None, JsonResponse({'success': False, 'message': str(error)}, status=400) + try: user_data = raw_data.get('user_name', '') or raw_data.get('user_email', '') except ValueError as error: