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

« back to all changes in this revision

Viewing changes to ivle/database.py

Now respects --zip, and creates Zip files.

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