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

« back to all changes in this revision

Viewing changes to ivle/worksheet/utils.py

  • Committer: William Grant
  • Date: 2010-02-11 08:53:40 UTC
  • Revision ID: grantw@unimelb.edu.au-20100211085340-4ms0t2f195dv0cqa
Correct the XHTML in the logout view.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
import ivle.database
32
32
from ivle.database import ExerciseAttempt, ExerciseSave, Worksheet, \
33
 
                          WorksheetExercise, Exercise, User
 
33
                          WorksheetExercise, Exercise
34
34
import ivle.webapp.tutorial.test
35
35
 
36
36
__all__ = ['ExerciseNotFound', 'get_exercise_status',
37
 
           'get_exercise_statistics',
38
37
           'get_exercise_stored_text', 'get_exercise_attempts',
39
38
           'get_exercise_attempt', 'test_exercise_submission',
40
39
          ]
83
82
 
84
83
    return first_success is not None, num_attempts
85
84
 
86
 
def get_exercise_statistics(store, worksheet_exercise):
87
 
    """Return statistics about an exercise (with respect to a given
88
 
    worksheet).
89
 
    (number of students completed, number of students attempted)."""
90
 
    # Count the set of Users whose ID matches an attempt in this worksheet
91
 
    num_completed = store.find(User, User.id == ExerciseAttempt.user_id,
92
 
        ExerciseAttempt.ws_ex_id == worksheet_exercise.id,
93
 
        ExerciseAttempt.complete == True).config(distinct=True).count()
94
 
    num_attempted = store.find(User, User.id == ExerciseAttempt.user_id,
95
 
        ExerciseAttempt.ws_ex_id == worksheet_exercise.id,
96
 
        ).config(distinct=True).count()
97
 
    return num_completed, num_attempted
98
 
 
99
85
def get_exercise_stored_text(store, user, worksheet_exercise):
100
86
    """Given a storm.store, User and WorksheetExercise, returns an
101
87
    ivle.database.ExerciseSave object for the last saved/submitted attempt for
258
244
    exercises = []
259
245
    # Turns the worksheet into an xml stream, and then finds all the 
260
246
    # exercise nodes in the stream.
261
 
    worksheetdata = genshi.XML(worksheet.data_xhtml)
 
247
    worksheetdata = genshi.XML(worksheet.get_xml())
262
248
    for kind, data, pos in worksheetdata:
263
249
        if kind is genshi.core.START:
264
250
            # Data is a tuple of tag name and a list of name->value tuples
308
294
    jail_path = os.path.join(config['paths']['jails']['mounts'],
309
295
                             user.login)
310
296
    working_dir = os.path.join("/home", user.login)
311
 
    cons = ivle.console.Console(config, user, jail_path,
 
297
    cons = ivle.console.Console(config, user.unixid, jail_path,
312
298
                                working_dir)
313
299
 
314
300
    # Parse the file into a exercise object using the test suite
331
317
    
332
318
    Do not confuse this with a worksheet in the database. This worksheet
333
319
    has extra information for use in the output, such as marks."""
334
 
    def __init__(self, id, name, assessable, published):
 
320
    def __init__(self, id, name, assessable):
335
321
        self.id = id
336
322
        self.name = name
337
323
        self.assessable = assessable
338
 
        self.published = published
339
324
        self.complete_class = ''
340
325
        self.optional_message = ''
341
326
        self.total = 0
346
331
 
347
332
 
348
333
# XXX: This really shouldn't be needed.
349
 
def create_list_of_fake_worksheets_and_stats(config, store, user, offering,
350
 
    as_of=None):
 
334
def create_list_of_fake_worksheets_and_stats(store, user, offering):
351
335
    """Take an offering's real worksheets, converting them into stats.
352
336
 
353
337
    The worksheet listing views expect special fake worksheet objects
361
345
    problems_total = 0
362
346
 
363
347
    # Offering.worksheets is ordered by the worksheets seq_no
364
 
    worksheets = offering.worksheets
365
 
 
366
 
    # Unless we can edit worksheets, hide unpublished ones.
367
 
    if 'edit_worksheets' not in offering.get_permissions(user, config):
368
 
        worksheets = worksheets.find(published=True)
369
 
 
370
 
    for worksheet in worksheets:
 
348
    for worksheet in offering.worksheets:
371
349
        new_worksheet = FakeWorksheetForMarks(
372
 
            worksheet.identifier, worksheet.name, worksheet.assessable,
373
 
            worksheet.published)
 
350
            worksheet.identifier, worksheet.name, worksheet.assessable)
374
351
        if new_worksheet.assessable:
375
352
            # Calculate the user's score for this worksheet
376
353
            mand_done, mand_total, opt_done, opt_total = (
377
 
                ivle.worksheet.utils.calculate_score(store, user, worksheet,
378
 
                                                     as_of=as_of))
 
354
                ivle.worksheet.utils.calculate_score(store, user, worksheet))
379
355
            if opt_total > 0:
380
356
                optional_message = " (excluding optional exercises)"
381
357
            else: