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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: William Grant
  • Date: 2009-03-26 11:58:44 UTC
  • mto: (1165.3.1 submissions)
  • mto: This revision was merged to the branch mainline in revision 1174.
  • Revision ID: grantw@unimelb.edu.au-20090326115844-n9dsmpfgo19vgpox
Add a method to retrieve or create an Assessed given a principal and project.

Show diffs side-by-side

added added

removed removed

Lines of Context:
493
493
        return "<%s %r in %r>" % (type(self).__name__,
494
494
            self.user or self.project_group, self.project)
495
495
 
 
496
    @classmethod
 
497
    def get(cls, store, principal, project):
 
498
        t = type(principal)
 
499
        if t not in (User, ProjectGroup):
 
500
            raise AssertionError('principal must be User or ProjectGroup')
 
501
 
 
502
        a = store.find(cls,
 
503
            (t is User) or (cls.project_group_id == principal.id),
 
504
            (t is ProjectGroup) or (cls.user_id == principal.id),
 
505
            Project.id == project.id).one()
 
506
 
 
507
        if a is None:
 
508
            a = cls()
 
509
            if t is User:
 
510
                a.user = principal
 
511
            else:
 
512
                a.project_group = principal
 
513
            a.project = project
 
514
            store.add(a)
 
515
 
 
516
        return a
 
517
 
 
518
 
496
519
class ProjectExtension(Storm):
497
520
    __storm_table__ = "project_extension"
498
521