~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-04-16 16:18:58 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:734
tutorial: BEHAVIOUR CHANGE
    Now assessable="true" is an attribute of the <worksheet> element of the
    subject.xml file, NOT the worksheet XML file!

    Reason: This allows you to quickly see at a glance for your subject which
    worksheets are assessable, all in the one place.
    Also, the worksheet XML files are being auto-generated and it's much
    easier to set the assessability in the subject XML file.
    Also, the subject XML file is under control of the subject coordinator,
    while the worksheet files may be written by other people.
    All around a Good Decision(TM).

This involved:
* No longer reads "assessable" in present_worksheet.
* Now the Worksheet class has an assessable attribute.
* In present_subject, every time it runs, it will check the assessable
  attribute of each worksheet against the DB to see if it has changed, and if
  so, it will update the db. It DOES NOT update the mtime in the DB when it
  does this (to make sure the worksheet XML still has a chance to update the
  DB).

All above claims are tested and work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
re_ident = re.compile("[0-9A-Za-z_]+")
53
53
 
54
54
class Worksheet:
55
 
    def __init__(self, id, name):
 
55
    def __init__(self, id, name, assessable):
56
56
        self.id = id
57
57
        self.name = name
 
58
        self.assessable = assessable
58
59
    def __repr__(self):
59
 
        return ("Worksheet(id=" + repr(self.id) + ", name=" + repr(self.name)
60
 
                + ")")
 
60
        return ("Worksheet(id=%s, name=%s, assessable=%s)"
 
61
                % (repr(self.id), repr(self.name), repr(self.assessable)))
61
62
 
62
63
def make_tutorial_path(subject=None, worksheet=None):
63
64
    """Creates an absolute (site-relative) path to a tutorial sheet.
195
196
    worksheets = []     # List of string IDs
196
197
    for worksheetdom in worksheetsdom.childNodes:
197
198
        if worksheetdom.nodeType == worksheetdom.ELEMENT_NODE:
 
199
            # Get the 3 attributes for this node and construct a Worksheet
 
200
            # object.
 
201
            # (Note: assessable will default to False, unless it is explicitly
 
202
            # set to "true").
198
203
            worksheet = Worksheet(worksheetdom.getAttribute("id"),
199
 
                worksheetdom.getAttribute("name"))
 
204
                worksheetdom.getAttribute("name"),
 
205
                worksheetdom.getAttribute("assessable") == "true")
200
206
            worksheets.append(worksheet)
201
207
 
202
208
    db = common.db.DB()
215
221
            req.write('  <li><a href="%s">%s</a>'
216
222
                % (urllib.quote(worksheet.id), cgi.escape(worksheet.name)))
217
223
            try:
218
 
                if db.worksheet_is_assessable(subject, worksheet.id):
 
224
                # If the assessable status of this worksheet has changed,
 
225
                # update the DB
 
226
                # (Note: This fails the try block if the worksheet is not yet
 
227
                # in the DB, which is fine. The author should visit the
 
228
                # worksheet page to get it into the DB).
 
229
                if (db.worksheet_is_assessable(subject, worksheet.id) !=
 
230
                    worksheet.assessable):
 
231
                    db.set_worksheet_assessable(subject, worksheet.id,
 
232
                        assessable=worksheet.assessable)
 
233
                if worksheet.assessable:
219
234
                    mand_done, mand_total, opt_done, opt_total = (
220
235
                        db.calculate_score_worksheet(req.user.login, subject,
221
236
                            worksheet.id))
291
306
    req.write("<h1>IVLE Tutorials - %s</h1>\n<h2>%s</h2>\n"
292
307
        % (cgi.escape(subject), cgi.escape(worksheetname)))
293
308
    exercise_list = present_table_of_contents(req, worksheetdom, 0)
294
 
    # Get the "assessable" attribute of the worksheet element.
295
 
    # Default to False
296
 
    assessable = worksheetdom.getAttribute("assessable") == "true"
297
309
    # If the database is missing this worksheet or out of date, update its
298
310
    # details about this worksheet
299
 
    update_db_worksheet(subject, worksheet, worksheetmtime,
300
 
        exercise_list, assessable)
 
311
    # Note: Do NOT set assessable (this is done at the subject level).
 
312
    update_db_worksheet(subject, worksheet, worksheetmtime, exercise_list)
301
313
 
302
314
    # Write each element
303
315
    exerciseid = 0