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

« back to all changes in this revision

Viewing changes to ivle/worksheet/utils.py

  • Committer: William Grant
  • Date: 2009-12-17 05:37:21 UTC
  • mfrom: (1442.1.33 offering-home)
  • Revision ID: me@williamgrant.id.au-20091217053721-cesek4r55zbsyj4b
Replace the offering worksheets page with an offering index, including project information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
309
309
    cons.close()
310
310
 
311
311
    return test_results
 
312
 
 
313
 
 
314
class FakeWorksheetForMarks:
 
315
    """This class represents a worksheet and a particular students progress
 
316
    through it.
 
317
    
 
318
    Do not confuse this with a worksheet in the database. This worksheet
 
319
    has extra information for use in the output, such as marks."""
 
320
    def __init__(self, id, name, assessable):
 
321
        self.id = id
 
322
        self.name = name
 
323
        self.assessable = assessable
 
324
        self.complete_class = ''
 
325
        self.optional_message = ''
 
326
        self.total = 0
 
327
        self.mand_done = 0
 
328
    def __repr__(self):
 
329
        return ("Worksheet(id=%s, name=%s, assessable=%s)"
 
330
                % (repr(self.id), repr(self.name), repr(self.assessable)))
 
331
 
 
332
 
 
333
# XXX: This really shouldn't be needed.
 
334
def create_list_of_fake_worksheets_and_stats(store, user, offering):
 
335
    """Take an offering's real worksheets, converting them into stats.
 
336
 
 
337
    The worksheet listing views expect special fake worksheet objects
 
338
    that contain counts of exercises, whether they've been completed,
 
339
    that sort of thing. A fake worksheet object is used to contain
 
340
    these values, because nobody has managed to refactor the need out
 
341
    yet.
 
342
    """
 
343
    new_worksheets = []
 
344
    problems_done = 0
 
345
    problems_total = 0
 
346
 
 
347
    # Offering.worksheets is ordered by the worksheets seq_no
 
348
    for worksheet in offering.worksheets:
 
349
        new_worksheet = FakeWorksheetForMarks(
 
350
            worksheet.identifier, worksheet.name, worksheet.assessable)
 
351
        if new_worksheet.assessable:
 
352
            # Calculate the user's score for this worksheet
 
353
            mand_done, mand_total, opt_done, opt_total = (
 
354
                ivle.worksheet.utils.calculate_score(store, user, worksheet))
 
355
            if opt_total > 0:
 
356
                optional_message = " (excluding optional exercises)"
 
357
            else:
 
358
                optional_message = ""
 
359
            if mand_done >= mand_total:
 
360
                new_worksheet.complete_class = "complete"
 
361
            elif mand_done > 0:
 
362
                new_worksheet.complete_class = "semicomplete"
 
363
            else:
 
364
                new_worksheet.complete_class = "incomplete"
 
365
            problems_done += mand_done
 
366
            problems_total += mand_total
 
367
            new_worksheet.mand_done = mand_done
 
368
            new_worksheet.total = mand_total
 
369
            new_worksheet.optional_message = optional_message
 
370
        new_worksheets.append(new_worksheet)
 
371
 
 
372
    return new_worksheets, problems_total, problems_done