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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: William Grant
  • Date: 2009-05-05 06:46:58 UTC
  • mto: (1165.3.65 submissions-admin)
  • mto: This revision was merged to the branch mainline in revision 1247.
  • Revision ID: grantw@unimelb.edu.au-20090505064658-o913x4ooxxbjfo1q
Avoid clobbering the submission owner's privileges if they have offering privs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
from storm.locals import create_database, Store, Int, Unicode, DateTime, \
30
30
                         Reference, ReferenceSet, Bool, Storm, Desc
31
 
from storm.expr import Select, Max
32
31
from storm.exceptions import NotOneError, IntegrityError
33
32
 
34
33
from ivle.worksheet.rst import rst
380
379
 
381
380
        return enrolment
382
381
 
383
 
    def get_members_by_role(self, role):
384
 
        return Store.of(self).find(User,
385
 
                Enrolment.user_id == User.id,
386
 
                Enrolment.offering_id == self.id,
387
 
                Enrolment.role == role
388
 
                )
389
 
 
390
 
    @property
391
 
    def students(self):
392
 
        return self.get_members_by_role(u'student')
393
 
 
394
382
class Enrolment(Storm):
395
383
    """An enrolment of a user in an offering.
396
384
 
450
438
    def get_permissions(self, user):
451
439
        return self.offering.get_permissions(user)
452
440
 
453
 
    @property
454
 
    def assigned(self):
455
 
        """Get the entities (groups or users) assigned to submit this project.
456
 
 
457
 
        This will be a Storm ResultSet.
458
 
        """
459
 
        #If its a solo project, return everyone in offering
460
 
        if self.max_students_per_group is None:
461
 
            return self.offering.students
462
 
        else:
463
 
            return self.project_groups
464
 
 
465
441
class Project(Storm):
466
442
    """A student project for which submissions can be made."""
467
443
 
518
494
    def get_permissions(self, user):
519
495
        return self.project_set.offering.get_permissions(user)
520
496
 
521
 
    @property
522
 
    def latest_submissions(self):
523
 
        """Return the latest submission for each Assessed."""
524
 
        return Store.of(self).find(ProjectSubmission,
525
 
            Assessed.project_id == self.id,
526
 
            ProjectSubmission.assessed_id == Assessed.id,
527
 
            ProjectSubmission.date_submitted == Select(
528
 
                    Max(ProjectSubmission.date_submitted),
529
 
                    ProjectSubmission.assessed_id == Assessed.id,
530
 
                    tables=ProjectSubmission
531
 
            )
532
 
        )
533
 
 
534
497
 
535
498
class ProjectGroup(Storm):
536
499
    """A group of students working together on a project."""
630
593
            self.user or self.project_group, self.project)
631
594
 
632
595
    @property
633
 
    def is_group(self):
634
 
        """True if the Assessed is a group, False if it is a user."""
635
 
        return self.project_group is not None
636
 
 
637
 
    @property
638
596
    def principal(self):
639
597
        return self.project_group or self.user
640
598