Commit 6c875206 by kimth

Simplify file submission front end

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