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

« back to all changes in this revision

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

  • Committer: Matt Giuca
  • Date: 2009-01-19 16:03:36 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: matt.giuca@gmail.com-20090119160336-28ob0uev0hnikec3
Added new module: ivle.worksheet. This will contain general functions for
    worksheets (particularly for interacting with the DB), which don't belong
    in either tutorial or tutorialservice.
    worksheet now has get_exercise_status, which is a Storm re-implementation
    of ivle.db.get_problem_status. Much cleaner!
tutorial, tutorialservice: Now use ivle.worksheet.get_exercise_status rather
    than ivle.db.get_problem_status.
ivle.db: Renamed get_problem_status to _get_problem_status. Still required,
    but only used internally now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
import ivle.conf
44
44
import ivle.db
45
45
import ivle.database
 
46
import ivle.worksheet
46
47
 
47
48
from rst import rst
48
49
 
362
363
<h2>Worksheet Contents</h2>
363
364
<ul>
364
365
""")
365
 
    db = ivle.db.DB()
366
 
    try:
367
 
        for tag, xml in find_all_nodes(req, node):
368
 
            if tag == "ex":
369
 
                # Exercise node
370
 
                # Fragment ID is an accumulating exerciseid
371
 
                # (The same algorithm is employed when presenting exercises)
372
 
                fragment_id = "exercise%d" % exerciseid
373
 
                exerciseid += 1
374
 
                exercisesrc = xml.getAttribute("src")
375
 
                # Optionality: Defaults to False
376
 
                exerciseoptional = xml.getAttribute("optional") == "true"
377
 
                # Record the name and optionality for returning in the list
378
 
                exercise_list.append((exercisesrc, exerciseoptional))
379
 
                # TODO: Get proper exercise title
380
 
                title = exercisesrc
381
 
                # Get the completion status of this exercise
382
 
                complete, _ = db.get_problem_status(req.user.login,
383
 
                    exercisesrc)
384
 
                req.write('  <li class="%s" id="toc_li_%s"><a href="#%s">%s'
385
 
                    '</a></li>\n'
386
 
                    % ("complete" if complete else "incomplete",
387
 
                        fragment_id, fragment_id, cgi.escape(title)))
388
 
            else:
389
 
                # Heading node
390
 
                fragment_id = getID(xml)
391
 
                title = getTextData(xml)
392
 
                req.write('  <li><a href="#%s">%s</a></li>\n'
393
 
                    % (fragment_id, cgi.escape(title)))
394
 
    finally:
395
 
        db.close()
 
366
    for tag, xml in find_all_nodes(req, node):
 
367
        if tag == "ex":
 
368
            # Exercise node
 
369
            # Fragment ID is an accumulating exerciseid
 
370
            # (The same algorithm is employed when presenting exercises)
 
371
            fragment_id = "exercise%d" % exerciseid
 
372
            exerciseid += 1
 
373
            exercisesrc = xml.getAttribute("src")
 
374
            # Optionality: Defaults to False
 
375
            exerciseoptional = xml.getAttribute("optional") == "true"
 
376
            # Record the name and optionality for returning in the list
 
377
            exercise_list.append((exercisesrc, exerciseoptional))
 
378
            # TODO: Get proper exercise title
 
379
            title = exercisesrc
 
380
            # Get the completion status of this exercise
 
381
            exercise = ivle.database.Exercise.get_by_name(req.store,
 
382
                            exercisesrc)
 
383
            complete, _ = ivle.worksheet.get_exercise_status(req.store,
 
384
                            req.user, exercise)
 
385
            req.write('  <li class="%s" id="toc_li_%s"><a href="#%s">%s'
 
386
                '</a></li>\n'
 
387
                % ("complete" if complete else "incomplete",
 
388
                    fragment_id, fragment_id, cgi.escape(title)))
 
389
        else:
 
390
            # Heading node
 
391
            fragment_id = getID(xml)
 
392
            title = getTextData(xml)
 
393
            req.write('  <li><a href="#%s">%s</a></li>\n'
 
394
                % (fragment_id, cgi.escape(title)))
396
395
    req.write('</ul>\n</div>\n')
397
396
    return exercise_list
398
397
 
492
491
    """
493
492
    req.write('<div class="exercise" id="exercise%d">\n'
494
493
        % exerciseid)
 
494
    exercise = ivle.database.Exercise.get_by_name(req.store, exercisesrc)
495
495
    exercisefile = util.open_exercise_file(exercisesrc)
496
496
    if exercisefile is None:
497
497
        req.write("<p><b>Server Error</b>: "
534
534
    try:
535
535
        saved_text = db.get_problem_stored_text(login=req.user.login,
536
536
            exercisename=exercisesrc)
537
 
        # Also get the number of attempts taken and whether this is complete.
538
 
        complete, attempts = db.get_problem_status(login=req.user.login,
539
 
            exercisename=exercisesrc)
540
537
    finally:
541
538
        db.close()
 
539
    # Also get the number of attempts taken and whether this is complete.
 
540
    complete, attempts = ivle.worksheet.get_exercise_status(req.store,
 
541
        req.user, exercise)
542
542
    if saved_text is not None:
543
543
        # Important: We got the string from the DB encoded in UTF-8
544
544
        # Make it a unicode string.