37
37
from ivle.webapp.base.xhtml import XHTMLView
38
38
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
39
from ivle.webapp.errors import NotFound
40
39
from ivle.webapp import ApplicationRoot
42
41
from ivle.database import Subject, Semester, Offering, Enrolment, User,\
47
46
from ivle.webapp.admin.projectservice import ProjectSetRESTView,\
49
48
from ivle.webapp.admin.offeringservice import OfferingRESTView
49
from ivle.webapp.admin.traversal import (root_to_subject,
50
subject_to_offering, offering_to_projectset, offering_to_project,
51
subject_url, offering_url, projectset_url, project_url)
51
53
class SubjectsView(XHTMLView):
52
54
'''The view of the list of subjects.'''
215
217
def __init__(self, offering):
216
218
self.offering = offering
218
def root_to_subject(root, name):
219
return root.store.find(Subject, short_name=name).one()
221
def subject_to_offering(subject, year, semester):
222
return subject.offering_for_semester(year, semester)
224
def offering_to_project(offering, name):
225
return Store.of(offering).find(Project,
226
Project.project_set_id == ProjectSet.id,
227
ProjectSet.offering == offering).one()
229
def offering_to_projectset(offering, name):
230
return Store.of(offering).find(ProjectSet,
231
ProjectSet.offering == offering).one()
233
220
class Plugin(ViewPlugin, MediaPlugin):
234
forward_routes = [(ApplicationRoot, 'subjects', root_to_subject, 1),
235
(Subject, None, subject_to_offering, 2),
236
(Offering, '+projects', offering_to_project, 1),
237
(Offering, '+projectsets', offering_to_projectset, 1),
221
forward_routes = (root_to_subject, subject_to_offering,
222
offering_to_project, offering_to_projectset)
223
reverse_routes = (subject_url, offering_url, projectset_url, project_url)
240
225
views = [(ApplicationRoot, ('subjects', '+index'), SubjectsView),
241
226
(Offering, ('+enrolments', '+new'), EnrolView),