~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-17 08:37:22 UTC
  • Revision ID: grantw@unimelb.edu.au-20100217083722-ji4v6fbztngy0p3s
Add UI to edit/delete enrolments.

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
56
            OfferingBreadcrumb, UserBreadcrumb, ProjectBreadcrumb)
57
57
from ivle.webapp.core import Plugin as CorePlugin
551
551
    def populate(self, req, ctx):
552
552
        ctx['req'] = req
553
553
        ctx['offering'] = self.context
 
554
        ctx['mediapath'] = media_url(req, CorePlugin, 'images/')
554
555
        ctx['EnrolView'] = EnrolView
 
556
        ctx['EnrolmentEdit'] = EnrolmentEdit
 
557
        ctx['EnrolmentDelete'] = EnrolmentDelete
555
558
 
556
559
 
557
560
class EnrolView(XHTMLView):
584
587
        ctx['roles_auth'] = self.context.get_permissions(req.user, req.config)
585
588
        ctx['errors'] = errors
586
589
 
 
590
 
 
591
class EnrolmentEditSchema(formencode.Schema):
 
592
    role = formencode.All(formencode.validators.OneOf(
 
593
                                ["lecturer", "tutor", "student"]),
 
594
                          RoleEnrolmentValidator(),
 
595
                          formencode.validators.UnicodeString())
 
596
 
 
597
 
 
598
class EnrolmentEdit(BaseFormView):
 
599
    """A form to alter an enrolment's role."""
 
600
    template = 'templates/enrolment-edit.html'
 
601
    tab = 'subjects'
 
602
    permission = 'edit'
 
603
 
 
604
    def populate_state(self, state):
 
605
        state.offering = self.context.offering
 
606
 
 
607
    def get_default_data(self, req):
 
608
        return {'role': self.context.role}
 
609
 
 
610
    @property
 
611
    def validator(self):
 
612
        return EnrolmentEditSchema()
 
613
 
 
614
    def save_object(self, req, data):
 
615
        self.context.role = data['role']
 
616
 
 
617
    def get_return_url(self, obj):
 
618
        return self.req.publisher.generate(
 
619
            self.context.offering, EnrolmentsView)
 
620
 
 
621
    def populate(self, req, ctx):
 
622
        super(EnrolmentEdit, self).populate(req, ctx)
 
623
        ctx['offering_perms'] = self.context.offering.get_permissions(
 
624
            req.user, req.config)
 
625
 
 
626
 
 
627
class EnrolmentDelete(XHTMLView):
 
628
    """A form to alter an enrolment's role."""
 
629
    template = 'templates/enrolment-delete.html'
 
630
    tab = 'subjects'
 
631
    permission = 'edit'
 
632
 
 
633
    def populate(self, req, ctx):
 
634
        # If POSTing, delete delete delete.
 
635
        if req.method == 'POST':
 
636
            self.context.delete()
 
637
            req.store.commit()
 
638
            req.throw_redirect(req.publisher.generate(
 
639
                self.context.offering, EnrolmentsView))
 
640
 
 
641
        ctx['enrolment'] = self.context
 
642
 
 
643
 
587
644
class OfferingProjectsView(XHTMLView):
588
645
    """View the projects for an offering."""
589
646
    template = 'templates/offering_projects.html'
667
724
 
668
725
class Plugin(ViewPlugin, MediaPlugin):
669
726
    forward_routes = (root_to_subject, root_to_semester, subject_to_offering,
670
 
                      offering_to_project, offering_to_projectset)
 
727
                      offering_to_project, offering_to_projectset,
 
728
                      offering_to_enrolment)
671
729
    reverse_routes = (
672
 
        subject_url, semester_url, offering_url, projectset_url, project_url)
 
730
        subject_url, semester_url, offering_url, projectset_url, project_url,
 
731
        enrolment_url)
673
732
 
674
733
    views = [(ApplicationRoot, ('subjects', '+index'), SubjectsView),
675
734
             (ApplicationRoot, ('subjects', '+manage'), SubjectsManage),
683
742
             (Offering, '+clone-worksheets', OfferingCloneWorksheets),
684
743
             (Offering, ('+enrolments', '+index'), EnrolmentsView),
685
744
             (Offering, ('+enrolments', '+new'), EnrolView),
 
745
             (Enrolment, '+edit', EnrolmentEdit),
 
746
             (Enrolment, '+delete', EnrolmentDelete),
686
747
             (Offering, ('+projects', '+index'), OfferingProjectsView),
687
748
             (Project, '+index', ProjectView),
688
749