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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: William Grant
  • Date: 2009-12-17 05:37:21 UTC
  • mfrom: (1442.1.33 offering-home)
  • Revision ID: me@williamgrant.id.au-20091217053721-cesek4r55zbsyj4b
Replace the offering worksheets page with an offering index, including project information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
330
330
                           'Enrolment.user_id',
331
331
                           'User.id')
332
332
    project_sets = ReferenceSet(id, 'ProjectSet.offering_id')
 
333
    projects = ReferenceSet(id,
 
334
                            'ProjectSet.offering_id',
 
335
                            'ProjectSet.id',
 
336
                            'Project.project_set_id')
333
337
 
334
338
    worksheets = ReferenceSet(id, 
335
339
        'Worksheet.offering_id', 
405
409
    def students(self):
406
410
        return self.get_members_by_role(u'student')
407
411
 
 
412
    def get_open_projects_for_user(self, user):
 
413
        """Find all projects currently open to submissions by a user."""
 
414
        # XXX: Respect extensions.
 
415
        return self.projects.find(Project.deadline > datetime.datetime.now())
 
416
 
408
417
class Enrolment(Storm):
409
418
    """An enrolment of a user in an offering.
410
419
 
464
473
    def get_permissions(self, user):
465
474
        return self.offering.get_permissions(user)
466
475
 
 
476
    def get_groups_for_user(self, user):
 
477
        """List all groups in this offering of which the user is a member."""
 
478
        assert self.is_group
 
479
        return Store.of(self).find(
 
480
            ProjectGroup,
 
481
            ProjectGroupMembership.user_id == user.id,
 
482
            ProjectGroupMembership.project_group_id == ProjectGroup.id,
 
483
            ProjectGroup.project_set_id == self.id)
 
484
 
 
485
    def get_submission_principal(self, user):
 
486
        """Get the principal on behalf of which the user can submit.
 
487
 
 
488
        If this is a solo project set, the given user is returned. If
 
489
        the user is a member of exactly one group, all the group is
 
490
        returned. Otherwise, None is returned.
 
491
        """
 
492
        if self.is_group:
 
493
            groups = self.get_groups_for_user(user)
 
494
            if groups.count() == 1:
 
495
                return groups.one()
 
496
            else:
 
497
                return None
 
498
        else:
 
499
            return user
 
500
 
467
501
    @property
468
502
    def is_group(self):
469
503
        return self.max_students_per_group is not None
549
583
            )
550
584
        )
551
585
 
 
586
    def has_deadline_passed(self, user):
 
587
        """Check whether the deadline has passed."""
 
588
        # XXX: Need to respect extensions.
 
589
        return self.deadline < datetime.datetime.now()
 
590
 
 
591
    def get_submissions_for_principal(self, principal):
 
592
        """Fetch a ResultSet of all submissions by a particular principal."""
 
593
        assessed = Assessed.get(Store.of(self), principal, self)
 
594
        if assessed is None:
 
595
            return
 
596
        return assessed.submissions
 
597
 
 
598
 
552
599
 
553
600
class ProjectGroup(Storm):
554
601
    """A group of students working together on a project."""
647
694
    project = Reference(project_id, Project.id)
648
695
 
649
696
    extensions = ReferenceSet(id, 'ProjectExtension.assessed_id')
650
 
    submissions = ReferenceSet(id, 'ProjectSubmission.assessed_id')
 
697
    submissions = ReferenceSet(
 
698
        id, 'ProjectSubmission.assessed_id', order_by='date_submitted')
651
699
 
652
700
    def __repr__(self):
653
701
        return "<%s %r in %r>" % (type(self).__name__,