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

« back to all changes in this revision

Viewing changes to ivle/database.py

Merge from submissions-admin.

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')
 
382
    def get_students(self):
 
383
        enrolments = self.enrolments.find(role=u'student')
 
384
        return [enrolment.user for enrolment in enrolments]
393
385
 
394
386
class Enrolment(Storm):
395
387
    """An enrolment of a user in an offering.
450
442
    def get_permissions(self, user):
451
443
        return self.offering.get_permissions(user)
452
444
 
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
 
445
    # Get the individuals (groups or users) Assigned to this project
 
446
    def get_assigned(self):
 
447
        #If its a Solo project, return everyone in offering
460
448
        if self.max_students_per_group is None:
461
 
            return self.offering.students
 
449
            return self.offering.get_students()
462
450
        else:
463
451
            return self.project_groups
464
452
 
518
506
    def get_permissions(self, user):
519
507
        return self.project_set.offering.get_permissions(user)
520
508
 
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
509
 
535
510
class ProjectGroup(Storm):
536
511
    """A group of students working together on a project."""
630
605
            self.user or self.project_group, self.project)
631
606
 
632
607
    @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
608
    def principal(self):
639
609
        return self.project_group or self.user
640
610