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

« back to all changes in this revision

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

Cache worksheet and exercise rST-generated XHTML in the DB, accelerating rendering by up to 2000%.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
50
50
from ivle.webapp.media import media_url
51
51
from ivle.webapp.errors import NotFound
52
 
from ivle.worksheet.rst import rst as rstfunc
53
52
 
54
53
from ivle.webapp.tutorial.service import (AttemptsRESTView, AttemptRESTView,
55
54
            WorksheetExerciseRESTView, WorksheetsRESTView)
87
86
        ctx['semester'] = self.context.offering.semester.semester
88
87
        ctx['year'] = self.context.offering.semester.year
89
88
 
90
 
        ctx['worksheetstream'] = genshi.Stream(list(genshi.XML(self.context.get_xml())))
 
89
        ctx['worksheetstream'] = genshi.Stream(list(genshi.XML(self.context.data_xhtml)))
91
90
        ctx['user'] = req.user
92
91
        ctx['config'] = req.config
93
92
 
237
236
    curctx['exercise'] = exercise
238
237
    curctx['description'] = None
239
238
    curctx['error'] = None
240
 
    if exercise.description is not None:
241
 
        try:
242
 
            desc = rstfunc(exercise.description)
243
 
            curctx['description'] = genshi.XML(desc)
244
 
        except docutils.utils.SystemMessage, e:
245
 
            curctx['error'] = "Error processing reStructuredText: '%s'"%str(e)
 
239
    try:
 
240
        desc_xhtml = exercise.description_xhtml
 
241
        if desc_xhtml:
 
242
            curctx['description'] = genshi.XML(desc_xhtml)
 
243
        else:
 
244
            curctx['description'] = None
 
245
    except docutils.utils.SystemMessage, e:
 
246
        curctx['error'] = "Error processing reStructuredText: '%s'" % str(e)
246
247
 
247
248
    # If the user has already saved some text for this problem, or submitted
248
249
    # an attempt, then use that text instead of the supplied "partial".
403
404
        new_worksheet.name = data['name']
404
405
        new_worksheet.assessable = data['assessable']
405
406
        new_worksheet.published = data['published']
406
 
        new_worksheet.data = data['data']
 
407
        new_worksheet.set_data(data['data'])
407
408
        new_worksheet.format = data['format']
408
409
 
409
410
        req.store.add(new_worksheet)
438
439
        self.context.name = data['name']
439
440
        self.context.assessable = data['assessable']
440
441
        self.context.published = data['published']
441
 
        self.context.data = data['data']
 
442
        self.context.set_data(data['data'])
442
443
        self.context.format = data['format']
443
444
 
444
445
        return self.context