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
OfferingBreadcrumb, UserBreadcrumb, ProjectBreadcrumb)
56
OfferingBreadcrumb, UserBreadcrumb, ProjectBreadcrumb,
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
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'
548
550
permission = 'edit'
551
breadcrumb_text = 'Enrolments'
550
553
def populate(self, req, ctx):
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
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
595
class EnrolmentEditSchema(formencode.Schema):
596
role = formencode.All(formencode.validators.OneOf(
597
["lecturer", "tutor", "student"]),
598
RoleEnrolmentValidator(),
599
formencode.validators.UnicodeString())
602
class EnrolmentEdit(BaseFormView):
603
"""A form to alter an enrolment's role."""
604
template = 'templates/enrolment-edit.html'
608
def populate_state(self, state):
609
state.offering = self.context.offering
611
def get_default_data(self, req):
612
return {'role': self.context.role}
616
return EnrolmentEditSchema()
618
def save_object(self, req, data):
619
self.context.role = data['role']
621
def get_return_url(self, obj):
622
return self.req.publisher.generate(
623
self.context.offering, EnrolmentsView)
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)
631
class EnrolmentDelete(XHTMLView):
632
"""A form to alter an enrolment's role."""
633
template = 'templates/enrolment-delete.html'
637
def populate(self, req, ctx):
638
# If POSTing, delete delete delete.
639
if req.method == 'POST':
640
self.context.delete()
642
req.throw_redirect(req.publisher.generate(
643
self.context.offering, EnrolmentsView))
645
ctx['enrolment'] = self.context
583
648
class OfferingProjectsView(XHTMLView):
584
649
"""View the projects for an offering."""
585
650
template = 'templates/offering_projects.html'
586
651
permission = 'edit'
653
breadcrumb_text = 'Projects'
589
655
def populate(self, req, ctx):
590
656
self.plugin_styles[Plugin] = ["project.css"]
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,
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),