Commit e3ddb02c by John Eskew

Merge pull request #11586 from edx/jeskew/remove_all_request_dot_request

Remove all request.REQUEST usages.
parents db5fe130 df261cd5
...@@ -61,7 +61,7 @@ def assets_handler(request, course_key_string=None, asset_key_string=None): ...@@ -61,7 +61,7 @@ def assets_handler(request, course_key_string=None, asset_key_string=None):
if not has_course_author_access(request.user, course_key): if not has_course_author_access(request.user, course_key):
raise PermissionDenied() raise PermissionDenied()
response_format = request.REQUEST.get('format', 'html') response_format = request.GET.get('format') or request.POST.get('format') or 'html'
if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'): if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'):
if request.method == 'GET': if request.method == 'GET':
return _assets_json(request, course_key) return _assets_json(request, course_key)
...@@ -97,10 +97,10 @@ def _assets_json(request, course_key): ...@@ -97,10 +97,10 @@ def _assets_json(request, course_key):
Supports start (0-based index into the list of assets) and max query parameters. Supports start (0-based index into the list of assets) and max query parameters.
""" """
requested_page = int(request.REQUEST.get('page', 0)) requested_page = int(request.GET.get('page', 0))
requested_page_size = int(request.REQUEST.get('page_size', 50)) requested_page_size = int(request.GET.get('page_size', 50))
requested_sort = request.REQUEST.get('sort', 'date_added') requested_sort = request.GET.get('sort', 'date_added')
requested_filter = request.REQUEST.get('asset_type', '') requested_filter = request.GET.get('asset_type', '')
requested_file_types = settings.FILES_AND_UPLOAD_TYPE_FILTERS.get( requested_file_types = settings.FILES_AND_UPLOAD_TYPE_FILTERS.get(
requested_filter, None) requested_filter, None)
filter_params = None filter_params = None
...@@ -124,7 +124,7 @@ def _assets_json(request, course_key): ...@@ -124,7 +124,7 @@ def _assets_json(request, course_key):
} }
sort_direction = DESCENDING sort_direction = DESCENDING
if request.REQUEST.get('direction', '').lower() == 'asc': if request.GET.get('direction', '').lower() == 'asc':
sort_direction = ASCENDING sort_direction = ASCENDING
# Convert the field name to the Mongo name # Convert the field name to the Mongo name
......
...@@ -96,7 +96,7 @@ def container_handler(request, usage_key_string): ...@@ -96,7 +96,7 @@ def container_handler(request, usage_key_string):
component_templates = get_component_templates(course) component_templates = get_component_templates(course)
ancestor_xblocks = [] ancestor_xblocks = []
parent = get_parent_xblock(xblock) parent = get_parent_xblock(xblock)
action = request.REQUEST.get('action', 'view') action = request.GET.get('action', 'view')
is_unit_page = is_unit(xblock) is_unit_page = is_unit(xblock)
unit = xblock if is_unit_page else None unit = xblock if is_unit_page else None
......
...@@ -164,7 +164,7 @@ def course_notifications_handler(request, course_key_string=None, action_state_i ...@@ -164,7 +164,7 @@ def course_notifications_handler(request, course_key_string=None, action_state_i
if not course_key_string or not action_state_id: if not course_key_string or not action_state_id:
return HttpResponseBadRequest() return HttpResponseBadRequest()
response_format = request.REQUEST.get('format', 'html') response_format = request.GET.get('format') or request.POST.get('format') or 'html'
course_key = CourseKey.from_string(course_key_string) course_key = CourseKey.from_string(course_key_string)
...@@ -250,7 +250,7 @@ def course_handler(request, course_key_string=None): ...@@ -250,7 +250,7 @@ def course_handler(request, course_key_string=None):
json: delete this branch from this course (leaving off /branch/draft would imply delete the course) json: delete this branch from this course (leaving off /branch/draft would imply delete the course)
""" """
try: try:
response_format = request.REQUEST.get('format', 'html') response_format = request.GET.get('format') or request.POST.get('format') or 'html'
if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'): if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'):
if request.method == 'GET': if request.method == 'GET':
course_key = CourseKey.from_string(course_key_string) course_key = CourseKey.from_string(course_key_string)
...@@ -582,7 +582,7 @@ def course_index(request, course_key): ...@@ -582,7 +582,7 @@ def course_index(request, course_key):
reindex_link = "/course/{course_id}/search_reindex".format(course_id=unicode(course_key)) reindex_link = "/course/{course_id}/search_reindex".format(course_id=unicode(course_key))
sections = course_module.get_children() sections = course_module.get_children()
course_structure = _course_outline_json(request, course_module) course_structure = _course_outline_json(request, course_module)
locator_to_show = request.REQUEST.get('show', None) locator_to_show = request.GET.get('show', None)
course_release_date = get_default_time_display(course_module.start) if course_module.start != DEFAULT_START_DATE else _("Unscheduled") course_release_date = get_default_time_display(course_module.start) if course_module.start != DEFAULT_START_DATE else _("Unscheduled")
settings_url = reverse_course_url('settings_handler', course_key) settings_url = reverse_course_url('settings_handler', course_key)
......
...@@ -83,7 +83,7 @@ def entrance_exam(request, course_key_string): ...@@ -83,7 +83,7 @@ def entrance_exam(request, course_key_string):
# Create a new entrance exam for the specified course (returns 201 if created) # Create a new entrance exam for the specified course (returns 201 if created)
elif request.method == 'POST': elif request.method == 'POST':
response_format = request.REQUEST.get('format', 'html') response_format = request.POST.get('format', 'html')
http_accept = request.META.get('http_accept') http_accept = request.META.get('http_accept')
if response_format == 'json' or 'application/json' in http_accept: if response_format == 'json' or 'application/json' in http_accept:
ee_min_score = request.POST.get('entrance_exam_minimum_score_pct', None) ee_min_score = request.POST.get('entrance_exam_minimum_score_pct', None)
......
...@@ -498,7 +498,7 @@ def export_handler(request, course_key_string): ...@@ -498,7 +498,7 @@ def export_handler(request, course_key_string):
context['export_url'] = export_url + '?_accept=application/x-tgz' context['export_url'] = export_url + '?_accept=application/x-tgz'
# an _accept URL parameter will be preferred over HTTP_ACCEPT in the header. # an _accept URL parameter will be preferred over HTTP_ACCEPT in the header.
requested_format = request.REQUEST.get('_accept', request.META.get('HTTP_ACCEPT', 'text/html')) requested_format = request.GET.get('_accept', request.META.get('HTTP_ACCEPT', 'text/html'))
if 'application/x-tgz' in requested_format: if 'application/x-tgz' in requested_format:
try: try:
......
...@@ -140,7 +140,7 @@ def xblock_handler(request, usage_key_string): ...@@ -140,7 +140,7 @@ def xblock_handler(request, usage_key_string):
accept_header = request.META.get('HTTP_ACCEPT', 'application/json') accept_header = request.META.get('HTTP_ACCEPT', 'application/json')
if 'application/json' in accept_header: if 'application/json' in accept_header:
fields = request.REQUEST.get('fields', '').split(',') fields = request.GET.get('fields', '').split(',')
if 'graderType' in fields: if 'graderType' in fields:
# right now can't combine output of this w/ output of _get_module_info, but worthy goal # right now can't combine output of this w/ output of _get_module_info, but worthy goal
return JsonResponse(CourseGradingModel.get_section_grader_type(usage_key)) return JsonResponse(CourseGradingModel.get_section_grader_type(usage_key))
...@@ -254,24 +254,24 @@ def xblock_view_handler(request, usage_key_string, view_name): ...@@ -254,24 +254,24 @@ def xblock_view_handler(request, usage_key_string, view_name):
paging = None paging = None
try: try:
if request.REQUEST.get('enable_paging', 'false') == 'true': if request.GET.get('enable_paging', 'false') == 'true':
paging = { paging = {
'page_number': int(request.REQUEST.get('page_number', 0)), 'page_number': int(request.GET.get('page_number', 0)),
'page_size': int(request.REQUEST.get('page_size', 0)), 'page_size': int(request.GET.get('page_size', 0)),
} }
except ValueError: except ValueError:
return HttpResponse( return HttpResponse(
content="Couldn't parse paging parameters: enable_paging: " content="Couldn't parse paging parameters: enable_paging: "
"{0}, page_number: {1}, page_size: {2}".format( "{0}, page_number: {1}, page_size: {2}".format(
request.REQUEST.get('enable_paging', 'false'), request.GET.get('enable_paging', 'false'),
request.REQUEST.get('page_number', 0), request.GET.get('page_number', 0),
request.REQUEST.get('page_size', 0) request.GET.get('page_size', 0)
), ),
status=400, status=400,
content_type="text/plain", content_type="text/plain",
) )
force_render = request.REQUEST.get('force_render', None) force_render = request.GET.get('force_render', None)
# Set up the context to be passed to each XBlock's render method. # Set up the context to be passed to each XBlock's render method.
context = { context = {
...@@ -325,7 +325,7 @@ def xblock_outline_handler(request, usage_key_string): ...@@ -325,7 +325,7 @@ def xblock_outline_handler(request, usage_key_string):
if not has_studio_read_access(request.user, usage_key.course_key): if not has_studio_read_access(request.user, usage_key.course_key):
raise PermissionDenied() raise PermissionDenied()
response_format = request.REQUEST.get('format', 'html') response_format = request.GET.get('format', 'html')
if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'): if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'):
store = modulestore() store = modulestore()
with store.bulk_operations(usage_key.course_key): with store.bulk_operations(usage_key.course_key):
...@@ -354,7 +354,7 @@ def xblock_container_handler(request, usage_key_string): ...@@ -354,7 +354,7 @@ def xblock_container_handler(request, usage_key_string):
if not has_studio_read_access(request.user, usage_key.course_key): if not has_studio_read_access(request.user, usage_key.course_key):
raise PermissionDenied() raise PermissionDenied()
response_format = request.REQUEST.get('format', 'html') response_format = request.GET.get('format', 'html')
if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'): if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'):
with modulestore().bulk_operations(usage_key.course_key): with modulestore().bulk_operations(usage_key.course_key):
response = _get_module_info( response = _get_module_info(
......
...@@ -86,7 +86,7 @@ def _display_library(library_key_string, request): ...@@ -86,7 +86,7 @@ def _display_library(library_key_string, request):
response_format = 'html' response_format = 'html'
if ( if (
request.REQUEST.get('format', 'html') == 'json' or request.GET.get('format', 'html') == 'json' or
'application/json' in request.META.get('HTTP_ACCEPT', 'text/html') 'application/json' in request.META.get('HTTP_ACCEPT', 'text/html')
): ):
response_format = 'json' response_format = 'json'
......
...@@ -756,7 +756,10 @@ def provider_login(request): ...@@ -756,7 +756,10 @@ def provider_login(request):
# first check to see if the request is an OpenID request. # first check to see if the request is an OpenID request.
# If so, the client will have specified an 'openid.mode' as part # If so, the client will have specified an 'openid.mode' as part
# of the request. # of the request.
querydict = dict(request.REQUEST.items()) if request.method == 'GET':
querydict = dict(request.GET.items())
else:
querydict = dict(request.POST.items())
error = False error = False
if 'openid.mode' in request.GET or 'openid.mode' in request.POST: if 'openid.mode' in request.GET or 'openid.mode' in request.POST:
# decode request # decode request
...@@ -899,9 +902,8 @@ def provider_login(request): ...@@ -899,9 +902,8 @@ def provider_login(request):
return HttpResponseRedirect(openid_request_url) return HttpResponseRedirect(openid_request_url)
# determine consumer domain if applicable # determine consumer domain if applicable
return_to = '' return_to = request.GET.get('openid.return_to') or request.POST.get('openid.return_to') or ''
if 'openid.return_to' in request.REQUEST: if return_to:
return_to = request.REQUEST['openid.return_to']
matches = re.match(r'\w+:\/\/([\w\.-]+)', return_to) matches = re.match(r'\w+:\/\/([\w\.-]+)', return_to)
return_to = matches.group(1) return_to = matches.group(1)
......
...@@ -176,7 +176,7 @@ class InstructorTaskCourseTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase) ...@@ -176,7 +176,7 @@ class InstructorTaskCourseTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase)
def get_task_status(task_id): def get_task_status(task_id):
"""Use api method to fetch task status, using mock request.""" """Use api method to fetch task status, using mock request."""
mock_request = Mock() mock_request = Mock()
mock_request.REQUEST = {'task_id': task_id} mock_request.GET = mock_request.POST = {'task_id': task_id}
response = instructor_task_status(mock_request) response = instructor_task_status(mock_request)
status = json.loads(response.content) status = json.loads(response.content)
return status return status
......
...@@ -7,7 +7,7 @@ from celery.states import SUCCESS, FAILURE, REVOKED, PENDING ...@@ -7,7 +7,7 @@ from celery.states import SUCCESS, FAILURE, REVOKED, PENDING
from mock import Mock, patch from mock import Mock, patch
from django.utils.datastructures import MultiValueDict from django.http import QueryDict
from instructor_task.models import PROGRESS from instructor_task.models import PROGRESS
from instructor_task.tests.test_base import (InstructorTaskTestCase, from instructor_task.tests.test_base import (InstructorTaskTestCase,
...@@ -24,14 +24,14 @@ class InstructorTaskReportTest(InstructorTaskTestCase): ...@@ -24,14 +24,14 @@ class InstructorTaskReportTest(InstructorTaskTestCase):
def _get_instructor_task_status(self, task_id): def _get_instructor_task_status(self, task_id):
"""Returns status corresponding to task_id via api method.""" """Returns status corresponding to task_id via api method."""
request = Mock() request = Mock()
request.REQUEST = {'task_id': task_id} request.GET = request.POST = {'task_id': task_id}
return instructor_task_status(request) return instructor_task_status(request)
def test_instructor_task_status(self): def test_instructor_task_status(self):
instructor_task = self._create_failure_entry() instructor_task = self._create_failure_entry()
task_id = instructor_task.task_id task_id = instructor_task.task_id
request = Mock() request = Mock()
request.REQUEST = {'task_id': task_id} request.GET = request.POST = {'task_id': task_id}
response = instructor_task_status(request) response = instructor_task_status(request)
output = json.loads(response.content) output = json.loads(response.content)
self.assertEquals(output['task_id'], task_id) self.assertEquals(output['task_id'], task_id)
...@@ -39,7 +39,7 @@ class InstructorTaskReportTest(InstructorTaskTestCase): ...@@ -39,7 +39,7 @@ class InstructorTaskReportTest(InstructorTaskTestCase):
def test_missing_instructor_task_status(self): def test_missing_instructor_task_status(self):
task_id = "missing_id" task_id = "missing_id"
request = Mock() request = Mock()
request.REQUEST = {'task_id': task_id} request.GET = request.POST = {'task_id': task_id}
response = instructor_task_status(request) response = instructor_task_status(request)
output = json.loads(response.content) output = json.loads(response.content)
self.assertEquals(output, {}) self.assertEquals(output, {})
...@@ -50,7 +50,9 @@ class InstructorTaskReportTest(InstructorTaskTestCase): ...@@ -50,7 +50,9 @@ class InstructorTaskReportTest(InstructorTaskTestCase):
# list data, so the key value has "[]" appended to it. # list data, so the key value has "[]" appended to it.
task_ids = [(self._create_failure_entry()).task_id for _ in range(1, 5)] task_ids = [(self._create_failure_entry()).task_id for _ in range(1, 5)]
request = Mock() request = Mock()
request.REQUEST = MultiValueDict({'task_ids[]': task_ids}) task_ids_query_dict = QueryDict(mutable=True)
task_ids_query_dict.update({'task_ids[]': task_ids})
request.GET = request.POST = task_ids_query_dict
response = instructor_task_status(request) response = instructor_task_status(request)
output = json.loads(response.content) output = json.loads(response.content)
self.assertEquals(len(output), len(task_ids)) self.assertEquals(len(output), len(task_ids))
......
...@@ -76,11 +76,11 @@ def instructor_task_status(request): ...@@ -76,11 +76,11 @@ def instructor_task_status(request):
""" """
output = {} output = {}
if 'task_id' in request.REQUEST: task_id = request.GET.get('task_id') or request.POST.get('task_id')
task_id = request.REQUEST['task_id'] tasks = request.GET.get('task_ids[]') or request.POST.get('task_ids[]')
if task_id:
output = _get_instructor_task_status(task_id) output = _get_instructor_task_status(task_id)
elif 'task_ids[]' in request.REQUEST: elif tasks:
tasks = request.REQUEST.getlist('task_ids[]')
for task_id in tasks: for task_id in tasks:
task_output = _get_instructor_task_status(task_id) task_output = _get_instructor_task_status(task_id)
if task_output is not None: if task_output is not None:
......
...@@ -217,7 +217,7 @@ def remove_item(request): ...@@ -217,7 +217,7 @@ def remove_item(request):
""" """
This will remove an item from the user cart and also delete the corresponding coupon codes redemption. This will remove an item from the user cart and also delete the corresponding coupon codes redemption.
""" """
item_id = request.REQUEST.get('id', '-1') item_id = request.GET.get('id') or request.POST.get('id') or '-1'
items = OrderItem.objects.filter(id=item_id, status='cart').select_subclasses() items = OrderItem.objects.filter(id=item_id, status='cart').select_subclasses()
......
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