Commit 6c875206 by kimth

Simplify file submission front end

parent c950d437
......@@ -67,16 +67,14 @@ class @Problem
fd = new FormData()
# For each file input, allow a single file submission,
# which is routed to Django 'request.FILES'
@$('input:file').each (index, element) ->
if element.files[0] instanceof File
fd.append(element.id, element.files[0])
@$("[id^=input_#{@element_id.replace(/problem_/, '')}_]").each (index, element) ->
if element.type is 'file'
if element.files[0] instanceof File
fd.append(element.id, element.files[0])
else
fd.append(element.id, '')
else
fd.append(element.id, '') # Even if no file selected, need to include input id
# Simple (non-file) answers, which is routed to Django 'request.POST'
fd.append('__answers_querystring', @answers)
fd.append(element.id, element.value)
settings =
type: "POST"
......
import json
import logging
from urlparse import parse_qs
from django.conf import settings
from django.http import Http404
......@@ -273,22 +272,10 @@ def modx_dispatch(request, dispatch=None, id=None):
# ''' (fix emacs broken parsing)
# Check for submitted files
post = dict()
p = request.POST.copy()
if request.FILES:
for inputfile_id in request.FILES.keys():
post[inputfile_id] = request.FILES[inputfile_id]
# 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?
for key in request.POST.keys():
if key == '__answers_querystring':
qs = request.POST.get(key)
qsdict = parse_qs(qs, keep_blank_values=True)
for qskey in qsdict.keys():
post[qskey] = qsdict[qskey][0] # parse_qs returns {key: list}
else:
post[key] = request.POST.get(key)
p[inputfile_id] = request.FILES[inputfile_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)
......@@ -301,7 +288,7 @@ def modx_dispatch(request, dispatch=None, id=None):
# Let the module handle the AJAX
try:
ajax_return = instance.handle_ajax(dispatch, post)
ajax_return = instance.handle_ajax(dispatch, p)
except NotFoundError:
log.exception("Module indicating to user that request doesn't exist")
raise Http404
......
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