~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-03-15 07:51:53 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:702
tutorial:
    Now calls util.open_exercise_file, instead of opening it itself.
    Calls DB.get_problem_stored_text to get the last text the user had saved
    or submitted. This means that reloading the page will now recover your
    stored text.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
from common import util
41
41
import conf
42
42
import plugins.console
 
43
import common.db
43
44
 
44
45
from rst import rst
45
46
 
305
306
    """
306
307
    req.write('<div class="exercise" id="exercise%d">\n'
307
308
        % exerciseid)
308
 
    # First normalise the path
309
 
    exercisesrc = os.path.normpath(exercisesrc)
310
 
    # Now if it begins with ".." or separator, then it's illegal
311
 
    if exercisesrc.startswith("..") or exercisesrc.startswith('/'):
312
 
        exercisefile = None
313
 
    else:
314
 
        exercisefile = os.path.join(conf.exercises_base, exercisesrc)
315
 
 
316
 
    try:
317
 
        exercisefile = open(exercisefile)
318
 
    except (TypeError, IOError):    # TypeError if exercisefile == None
 
309
    exercisefile = util.open_exercise_file(exercisesrc)
 
310
    if exercisefile is None:
319
311
        req.write("<p><b>Server Error</b>: "
320
312
            + "Exercise file could not be opened.</p>\n")
321
313
        req.write("</div>\n")
348
340
            if elem.tagName == "partial":
349
341
                exercisepartial= getTextData(elem) + '\n'
350
342
 
 
343
    # If the user has already saved some text for this problem, or submitted
 
344
    # an attempt, then use that text instead of the supplied "partial".
 
345
    saved_text = None
 
346
    db = common.db.DB()
 
347
    try:
 
348
        saved_text = db.get_problem_stored_text(login=req.user.login,
 
349
            exercisename=exercisesrc)
 
350
    finally:
 
351
        db.close()
 
352
    if saved_text is not None:
 
353
        exercisepartial = saved_text
 
354
 
351
355
    # Print this exercise out to HTML 
352
356
    req.write("<p><b>Exercise:</b> %s</p>\n" % exercisename)
353
357
    if exercisedesc is not None: