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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: matt.giuca
  • Date: 2009-02-25 01:15:49 UTC
  • Revision ID: svn-v4:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1206
tutorial/__init__.py: Fixed path to exercises template
    (prefixed "templates/").

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
            'ProjectSet', 'Project', 'ProjectGroup', 'ProjectGroupMembership',
39
39
            'Exercise', 'Worksheet', 'WorksheetExercise',
40
40
            'ExerciseSave', 'ExerciseAttempt',
41
 
            'TestCase', 'TestSuite', 'TestSuiteVar'
 
41
            'AlreadyEnrolledError', 'TestCase', 'TestSuite', 'TestSuiteVar'
42
42
        ]
43
43
 
44
44
def _kwarg_init(self, **kwargs):
269
269
        return "<%s %r in %r>" % (type(self).__name__, self.subject,
270
270
                                  self.semester)
271
271
 
272
 
    def enrol(self, user, role=u'student'):
 
272
    def enrol(self, user):
273
273
        '''Enrol a user in this offering.'''
274
 
        enrolment = Store.of(self).find(Enrolment,
 
274
        # We'll get a horrible database constraint violation error if we try
 
275
        # to add a second enrolment.
 
276
        if Store.of(self).find(Enrolment,
275
277
                               Enrolment.user_id == user.id,
276
 
                               Enrolment.offering_id == self.id).one()
277
 
 
278
 
        if enrolment is None:
279
 
            enrolment = Enrolment(user=user, offering=self)
280
 
            self.enrolments.add(enrolment)
281
 
 
282
 
        enrolment.active = True
283
 
        enrolment.role = role
 
278
                               Enrolment.offering_id == self.id).count() == 1:
 
279
            raise AlreadyEnrolledError()
 
280
 
 
281
        e = Enrolment(user=user, offering=self, active=True)
 
282
        self.enrolments.add(e)
284
283
 
285
284
    def get_permissions(self, user):
286
285
        perms = set()
316
315
        return "<%s %r in %r>" % (type(self).__name__, self.user,
317
316
                                  self.offering)
318
317
 
 
318
class AlreadyEnrolledError(Exception):
 
319
    pass
 
320
 
319
321
# PROJECTS #
320
322
 
321
323
class ProjectSet(Storm):