Filesubmission frontend
This commit is contained in:
@@ -39,7 +39,7 @@ import responsetypes
|
||||
# dict of tagname, Response Class -- this should come from auto-registering
|
||||
response_tag_dict = dict([(x.response_tag, x) for x in responsetypes.__all__])
|
||||
|
||||
entry_types = ['textline', 'schematic', 'textbox', 'imageinput', 'optioninput', 'choicegroup', 'radiogroup', 'checkboxgroup']
|
||||
entry_types = ['textline', 'schematic', 'textbox', 'imageinput', 'optioninput', 'choicegroup', 'radiogroup', 'checkboxgroup', 'filesubmission']
|
||||
solution_types = ['solution'] # extra things displayed after "show answers" is pressed
|
||||
response_properties = ["responseparam", "answer"] # these get captured as student responses
|
||||
|
||||
|
||||
@@ -299,6 +299,19 @@ def textline_dynamath(element, value, status, render_template, msg=''):
|
||||
return etree.XML(html)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
@register_render_function
|
||||
def filesubmission(element, value, status, render_template, msg=''):
|
||||
'''
|
||||
Upload a single file (e.g. for programming assignments)
|
||||
'''
|
||||
eid = element.get('id')
|
||||
|
||||
context = {'id': eid, }
|
||||
html = render_template("filesubmission.html", context)
|
||||
return etree.XML(html)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
## TODO: Make a wrapper for <codeinput>
|
||||
@register_render_function
|
||||
|
||||
@@ -805,7 +805,7 @@ class CodeResponse(LoncapaResponse):
|
||||
'''
|
||||
|
||||
response_tag = 'coderesponse'
|
||||
allowed_inputfields = ['textline', 'textbox']
|
||||
allowed_inputfields = ['textbox', 'filesubmission']
|
||||
max_inputfields = 1
|
||||
|
||||
def setup_response(self):
|
||||
|
||||
3
common/lib/capa/capa/templates/filesubmission.html
Normal file
3
common/lib/capa/capa/templates/filesubmission.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<section id="filesubmission_${id}" class="filesubmission">
|
||||
<input type="file" name="input_${id}" id="input_${id}" /><br />
|
||||
</section>
|
||||
@@ -13,7 +13,7 @@ class @Problem
|
||||
MathJax.Hub.Queue ["Typeset", MathJax.Hub]
|
||||
window.update_schematics()
|
||||
@$('section.action input:button').click @refreshAnswers
|
||||
@$('section.action input.check').click @check
|
||||
@$('section.action input.check').click @check_fd
|
||||
@$('section.action input.reset').click @reset
|
||||
@$('section.action input.show').click @show
|
||||
@$('section.action input.save').click @save
|
||||
@@ -45,6 +45,38 @@ class @Problem
|
||||
$('head')[0].appendChild(s[0])
|
||||
$(placeholder).remove()
|
||||
|
||||
check_fd: =>
|
||||
Logger.log 'problem_check', @answers
|
||||
|
||||
if not window.FormData
|
||||
alert "Sorry, your browser does not support file uploads. If you can, please use Chrome or Safari which have been verified to support this feature."
|
||||
return
|
||||
|
||||
fd = new FormData()
|
||||
|
||||
# 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])
|
||||
|
||||
# Simple (non-file) answers,
|
||||
# routed to Django 'request.POST'
|
||||
fd.append('answers', @answers)
|
||||
|
||||
settings =
|
||||
type: "POST"
|
||||
data: fd
|
||||
processData: false
|
||||
contentType: false
|
||||
success: (response) ->
|
||||
switch response.success
|
||||
when 'incorrect', 'correct'
|
||||
@render(response.contents)
|
||||
@updateProgress response
|
||||
else
|
||||
alert(response.success)
|
||||
$.ajaxWithPrefix("#{@url}/problem_check", settings)
|
||||
|
||||
check: =>
|
||||
Logger.log 'problem_check', @answers
|
||||
$.postWithPrefix "#{@url}/problem_check", @answers, (response) =>
|
||||
|
||||
@@ -270,6 +270,16 @@ def modx_dispatch(request, dispatch=None, id=None):
|
||||
- id -- the module id. Used to look up the XModule instance
|
||||
'''
|
||||
# ''' (fix emacs broken parsing)
|
||||
|
||||
print ' THK: module_render.modx_dispatch'
|
||||
print dispatch
|
||||
print request.POST.keys()
|
||||
print request.FILES.keys()
|
||||
if request.POST.has_key('answers'):
|
||||
print request.POST['answers']
|
||||
for filename in request.FILES.keys():
|
||||
uploadedFile = request.FILES.get(filename)
|
||||
print uploadedFile.read()
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user