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

« back to all changes in this revision

Viewing changes to ivle/webapp/admin/subject.py

  • Committer: William Grant
  • Date: 2010-02-23 08:48:09 UTC
  • mfrom: (1673 trunk)
  • mto: This revision was merged to the branch mainline in revision 1674.
  • Revision ID: grantw@unimelb.edu.au-20100223084809-du6dvsxrjhw15ytr
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
from ivle.webapp.admin.offeringservice import OfferingRESTView
51
51
from ivle.webapp.admin.publishing import (root_to_subject, root_to_semester,
52
52
            subject_to_offering, offering_to_projectset, offering_to_project,
53
 
            subject_url, semester_url, offering_url, projectset_url,
54
 
            project_url)
 
53
            offering_to_enrolment, subject_url, semester_url, offering_url,
 
54
            projectset_url, project_url, enrolment_url)
55
55
from ivle.webapp.admin.breadcrumbs import (SubjectBreadcrumb,
56
 
            OfferingBreadcrumb, UserBreadcrumb, ProjectBreadcrumb)
 
56
            OfferingBreadcrumb, UserBreadcrumb, ProjectBreadcrumb,
 
57
            EnrolmentBreadcrumb)
57
58
from ivle.webapp.core import Plugin as CorePlugin
58
59
from ivle.webapp.groups import GroupsView
59
60
from ivle.webapp.media import media_url
284
285
        ctx['OfferingEdit'] = OfferingEdit
285
286
        ctx['OfferingCloneWorksheets'] = OfferingCloneWorksheets
286
287
        ctx['GroupsView'] = GroupsView
 
288
        ctx['EnrolmentsView'] = EnrolmentsView
287
289
 
288
290
        # As we go, calculate the total score for this subject
289
291
        # (Assessable worksheets only, mandatory problems only)
546
548
    template = 'templates/enrolments.html'
547
549
    tab = 'subjects'
548
550
    permission = 'edit'
 
551
    breadcrumb_text = 'Enrolments'
549
552
 
550
553
    def populate(self, req, ctx):
 
554
        ctx['req'] = req
551
555
        ctx['offering'] = self.context
 
556
        ctx['mediapath'] = media_url(req, CorePlugin, 'images/')
 
557
        ctx['offering_perms'] = self.context.get_permissions(
 
558
            req.user, req.config)
 
559
        ctx['EnrolView'] = EnrolView
 
560
        ctx['EnrolmentEdit'] = EnrolmentEdit
 
561
        ctx['EnrolmentDelete'] = EnrolmentDelete
 
562
 
552
563
 
553
564
class EnrolView(XHTMLView):
554
565
    """A form to enrol a user in an offering."""
580
591
        ctx['roles_auth'] = self.context.get_permissions(req.user, req.config)
581
592
        ctx['errors'] = errors
582
593
 
 
594
 
 
595
class EnrolmentEditSchema(formencode.Schema):
 
596
    role = formencode.All(formencode.validators.OneOf(
 
597
                                ["lecturer", "tutor", "student"]),
 
598
                          RoleEnrolmentValidator(),
 
599
                          formencode.validators.UnicodeString())
 
600
 
 
601
 
 
602
class EnrolmentEdit(BaseFormView):
 
603
    """A form to alter an enrolment's role."""
 
604
    template = 'templates/enrolment-edit.html'
 
605
    tab = 'subjects'
 
606
    permission = 'edit'
 
607
 
 
608
    def populate_state(self, state):
 
609
        state.offering = self.context.offering
 
610
 
 
611
    def get_default_data(self, req):
 
612
        return {'role': self.context.role}
 
613
 
 
614
    @property
 
615
    def validator(self):
 
616
        return EnrolmentEditSchema()
 
617
 
 
618
    def save_object(self, req, data):
 
619
        self.context.role = data['role']
 
620
 
 
621
    def get_return_url(self, obj):
 
622
        return self.req.publisher.generate(
 
623
            self.context.offering, EnrolmentsView)
 
624
 
 
625
    def populate(self, req, ctx):
 
626
        super(EnrolmentEdit, self).populate(req, ctx)
 
627
        ctx['offering_perms'] = self.context.offering.get_permissions(
 
628
            req.user, req.config)
 
629
 
 
630
 
 
631
class EnrolmentDelete(XHTMLView):
 
632
    """A form to alter an enrolment's role."""
 
633
    template = 'templates/enrolment-delete.html'
 
634
    tab = 'subjects'
 
635
    permission = 'edit'
 
636
 
 
637
    def populate(self, req, ctx):
 
638
        # If POSTing, delete delete delete.
 
639
        if req.method == 'POST':
 
640
            self.context.delete()
 
641
            req.store.commit()
 
642
            req.throw_redirect(req.publisher.generate(
 
643
                self.context.offering, EnrolmentsView))
 
644
 
 
645
        ctx['enrolment'] = self.context
 
646
 
 
647
 
583
648
class OfferingProjectsView(XHTMLView):
584
649
    """View the projects for an offering."""
585
650
    template = 'templates/offering_projects.html'
586
651
    permission = 'edit'
587
652
    tab = 'subjects'
 
653
    breadcrumb_text = 'Projects'
588
654
 
589
655
    def populate(self, req, ctx):
590
656
        self.plugin_styles[Plugin] = ["project.css"]
663
729
 
664
730
class Plugin(ViewPlugin, MediaPlugin):
665
731
    forward_routes = (root_to_subject, root_to_semester, subject_to_offering,
666
 
                      offering_to_project, offering_to_projectset)
 
732
                      offering_to_project, offering_to_projectset,
 
733
                      offering_to_enrolment)
667
734
    reverse_routes = (
668
 
        subject_url, semester_url, offering_url, projectset_url, project_url)
 
735
        subject_url, semester_url, offering_url, projectset_url, project_url,
 
736
        enrolment_url)
669
737
 
670
738
    views = [(ApplicationRoot, ('subjects', '+index'), SubjectsView),
671
739
             (ApplicationRoot, ('subjects', '+manage'), SubjectsManage),
679
747
             (Offering, '+clone-worksheets', OfferingCloneWorksheets),
680
748
             (Offering, ('+enrolments', '+index'), EnrolmentsView),
681
749
             (Offering, ('+enrolments', '+new'), EnrolView),
 
750
             (Enrolment, '+edit', EnrolmentEdit),
 
751
             (Enrolment, '+delete', EnrolmentDelete),
682
752
             (Offering, ('+projects', '+index'), OfferingProjectsView),
683
753
             (Project, '+index', ProjectView),
684
754
 
690
760
                   Offering: OfferingBreadcrumb,
691
761
                   User: UserBreadcrumb,
692
762
                   Project: ProjectBreadcrumb,
 
763
                   Enrolment: EnrolmentBreadcrumb,
693
764
                   }
694
765
 
695
766
    tabs = [