22
22
# Provides the AJAX backend for the tutorial application.
23
# Not yet implemented.
23
# This allows several actions to be performed on the code the student has
24
# typed into one of the problem boxes.
27
# The "path" to this app is the path to a problem file (including the .xml
28
# extension), relative to the subjects base directory.
29
# The arguments determine what is to be done on this file.
31
# "code" - Full text of the student's code being submitted.
32
# "action". May be "test". (More to come).
34
# Returns a JSON response string indicating the results.
39
"""Handler for Ajax backend TutorialService app."""
40
# Set request attributes
41
req.write_html_head_foot = False # No HTML
43
# Get all the arguments, if POST.
44
# Ignore arguments if not POST, since we aren't allowed to cause
45
# side-effects on the server.
46
fields = req.get_fieldstorage()
47
act = fields.getfirst('action')
48
code = fields.getfirst('code')
50
if code == None or act == None:
51
req.throw_error(req.HTTP_BAD_REQUEST)
56
handle_test(req, code, fields)
58
req.throw_error(req.HTTP_BAD_REQUEST)
60
def handle_test(req, code, fields):
61
"""Handles a test action."""
62
# TEMP: Just echo the code back in JSON form
63
req.write(cjson.encode({"code": code}))