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

« back to all changes in this revision

Viewing changes to ivle/webapp/tutorial/__init__.py

  • Committer: David Coles
  • Date: 2010-02-23 09:28:32 UTC
  • Revision ID: coles.david@gmail.com-20100223092832-5jsmysvrmdensnhg
exercises: Show error for bad reStructuredText rather than crashing

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
import genshi
36
36
import genshi.input
37
37
from genshi.filters import HTMLFormFiller
 
38
import docutils.utils
38
39
 
39
40
import ivle.database
40
41
from ivle.database import Subject, Offering, Semester, Exercise, \
227
228
    # fields from the XML.
228
229
 
229
230
    curctx['exercise'] = exercise
 
231
    curctx['description'] = None
 
232
    curctx['error'] = None
230
233
    if exercise.description is not None:
231
 
        desc = rstfunc(exercise.description)
232
 
        curctx['description'] = genshi.XML('<div id="description">' + desc + 
233
 
                                           '</div>')
234
 
    else:
235
 
        curctx['description'] = None
 
234
        try:
 
235
            desc = rstfunc(exercise.description)
 
236
            curctx['description'] = genshi.XML(desc)
 
237
        except docutils.utils.SystemMessage, e:
 
238
            curctx['error'] = "Error processing reStructuredText: '%s'"%str(e)
236
239
 
237
240
    # If the user has already saved some text for this problem, or submitted
238
241
    # an attempt, then use that text instead of the supplied "partial".