~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/apps/tutorial/__init__.py

  • Committer: mattgiuca
  • Date: 2008-01-25 03:42:11 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:307
tutorial: Now each problem div has an ID. Added submit buttons which call
    JavaScript code to submit.
Added tutorial.js, which receives the submit request (currently stubbish).

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
import re
35
35
from xml.dom import minidom
36
36
 
 
37
import cjson
 
38
 
37
39
from common import util
38
40
import conf
39
41
 
193
195
    req.write("<h1>IVLE Tutorials - %s</h1>\n<h2>%s</h2>\n"
194
196
        % (cgi.escape(subject), cgi.escape(worksheetname)))
195
197
    # Write each element
 
198
    problemid = 0
196
199
    for elem in elements:
197
200
        if elem.tagName == "problem":
198
 
            present_problem(req, subject, elem.getAttribute("src"))
 
201
            present_problem(req, subject, elem.getAttribute("src"), problemid)
 
202
            problemid += 1
199
203
        else:
200
204
            # Just treat this as a normal HTML element
201
205
            req.write(elem.toxml() + '\n')
221
225
 
222
226
    return data.strip()
223
227
 
224
 
def present_problem(req, subject, problemsrc):
 
228
def present_problem(req, subject, problemsrc, problemid):
225
229
    """Open a problem file, and write out the problem to the request in HTML.
226
230
    subject: Subject name.
227
231
    problemsrc: "src" of the problem file. A path relative to the top-level
228
232
        subjects base directory, as configured in conf.
229
233
    """
230
 
    req.write('<div class="tuteproblem">\n')
 
234
    req.write('<div class="tuteproblem" id="problem%d">\n'
 
235
        % problemid)
231
236
    # First normalise the path
232
237
    problemsrc = os.path.normpath(problemsrc)
233
238
    # Now if it begins with ".." or separator, then it's illegal
272
277
    req.write("<p><b>Problem:</b> %s</p>\n" % problemname)
273
278
    if problemdesc is not None:
274
279
        req.write("<p>%s</p>" % problemdesc)
275
 
    req.write('<textarea class="problembox">%s</textarea>' \
 
280
    req.write('<textarea class="problembox" cols="80" rows="12">%s</textarea>'
276
281
            % problempartial)
 
282
    req.write("""<div class="problembuttons">
 
283
  <input type="button" value="Submit"
 
284
    onclick="submitproblem(&quot;problem%d&quot;, %s)" />
 
285
</div>
 
286
""" % (problemid, cgi.escape(cjson.encode(problemsrc), quote=True)))
277
287
    req.write("</div>\n")