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,
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):
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
557
560
class EnrolView(XHTMLView):
584
587
ctx['roles_auth'] = self.context.get_permissions(req.user, req.config)
585
588
ctx['errors'] = errors
591
class EnrolmentEditSchema(formencode.Schema):
592
role = formencode.All(formencode.validators.OneOf(
593
["lecturer", "tutor", "student"]),
594
RoleEnrolmentValidator(),
595
formencode.validators.UnicodeString())
598
class EnrolmentEdit(BaseFormView):
599
"""A form to alter an enrolment's role."""
600
template = 'templates/enrolment-edit.html'
604
def populate_state(self, state):
605
state.offering = self.context.offering
607
def get_default_data(self, req):
608
return {'role': self.context.role}
612
return EnrolmentEditSchema()
614
def save_object(self, req, data):
615
self.context.role = data['role']
617
def get_return_url(self, obj):
618
return self.req.publisher.generate(
619
self.context.offering, EnrolmentsView)
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)
627
class EnrolmentDelete(XHTMLView):
628
"""A form to alter an enrolment's role."""
629
template = 'templates/enrolment-delete.html'
633
def populate(self, req, ctx):
634
# If POSTing, delete delete delete.
635
if req.method == 'POST':
636
self.context.delete()
638
req.throw_redirect(req.publisher.generate(
639
self.context.offering, EnrolmentsView))
641
ctx['enrolment'] = self.context
587
644
class OfferingProjectsView(XHTMLView):
588
645
"""View the projects for an offering."""
589
646
template = 'templates/offering_projects.html'
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,
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),