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
# For each file input, allow a single file submission,
# routed to Django 'request.FILES'
@$('input:file').each (index, element) ->
fd.append(element.id, element.files[0])
if element.files[0] instanceof File
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,
# routed to Django 'request.POST'
fd.append('_answers_querystring', @answers)
fd.append('__answers_querystring', @answers)
settings =
type: "POST"
......
......@@ -275,13 +275,22 @@ def modx_dispatch(request, dispatch=None, id=None):
post = request.POST.copy()
# Catch the use of FormData in xmodule frontend. After this block, the 'post' dict
# is functionally equivalent before- and after- the use of FormData
# Catch the use of FormData in xmodule frontend for 'problem_check'. After this block,
# the 'post' dict is functionally equivalent before- and after- the use of FormData
# TODO: A more elegant solution?
if post.has_key('_answers_querystring'):
post = parse_qs(post.get('_answers_querystring'))
for key in post.keys():
post[key] = post[key][0] # parse_qs returns { key: list }
if post.has_key('__answers_querystring'):
qs = post.pop('__answers_querystring')[0]
qsdict = parse_qs(qs, keep_blank_values=True)
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))
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