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

« back to all changes in this revision

Viewing changes to ivle/database.py

ivle.webapp.base.views.JSONRestView: Don't render anything if None is
    returned.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
            'ProjectSet', 'Project', 'ProjectGroup', 'ProjectGroupMembership',
40
40
            'Exercise', 'Worksheet', 'WorksheetExercise',
41
41
            'ExerciseSave', 'ExerciseAttempt',
42
 
            'AlreadyEnrolledError', 'TestCase', 'TestSuite'
 
42
            'AlreadyEnrolledError'
43
43
        ]
44
44
 
45
45
def _kwarg_init(self, **kwargs):
130
130
        fieldval = self.acct_exp
131
131
        return fieldval is not None and datetime.datetime.now() > fieldval
132
132
 
133
 
    @property
134
 
    def valid(self):
135
 
        return self.state == 'enabled' and not self.account_expired
136
 
 
137
133
    def _get_enrolments(self, justactive):
138
134
        return Store.of(self).find(Enrolment,
139
135
            Enrolment.user_id == self.id,
200
196
        """
201
197
        return store.find(cls, cls.login == unicode(login)).one()
202
198
 
203
 
    def get_permissions(self, user):
204
 
        if user and user.rolenm == 'admin' or user is self:
205
 
            return set(['view', 'edit'])
206
 
        else:
207
 
            return set()
208
 
 
209
199
# SUBJECTS AND ENROLMENTS #
210
200
 
211
201
class Subject(Storm):
224
214
    def __repr__(self):
225
215
        return "<%s '%s'>" % (type(self).__name__, self.short_name)
226
216
 
227
 
    def get_permissions(self, user):
228
 
        perms = set()
229
 
        if user is not None:
230
 
            perms.add('view')
231
 
        if user.rolenm == 'admin':
232
 
            perms.add('edit')
233
 
        return perms
234
 
 
235
217
class Semester(Storm):
236
218
    __storm_table__ = "semester"
237
219
 
264
246
                           'User.id')
265
247
    project_sets = ReferenceSet(id, 'ProjectSet.offering_id')
266
248
 
267
 
    worksheets = ReferenceSet(id, 'Worksheet.offering_id')
268
 
 
269
249
    __init__ = _kwarg_init
270
250
 
271
251
    def __repr__(self):
391
371
    # Note: Table "problem" is called "Exercise" in the Object layer, since
392
372
    # it's called that everywhere else.
393
373
    __storm_table__ = "problem"
394
 
#TODO: Add in a field for the user-friendly identifier
395
 
    id = Unicode(primary=True, name="identifier")
396
 
    name = Unicode()
397
 
    description = Unicode()
398
 
    partial = Unicode()
399
 
    solution = Unicode()
400
 
    include = Unicode()
401
 
    num_rows = Int()
 
374
 
 
375
    id = Int(primary=True, name="problemid")
 
376
    name = Unicode(name="identifier")
 
377
    spec = Unicode()
402
378
 
403
379
    worksheets = ReferenceSet(id,
404
380
        'WorksheetExercise.exercise_id',
405
381
        'WorksheetExercise.worksheet_id',
406
382
        'Worksheet.id'
407
383
    )
408
 
    
409
 
    test_suites = ReferenceSet(id, 'TestSuite.exercise_id')
410
384
 
411
385
    __init__ = _kwarg_init
412
386
 
435
409
    # XXX subject is not linked to a Subject object. This is a property of
436
410
    # the database, and will be refactored.
437
411
    subject = Unicode()
438
 
    offering_id = Int(name="offeringid")
439
412
    name = Unicode(name="identifier")
440
413
    assessable = Bool()
441
414
    mtime = DateTime()
442
415
 
443
 
    offering = Reference(offering_id, 'Offering.id')
444
 
 
445
416
    exercises = ReferenceSet(id,
446
417
        'WorksheetExercise.worksheet_id',
447
418
        'WorksheetExercise.exercise_id',
451
422
    # "optional" field.
452
423
    worksheet_exercises = ReferenceSet(id,
453
424
        'WorksheetExercise.worksheet_id')
454
 
        
455
425
 
456
426
    __init__ = _kwarg_init
457
427
 
485
455
 
486
456
    worksheet_id = Int(name="worksheetid")
487
457
    worksheet = Reference(worksheet_id, Worksheet.id)
488
 
    exercise_id = Unicode(name="problemid")
 
458
    exercise_id = Int(name="problemid")
489
459
    exercise = Reference(exercise_id, Exercise.id)
490
460
    optional = Bool()
491
461
 
507
477
    __storm_table__ = "problem_save"
508
478
    __storm_primary__ = "exercise_id", "user_id", "date"
509
479
 
510
 
    exercise_id = Unicode(name="problemid")
 
480
    exercise_id = Int(name="problemid")
511
481
    exercise = Reference(exercise_id, Exercise.id)
512
482
    user_id = Int(name="loginid")
513
483
    user = Reference(user_id, User.id)
514
484
    date = DateTime()
515
485
    text = Unicode()
516
 
    worksheetid = Int()
517
 
    worksheet = Reference(worksheetid, Worksheet.id)
518
486
 
519
487
    __init__ = _kwarg_init
520
488
 
543
511
    text = Unicode(name="attempt")
544
512
    complete = Bool()
545
513
    active = Bool()
546
 
    
547
 
    def get_permissions(self, user):
548
 
        return set(['view']) if user is self.user else set()
549
 
  
550
 
class TestSuite(Storm):
551
 
    """A Testsuite acts as a container for the test cases of an exercise."""
552
 
    __storm_table__ = "test_suite"
553
 
    __storm_primary__ = "exercise_id", "suiteid"
554
 
    
555
 
    suiteid = Int()
556
 
    exercise_id = Unicode(name="problemid")
557
 
    exercise = Reference(exercise_id, Exercise.id)
558
 
    test_cases = ReferenceSet(suiteid, 'TestCase.suiteid')
559
 
    description = Unicode()
560
 
    seq_no = Int()
561
 
 
562
 
class TestCase(Storm):
563
 
    """A TestCase is a member of a TestSuite.
564
 
    
565
 
    It contains the data necessary to check if an exercise is correct"""
566
 
    __storm_table__ = "test_case"
567
 
    __storm_primary__ = "testid", "suiteid"
568
 
    
569
 
    testid = Int()
570
 
    suiteid = Int()
571
 
    suite = Reference(suiteid, TestSuite.suiteid)
572
 
    passmsg = Unicode()
573
 
    failmsg = Unicode()
574
 
    init = Unicode()
575
 
    code_type = Unicode()
576
 
    code = Unicode()
577
 
    testtype = Unicode()
578
 
    seq_no = Int()
579
 
    
580
 
    __init__ = _kwarg_init