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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: William Grant
  • Date: 2009-02-25 23:04:11 UTC
  • Revision ID: grantw@unimelb.edu.au-20090225230411-lbdyl32ir0m3d59b
Make all of the services executable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
from storm.locals import create_database, Store, Int, Unicode, DateTime, \
31
31
                         Reference, ReferenceSet, Bool, Storm, Desc
32
 
from storm.exceptions import NotOneError
33
32
 
34
33
import ivle.conf
35
34
 
236
235
    state = Unicode()
237
236
 
238
237
    offerings = ReferenceSet(id, 'Offering.semester_id')
239
 
    enrolments = ReferenceSet(id,
240
 
                              'Offering.semester_id',
241
 
                              'Offering.id',
242
 
                              'Enrolment.offering_id')
243
238
 
244
239
    __init__ = _kwarg_init
245
240
 
287
282
        enrolment.active = True
288
283
        enrolment.role = role
289
284
 
290
 
    def unenrol(self, user):
291
 
        '''Unenrol a user from this offering.'''
292
 
        enrolment = Store.of(self).find(Enrolment,
293
 
                               Enrolment.user_id == user.id,
294
 
                               Enrolment.offering_id == self.id).one()
295
 
        Store.of(enrolment).remove(enrolment)
296
 
 
297
285
    def get_permissions(self, user):
298
286
        perms = set()
299
287
        if user is not None:
300
 
            enrolment = self.get_enrolment(user)
301
 
            if enrolment or user.admin:
302
 
                perms.add('view')
303
 
            if (enrolment and enrolment.role in (u'tutor', u'lecturer')) \
304
 
               or user.admin:
 
288
            perms.add('view')
 
289
            if user.admin:
305
290
                perms.add('edit')
306
291
        return perms
307
292
 
308
 
    def get_enrolment(self, user):
309
 
        try:
310
 
            enrolment = self.enrolments.find(user=user).one()
311
 
        except NotOneError:
312
 
            enrolment = None
313
 
 
314
 
        return enrolment
315
 
 
316
293
class Enrolment(Storm):
317
294
    __storm_table__ = "enrolment"
318
295
    __storm_primary__ = "user_id", "offering_id"
521
498
        return "<%s %s in %s>" % (type(self).__name__, self.exercise.name,
522
499
                                  self.worksheet.identifier)
523
500
 
524
 
    def get_permissions(self, user):
525
 
        return self.worksheet.get_permissions(user)
526
 
 
527
501
class ExerciseSave(Storm):
528
502
    """
529
503
    Represents a potential solution to an exercise that a user has submitted