Commit 35a461d9 by kimth

Empty file inputs insert empty string as their submission in ajax; LMS reacts accordingly

parent ea36eef6
...@@ -65,11 +65,14 @@ class @Problem ...@@ -65,11 +65,14 @@ class @Problem
# For each file input, allow a single file submission, # For each file input, allow a single file submission,
# routed to Django 'request.FILES' # routed to Django 'request.FILES'
@$('input:file').each (index, element) -> @$('input:file').each (index, element) ->
if element.files[0] instanceof File
fd.append(element.id, element.files[0]) fd.append(element.id, element.files[0])
else
fd.append(element.id, '') # Even if no file selected, need to include input id
# Simple (non-file) answers, # Simple (non-file) answers,
# routed to Django 'request.POST' # routed to Django 'request.POST'
fd.append('_answers_querystring', @answers) fd.append('__answers_querystring', @answers)
settings = settings =
type: "POST" type: "POST"
......
...@@ -275,13 +275,22 @@ def modx_dispatch(request, dispatch=None, id=None): ...@@ -275,13 +275,22 @@ def modx_dispatch(request, dispatch=None, id=None):
post = request.POST.copy() post = request.POST.copy()
# Catch the use of FormData in xmodule frontend. After this block, the 'post' dict # Catch the use of FormData in xmodule frontend for 'problem_check'. After this block,
# is functionally equivalent before- and after- the use of FormData # the 'post' dict is functionally equivalent before- and after- the use of FormData
# TODO: A more elegant solution? # TODO: A more elegant solution?
if post.has_key('_answers_querystring'): if post.has_key('__answers_querystring'):
post = parse_qs(post.get('_answers_querystring')) qs = post.pop('__answers_querystring')[0]
for key in post.keys(): qsdict = parse_qs(qs, keep_blank_values=True)
post[key] = post[key][0] # parse_qs returns { key: list } for key in qsdict.keys():
qsdict[key] = qsdict[key][0] # parse_qs returns { key: list }
post.update(qsdict)
# Check for submitted files
if request.FILES:
print 'Got files!'
print post.keys()
print request.FILES.keys()
student_module_cache = StudentModuleCache(request.user, modulestore().get_item(id)) student_module_cache = StudentModuleCache(request.user, modulestore().get_item(id))
instance, instance_module, shared_module, module_type = get_module(request.user, request, id, student_module_cache) instance, instance_module, shared_module, module_type = get_module(request.user, request, id, student_module_cache)
......
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