~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 04:57:52 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: matt.giuca@gmail.com-20090119045752-3hbb1yego8ynrqmu
ivle.database: Added Worksheet.get_by_name method.
tutorial: Replaced calls to get_worksheet_mtime with Worksheet.get_by_name.
    Also replaced all usage of the time module with datetime (so as to be
    compatible with Storm).
ivle.db: Removed get_worksheet_mtime.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
import os
32
32
import os.path
33
 
import time
 
33
import datetime
34
34
import cgi
35
35
import urllib
36
36
import re
304
304
    except:
305
305
        req.throw_error(req.HTTP_NOT_FOUND,
306
306
            "Worksheet file not found.")
307
 
    worksheetmtime = time.localtime(worksheetmtime)
 
307
    worksheetmtime = datetime.datetime.fromtimestamp(worksheetmtime)
308
308
 
309
309
    worksheetdom = minidom.parse(worksheetfile)
310
310
    worksheetfile.close()
326
326
    # If the database is missing this worksheet or out of date, update its
327
327
    # details about this worksheet
328
328
    # Note: Do NOT set assessable (this is done at the subject level).
329
 
    update_db_worksheet(subject, worksheet, worksheetmtime, exercise_list)
 
329
    update_db_worksheet(req.store, subject, worksheet, worksheetmtime,
 
330
        exercise_list)
330
331
 
331
332
    # Write each element
332
333
    exerciseid = 0
613
614
""" % (exerciseid, filename, exerciseid, exerciseid, filename, rows))
614
615
    req.write("</div>\n")
615
616
 
616
 
def update_db_worksheet(subject, worksheet, file_mtime,
 
617
def update_db_worksheet(store, subject, worksheetname, file_mtime,
617
618
    exercise_list=None, assessable=None):
618
619
    """
619
620
    Determines if the database is missing this worksheet or out of date,
620
621
    and inserts or updates its details about the worksheet.
621
 
    file_mtime is a time.struct_time with the modification time of the XML
 
622
    file_mtime is a datetime.datetime with the modification time of the XML
622
623
    file. The database will not be updated unless worksheetmtime is newer than
623
624
    the mtime in the database.
624
625
    exercise_list is a list of (filename, optional) pairs as returned by
628
629
    the existing data. If the worksheet does not yet exist, and assessable
629
630
    is omitted, it defaults to False.
630
631
    """
631
 
    db = ivle.db.DB()
632
 
    try:
633
 
        db_mtime = db.get_worksheet_mtime(subject, worksheet)
634
 
        if db_mtime is None or file_mtime > db_mtime:
635
 
            db.create_worksheet(subject, worksheet, exercise_list, assessable)
636
 
    finally:
637
 
        db.close()
 
632
    worksheet = ivle.database.Worksheet.get_by_name(store, subject,
 
633
                                                    worksheetname)
 
634
    db_mtime = worksheet.mtime if worksheet is not None else None
 
635
    if db_mtime is None or file_mtime > db_mtime:
 
636
        db = ivle.db.DB()
 
637
        try:
 
638
            db.create_worksheet(subject, worksheetname, exercise_list,
 
639
                                assessable)
 
640
        finally:
 
641
            db.close()