~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-13 12:41:59 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:730
Added per-worksheet and per-subject score calculation.
common/db: Added functions worksheet_is_assessable and
            calculate_score_worksheet.
            (Added other helper functions too).
apps/tutorial: Expanded handle_subject_menu to include display of scores.
    (NOTE: IVLE does not apportion marks at this stage, just displays scores).
    * Displays under each assessable worksheet the number of mandatory
      exercises completed.
    * Displays at the bottom of the page the total number of mandatory
      exercises completed for the subject.
    * Note: Neither of these displays are visible if there are no assessable
      worksheets. If this doesn't show up, check that you have at least one
      worksheet with an 'assessable="true"' attribute in its top level
      element.
Added media/images/tutorial/tiny/semicomplete.png: Orange dot for the subject
menu.
Added new styles to media/tutorial/tutorial/css.

Show diffs side-by-side

added added

removed removed

Lines of Context:
199
199
                worksheetdom.getAttribute("name"))
200
200
            worksheets.append(worksheet)
201
201
 
202
 
    # Now all the errors are out the way, we can begin writing
203
 
    req.title = "Tutorial - %s" % subject
204
 
    req.write_html_head_foot = True
205
 
    req.write('<div id="ivle_padding">\n')
206
 
    req.write("<h1>IVLE Tutorials - %s</h1>\n" % cgi.escape(subject))
207
 
    req.write("<h2>Worksheets</h2>\n<ul>\n")
208
 
    for worksheet in worksheets:
209
 
        req.write('  <li><a href="%s">%s</a></li>\n'
210
 
            % (urllib.quote(worksheet.id), cgi.escape(worksheet.name)))
211
 
    req.write("</ul>\n")
212
 
    req.write("</div>\n")   # tutorialbody
 
202
    db = common.db.DB()
 
203
    try:
 
204
        # Now all the errors are out the way, we can begin writing
 
205
        req.title = "Tutorial - %s" % subject
 
206
        req.write_html_head_foot = True
 
207
        req.write('<div id="ivle_padding">\n')
 
208
        req.write("<h1>IVLE Tutorials - %s</h1>\n" % cgi.escape(subject))
 
209
        req.write('<h2>Worksheets</h2>\n<ul id="tutorial-toc">\n')
 
210
        # As we go, calculate the total score for this subject
 
211
        # (Assessable worksheets only, mandatory problems only)
 
212
        problems_done = 0
 
213
        problems_total = 0
 
214
        for worksheet in worksheets:
 
215
            req.write('  <li><a href="%s">%s</a>'
 
216
                % (urllib.quote(worksheet.id), cgi.escape(worksheet.name)))
 
217
            try:
 
218
                if db.worksheet_is_assessable(subject, worksheet.id):
 
219
                    mand_done, mand_total, opt_done, opt_total = (
 
220
                        db.calculate_score_worksheet(req.user.login, subject,
 
221
                            worksheet.id))
 
222
                    if opt_total > 0:
 
223
                        optional_message = " (excluding optional exercises)"
 
224
                    else:
 
225
                        optional_message = ""
 
226
                    if mand_done >= mand_total:
 
227
                        complete_class = "complete"
 
228
                    elif mand_done > 0:
 
229
                        complete_class = "semicomplete"
 
230
                    else:
 
231
                        complete_class = "incomplete"
 
232
                    problems_done += mand_done
 
233
                    problems_total += mand_total
 
234
                    req.write('\n    <ul><li class="%s">'
 
235
                            'Completed %d/%d%s</li></ul>\n  '
 
236
                            % (complete_class, mand_done, mand_total,
 
237
                                optional_message))
 
238
            except common.db.DBException:
 
239
                # Worksheet is probably not in database yet
 
240
                pass
 
241
            req.write('</li>\n')
 
242
        req.write("</ul>\n")
 
243
        if problems_total > 0:
 
244
            if problems_done >= problems_total:
 
245
                complete_class = "complete"
 
246
            elif problems_done > 0:
 
247
                complete_class = "semicomplete"
 
248
            else:
 
249
                complete_class = "incomplete"
 
250
            problems_pct = (100 * problems_done) / problems_total       # int
 
251
            req.write('<ul><li class="%s">Total exercises completed: %d/%d '
 
252
                        '(%d%%)</li></ul>'
 
253
                % (complete_class, problems_done, problems_total,
 
254
                    problems_pct))
 
255
        req.write("</div>\n")   # tutorialbody
 
256
    finally:
 
257
        db.close()
213
258
 
214
259
def handle_worksheet(req, subject, worksheet):
215
260
    # Subject and worksheet names must be valid identifiers