Skip to content

Commit

Permalink
feat: upgrading simple api to drf compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
awais786 committed Aug 15, 2024
1 parent c3853ec commit 2473305
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
10 changes: 5 additions & 5 deletions lms/djangoapps/instructor/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,13 @@ def _access_endpoint(self, endpoint, args, status_code, msg, content_type=MULTIP
"""

url = reverse(endpoint, kwargs={'course_id': str(self.course.id)})
# if endpoint in INSTRUCTOR_GET_ENDPOINTS:
# response = self.client.get(url, args)
# else:
if endpoint in INSTRUCTOR_GET_ENDPOINTS:
response = self.client.get(url, args)
else:
# if endpoint not in ['get_students_features', 'get_students_who_may_enroll']:
response = self.client.post(url, args, content_type=content_type)
response = self.client.post(url, args, content_type=content_type)

# assert response.status_code == status_code, msg
assert response.status_code == status_code, msg

def test_student_level(self):
"""
Expand Down
17 changes: 8 additions & 9 deletions lms/djangoapps/instructor/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1523,17 +1523,16 @@ def post(self, request, course_id):
Responds with JSON
{"status": "... status message ..."}
"""
import pdb;
pdb.set_trace()
# course_key = CourseKey.from_string(course_id)
# query_features = ['email']
# report_type = _('enrollment')
# # task_api.submit_calculate_may_enroll_csv(request, course_key, query_features)
# success_status = SUCCESS_MESSAGE_TEMPLATE.format(report_type=report_type)
course_key = CourseKey.from_string(course_id)
query_features = ['email']
report_type = _('enrollment')
task_api.submit_calculate_may_enroll_csv(request, course_key, query_features)
success_status = SUCCESS_MESSAGE_TEMPLATE.format(report_type=report_type)

return JsonResponse({"status": success_status})

return Response({"status": 200})

def get(self, request, *args, **kwargs):
def get(self, request, *args, **kwargs):
"""
Handle GET requests to return a 400 Bad Request status code.
Expand Down
9 changes: 2 additions & 7 deletions openedx/core/djangoapps/user_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,8 @@ def get_value(cls, user, preference_key, default=None):
The user preference value, or default if one is not set.
"""
try:
import pdb;
pdb.set_trace()
user_preference, __ = cls.objects.get_or_create(user=user, key='pref-lang', value='en')
if user_preference:
return user_preference.value
user_preference, __ = cls.objects.get_or_create(user=user, key='pref-lang', value='en')
return user_preference
user_preference = cls.objects.get(user=user, key=preference_key)
return user_preference.value
except cls.DoesNotExist:
return default

Expand Down
2 changes: 0 additions & 2 deletions openedx/core/djangoapps/user_api/preferences/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ def get_user_preference(requesting_user, preference_key, username=None):
UserNotAuthorized: the requesting_user does not have access to the user preference.
UserAPIInternalError: the operation failed due to an unexpected error.
"""
import pdb;
pdb.set_trace()
existing_user = _get_authorized_user(requesting_user, username, allow_staff=True)
return UserPreference.get_value(existing_user, preference_key)

Expand Down

0 comments on commit 2473305

Please sign in to comment.