Commit b2ebb680 by muzaffaryousaf

DRF uses query_params instead of QUERY_PARAMS.

TNL-3442
parent c486f857
...@@ -160,7 +160,7 @@ class CourseList(CourseViewMixin, ListAPIView): ...@@ -160,7 +160,7 @@ class CourseList(CourseViewMixin, ListAPIView):
serializer_class = serializers.CourseSerializer serializer_class = serializers.CourseSerializer
def get_queryset(self): def get_queryset(self):
course_ids = self.request.QUERY_PARAMS.get('course_id', None) course_ids = self.request.query_params.get('course_id', None)
results = [] results = []
if course_ids: if course_ids:
......
...@@ -383,8 +383,8 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView): ...@@ -383,8 +383,8 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView):
"""GET /api/team/v0/teams/""" """GET /api/team/v0/teams/"""
result_filter = {} result_filter = {}
if 'course_id' in request.QUERY_PARAMS: if 'course_id' in request.query_params:
course_id_string = request.QUERY_PARAMS['course_id'] course_id_string = request.query_params['course_id']
try: try:
course_key = CourseKey.from_string(course_id_string) course_key = CourseKey.from_string(course_id_string)
# Ensure the course exists # Ensure the course exists
...@@ -407,14 +407,14 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView): ...@@ -407,14 +407,14 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView):
status=status.HTTP_400_BAD_REQUEST status=status.HTTP_400_BAD_REQUEST
) )
text_search = request.QUERY_PARAMS.get('text_search', None) text_search = request.query_params.get('text_search', None)
if text_search and request.QUERY_PARAMS.get('order_by', None): if text_search and request.query_params.get('order_by', None):
return Response( return Response(
build_api_error(ugettext_noop("text_search and order_by cannot be provided together")), build_api_error(ugettext_noop("text_search and order_by cannot be provided together")),
status=status.HTTP_400_BAD_REQUEST status=status.HTTP_400_BAD_REQUEST
) )
topic_id = request.QUERY_PARAMS.get('topic_id', None) topic_id = request.query_params.get('topic_id', None)
if topic_id is not None: if topic_id is not None:
if topic_id not in [topic['id'] for topic in course_module.teams_configuration['topics']]: if topic_id not in [topic['id'] for topic in course_module.teams_configuration['topics']]:
error = build_api_error( error = build_api_error(
...@@ -457,7 +457,7 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView): ...@@ -457,7 +457,7 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView):
order_by_input = None order_by_input = None
else: else:
queryset = CourseTeam.objects.filter(**result_filter) queryset = CourseTeam.objects.filter(**result_filter)
order_by_input = request.QUERY_PARAMS.get('order_by', 'name') order_by_input = request.query_params.get('order_by', 'name')
if order_by_input == 'name': if order_by_input == 'name':
# MySQL does case-insensitive order_by. # MySQL does case-insensitive order_by.
queryset = queryset.order_by('name') queryset = queryset.order_by('name')
...@@ -553,7 +553,7 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView): ...@@ -553,7 +553,7 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView):
# This code is taken from within the GenericAPIView#paginate_queryset method. # This code is taken from within the GenericAPIView#paginate_queryset method.
# We need need access to the page outside of that method for our paginate_search_results method # We need need access to the page outside of that method for our paginate_search_results method
page_kwarg = self.kwargs.get(self.paginator.page_query_param) page_kwarg = self.kwargs.get(self.paginator.page_query_param)
page_query_param = self.request.QUERY_PARAMS.get(self.paginator.page_query_param) page_query_param = self.request.query_params.get(self.paginator.page_query_param)
return page_kwarg or page_query_param or 1 return page_kwarg or page_query_param or 1
...@@ -769,7 +769,7 @@ class TopicListView(GenericAPIView): ...@@ -769,7 +769,7 @@ class TopicListView(GenericAPIView):
def get(self, request): def get(self, request):
"""GET /api/team/v0/topics/?course_id={course_id}""" """GET /api/team/v0/topics/?course_id={course_id}"""
course_id_string = request.QUERY_PARAMS.get('course_id', None) course_id_string = request.query_params.get('course_id', None)
if course_id_string is None: if course_id_string is None:
return Response({ return Response({
'field_errors': { 'field_errors': {
...@@ -793,7 +793,7 @@ class TopicListView(GenericAPIView): ...@@ -793,7 +793,7 @@ class TopicListView(GenericAPIView):
if not has_team_api_access(request.user, course_id): if not has_team_api_access(request.user, course_id):
return Response(status=status.HTTP_403_FORBIDDEN) return Response(status=status.HTTP_403_FORBIDDEN)
ordering = request.QUERY_PARAMS.get('order_by', 'name') ordering = request.query_params.get('order_by', 'name')
if ordering not in ['name', 'team_count']: if ordering not in ['name', 'team_count']:
return Response({ return Response({
'developer_message': "unsupported order_by value {ordering}".format(ordering=ordering), 'developer_message': "unsupported order_by value {ordering}".format(ordering=ordering),
...@@ -1044,16 +1044,16 @@ class MembershipListView(ExpandableFieldViewMixin, GenericAPIView): ...@@ -1044,16 +1044,16 @@ class MembershipListView(ExpandableFieldViewMixin, GenericAPIView):
requested_course_key = None requested_course_key = None
accessible_course_ids = None accessible_course_ids = None
if 'course_id' in request.QUERY_PARAMS: if 'course_id' in request.query_params:
requested_course_id = request.QUERY_PARAMS['course_id'] requested_course_id = request.query_params['course_id']
try: try:
requested_course_key = CourseKey.from_string(requested_course_id) requested_course_key = CourseKey.from_string(requested_course_id)
except InvalidKeyError: except InvalidKeyError:
return Response(status=status.HTTP_404_NOT_FOUND) return Response(status=status.HTTP_404_NOT_FOUND)
if 'team_id' in request.QUERY_PARAMS: if 'team_id' in request.query_params:
specified_username_or_team = True specified_username_or_team = True
team_id = request.QUERY_PARAMS['team_id'] team_id = request.query_params['team_id']
try: try:
team = CourseTeam.objects.get(team_id=team_id) team = CourseTeam.objects.get(team_id=team_id)
except CourseTeam.DoesNotExist: except CourseTeam.DoesNotExist:
...@@ -1063,9 +1063,9 @@ class MembershipListView(ExpandableFieldViewMixin, GenericAPIView): ...@@ -1063,9 +1063,9 @@ class MembershipListView(ExpandableFieldViewMixin, GenericAPIView):
if not has_team_api_access(request.user, team.course_id): if not has_team_api_access(request.user, team.course_id):
return Response(status=status.HTTP_404_NOT_FOUND) return Response(status=status.HTTP_404_NOT_FOUND)
if 'username' in request.QUERY_PARAMS: if 'username' in request.query_params:
specified_username_or_team = True specified_username_or_team = True
username = request.QUERY_PARAMS['username'] username = request.query_params['username']
if not request.user.is_staff: if not request.user.is_staff:
enrolled_courses = ( enrolled_courses = (
CourseEnrollment.enrollments_for_user(request.user).values_list('course_id', flat=True) CourseEnrollment.enrollments_for_user(request.user).values_list('course_id', flat=True)
...@@ -1267,7 +1267,7 @@ class MembershipDetailView(ExpandableFieldViewMixin, GenericAPIView): ...@@ -1267,7 +1267,7 @@ class MembershipDetailView(ExpandableFieldViewMixin, GenericAPIView):
if has_team_api_access(request.user, team.course_id, access_username=username): if has_team_api_access(request.user, team.course_id, access_username=username):
membership = self.get_membership(username, team) membership = self.get_membership(username, team)
removal_method = 'self_removal' removal_method = 'self_removal'
if 'admin' in request.QUERY_PARAMS: if 'admin' in request.query_params:
removal_method = 'removed_by_admin' removal_method = 'removed_by_admin'
membership.delete() membership.delete()
emit_team_event( emit_team_event(
......
...@@ -146,7 +146,7 @@ class AccountView(APIView): ...@@ -146,7 +146,7 @@ class AccountView(APIView):
GET /api/user/v1/accounts/{username}/ GET /api/user/v1/accounts/{username}/
""" """
try: try:
account_settings = get_account_settings(request, username, view=request.QUERY_PARAMS.get('view')) account_settings = get_account_settings(request, username, view=request.query_params.get('view'))
except UserNotFound: except UserNotFound:
return Response(status=status.HTTP_403_FORBIDDEN if request.user.is_staff else status.HTTP_404_NOT_FOUND) return Response(status=status.HTTP_403_FORBIDDEN if request.user.is_staff else status.HTTP_404_NOT_FOUND)
......
...@@ -823,7 +823,7 @@ class ForumRoleUsersListView(generics.ListAPIView): ...@@ -823,7 +823,7 @@ class ForumRoleUsersListView(generics.ListAPIView):
Return a list of users with the specified role/course pair Return a list of users with the specified role/course pair
""" """
name = self.kwargs['name'] name = self.kwargs['name']
course_id_string = self.request.QUERY_PARAMS.get('course_id') course_id_string = self.request.query_params.get('course_id')
if not course_id_string: if not course_id_string:
raise ParseError('course_id must be specified') raise ParseError('course_id must be specified')
course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id_string) course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id_string)
......
...@@ -79,7 +79,7 @@ class ExpandableFieldViewMixin(object): ...@@ -79,7 +79,7 @@ class ExpandableFieldViewMixin(object):
def get_serializer_context(self): def get_serializer_context(self):
"""Adds expand information from query parameters to the serializer context to support expandable fields.""" """Adds expand information from query parameters to the serializer context to support expandable fields."""
result = super(ExpandableFieldViewMixin, self).get_serializer_context() result = super(ExpandableFieldViewMixin, self).get_serializer_context()
result['expand'] = [x for x in self.request.QUERY_PARAMS.get('expand', '').split(',') if x] result['expand'] = [x for x in self.request.query_params.get('expand', '').split(',') if x]
return result return result
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment