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

« back to all changes in this revision

Viewing changes to ivle/database.py

Better instructions in the usage message.

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
31
32
from storm.exceptions import NotOneError, IntegrityError
32
33
 
33
34
from ivle.worksheet.rst import rst
379
380
 
380
381
        return enrolment
381
382
 
 
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
 
382
394
class Enrolment(Storm):
383
395
    """An enrolment of a user in an offering.
384
396
 
438
450
    def get_permissions(self, user):
439
451
        return self.offering.get_permissions(user)
440
452
 
 
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
 
441
465
class Project(Storm):
442
466
    """A student project for which submissions can be made."""
443
467
 
494
518
    def get_permissions(self, user):
495
519
        return self.project_set.offering.get_permissions(user)
496
520
 
 
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
 
497
534
 
498
535
class ProjectGroup(Storm):
499
536
    """A group of students working together on a project."""
593
630
            self.user or self.project_group, self.project)
594
631
 
595
632
    @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
596
638
    def principal(self):
597
639
        return self.project_group or self.user
598
640