193
193
# Just treat this as a normal HTML element
194
194
req.write(elem.toxml() + '\n')
197
"""Given an element, returns its children as XML strings concatenated
200
for child in elem.childNodes:
204
def getTextData(element):
205
""" Get the text and cdata inside an element
206
Leading and trailing whitespace are stripped
209
for child in element.childNodes:
210
if child.nodeType == child.CDATA_SECTION_NODE:
212
if child.nodeType == child.TEXT_NODE:
196
217
def present_problem(req, subject, problemsrc):
197
218
"""Open a problem file, and write out the problem to the request in HTML.
198
219
subject: Subject name.
217
238
req.write("</div>\n")
220
# TODO: Read problem file and present the problem
221
# TEMP: Print out the problem XML source
222
req.write("<p><b>Problem:</b></p>\n")
223
req.write("<pre>%s</pre>\n" % cgi.escape(problemfile.read()))
241
# Read problem file and present the problem
242
# Note: We do not use the testing framework because it does a lot more
243
# work than we need. We just need to get the problem name and a few other
244
# fields from the XML.
246
problemdom = minidom.parse(problemfile)
248
problemdom = problemdom.documentElement
249
if problemdom.tagName != "problem":
250
# TODO: Nicer error message, to help authors
251
req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR)
252
problemname = problemdom.getAttribute("name")
253
# Look for some other fields we need, which are elements:
258
for elem in problemdom.childNodes:
259
if elem.nodeType == elem.ELEMENT_NODE:
260
if elem.tagName == "desc":
261
problemdesc = innerXML(elem).strip()
262
if elem.tagName == "partial":
263
problempartial= getTextData(elem) + '\n'
265
# Print this problem out to HTML
266
req.write("<p><b>Problem:</b> %s</p>\n" % problemname)
267
if problemdesc is not None:
268
req.write("<p>%s</p>" % problemdesc)
269
req.write('<textarea class="problembox">%s</textarea>' \
224
271
req.write("</div>\n")