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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: Matt Giuca
  • Date: 2009-12-01 04:27:58 UTC
  • mfrom: (1164.2.46 sphinx-docs)
  • Revision ID: matt.giuca@gmail.com-20091201042758-wuxd9bdec00c283i
Merged sphinx-docs branch. This adds Sphinx documentation for the entire IVLE system (for system administrators and developers), and removes all of our random old document files (all either irrelevant, or moved into the Sphinx docs nicely). Currently incomplete, but ready to merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
234
234
        they may do everything. Otherwise they may do nothing.
235
235
        """
236
236
        if user and user.admin or user is self:
237
 
            return set(['view_public', 'view', 'edit', 'submit_project'])
 
237
            return set(['view', 'edit', 'submit_project'])
238
238
        else:
239
 
            return set(['view_public'])
 
239
            return set()
240
240
 
241
241
# SUBJECTS AND ENROLMENTS #
242
242
 
249
249
    code = Unicode(name="subj_code")
250
250
    name = Unicode(name="subj_name")
251
251
    short_name = Unicode(name="subj_short_name")
 
252
    url = Unicode()
252
253
 
253
254
    offerings = ReferenceSet(id, 'Offering.subject_id')
254
255
 
321
322
    subject = Reference(subject_id, Subject.id)
322
323
    semester_id = Int(name="semesterid")
323
324
    semester = Reference(semester_id, Semester.id)
324
 
    description = Unicode()
325
 
    url = Unicode()
326
325
    groups_student_permissions = Unicode()
327
326
 
328
327
    enrolments = ReferenceSet(id, 'Enrolment.offering_id')
331
330
                           'Enrolment.user_id',
332
331
                           'User.id')
333
332
    project_sets = ReferenceSet(id, 'ProjectSet.offering_id')
334
 
    projects = ReferenceSet(id,
335
 
                            'ProjectSet.offering_id',
336
 
                            'ProjectSet.id',
337
 
                            'Project.project_set_id')
338
333
 
339
334
    worksheets = ReferenceSet(id, 
340
335
        'Worksheet.offering_id', 
380
375
            if (enrolment and enrolment.role in (u'tutor', u'lecturer')) \
381
376
               or user.admin:
382
377
                perms.add('edit')
383
 
                # XXX Bug #493945 -- should tutors have these permissions?
384
 
                # Potentially move into the next category (lecturer & admin)
385
 
                perms.add('enrol')          # Can see enrolment screen at all
386
 
                perms.add('enrol_student')  # Can enrol students
387
 
            if (enrolment and enrolment.role in (u'lecturer')) or user.admin:
388
 
                perms.add('enrol_tutor')    # Can enrol tutors
389
 
            if user.admin:
390
 
                perms.add('enrol_lecturer') # Can enrol lecturers
391
378
        return perms
392
379
 
393
380
    def get_enrolment(self, user):
404
391
                Enrolment.user_id == User.id,
405
392
                Enrolment.offering_id == self.id,
406
393
                Enrolment.role == role
407
 
                ).order_by(User.login)
 
394
                )
408
395
 
409
396
    @property
410
397
    def students(self):
411
398
        return self.get_members_by_role(u'student')
412
399
 
413
 
    def get_open_projects_for_user(self, user):
414
 
        """Find all projects currently open to submissions by a user."""
415
 
        # XXX: Respect extensions.
416
 
        return self.projects.find(Project.deadline > datetime.datetime.now())
417
 
 
418
400
class Enrolment(Storm):
419
401
    """An enrolment of a user in an offering.
420
402
 
474
456
    def get_permissions(self, user):
475
457
        return self.offering.get_permissions(user)
476
458
 
477
 
    def get_groups_for_user(self, user):
478
 
        """List all groups in this offering of which the user is a member."""
479
 
        assert self.is_group
480
 
        return Store.of(self).find(
481
 
            ProjectGroup,
482
 
            ProjectGroupMembership.user_id == user.id,
483
 
            ProjectGroupMembership.project_group_id == ProjectGroup.id,
484
 
            ProjectGroup.project_set_id == self.id)
485
 
 
486
 
    def get_submission_principal(self, user):
487
 
        """Get the principal on behalf of which the user can submit.
488
 
 
489
 
        If this is a solo project set, the given user is returned. If
490
 
        the user is a member of exactly one group, all the group is
491
 
        returned. Otherwise, None is returned.
492
 
        """
493
 
        if self.is_group:
494
 
            groups = self.get_groups_for_user(user)
495
 
            if groups.count() == 1:
496
 
                return groups.one()
497
 
            else:
498
 
                return None
499
 
        else:
500
 
            return user
501
 
 
502
 
    @property
503
 
    def is_group(self):
504
 
        return self.max_students_per_group is not None
505
 
 
506
459
    @property
507
460
    def assigned(self):
508
461
        """Get the entities (groups or users) assigned to submit this project.
510
463
        This will be a Storm ResultSet.
511
464
        """
512
465
        #If its a solo project, return everyone in offering
513
 
        if self.is_group:
 
466
        if self.max_students_per_group is None:
 
467
            return self.offering.students
 
468
        else:
514
469
            return self.project_groups
515
 
        else:
516
 
            return self.offering.students
517
470
 
518
471
class Project(Storm):
519
472
    """A student project for which submissions can be made."""
584
537
            )
585
538
        )
586
539
 
587
 
    def has_deadline_passed(self, user):
588
 
        """Check whether the deadline has passed."""
589
 
        # XXX: Need to respect extensions.
590
 
        return self.deadline < datetime.datetime.now()
591
 
 
592
 
    def get_submissions_for_principal(self, principal):
593
 
        """Fetch a ResultSet of all submissions by a particular principal."""
594
 
        assessed = Assessed.get(Store.of(self), principal, self)
595
 
        if assessed is None:
596
 
            return
597
 
        return assessed.submissions
598
 
 
599
 
 
600
540
 
601
541
class ProjectGroup(Storm):
602
542
    """A group of students working together on a project."""
695
635
    project = Reference(project_id, Project.id)
696
636
 
697
637
    extensions = ReferenceSet(id, 'ProjectExtension.assessed_id')
698
 
    submissions = ReferenceSet(
699
 
        id, 'ProjectSubmission.assessed_id', order_by='date_submitted')
 
638
    submissions = ReferenceSet(id, 'ProjectSubmission.assessed_id')
700
639
 
701
640
    def __repr__(self):
702
641
        return "<%s %r in %r>" % (type(self).__name__,
725
664
        a = store.find(cls,
726
665
            (t is User) or (cls.project_group_id == principal.id),
727
666
            (t is ProjectGroup) or (cls.user_id == principal.id),
728
 
            cls.project_id == project.id).one()
 
667
            Project.id == project.id).one()
729
668
 
730
669
        if a is None:
731
670
            a = cls()
1020
959
 
1021
960
    def delete(self):
1022
961
        """Delete this suite, without asking questions."""
1023
 
        for variable in self.variables:
 
962
        for vaariable in self.variables:
1024
963
            variable.delete()
1025
964
        for test_case in self.test_cases:
1026
965
            test_case.delete()
1039
978
    suite = Reference(suiteid, "TestSuite.suiteid")
1040
979
    passmsg = Unicode()
1041
980
    failmsg = Unicode()
1042
 
    test_default = Unicode() # Currently unused - only used for file matching.
 
981
    test_default = Unicode()
1043
982
    seq_no = Int()
1044
983
 
1045
984
    parts = ReferenceSet(testid, "TestCasePart.testid")