37
37
from ivle.webapp.base.xhtml import XHTMLView
38
38
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
39
from ivle.webapp import ApplicationRoot
39
from ivle.webapp.errors import NotFound
41
41
from ivle.database import Subject, Semester, Offering, Enrolment, User,\
42
42
ProjectSet, Project, ProjectSubmission
46
46
from ivle.webapp.admin.projectservice import ProjectSetRESTView,\
48
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)
53
51
class SubjectsView(XHTMLView):
54
52
'''The view of the list of subjects.'''
103
101
permission = 'edit'
103
def __init__(self, req, subject, year, semester):
104
"""Find the given offering by subject, year and semester."""
105
self.context = req.store.find(Offering,
106
Offering.subject_id == Subject.id,
107
Subject.short_name == subject,
108
Offering.semester_id == Semester.id,
109
Semester.year == year,
110
Semester.semester == semester).one()
105
115
def filter(self, stream, ctx):
106
116
return stream | HTMLFormFiller(data=ctx['data'])
130
140
template = 'templates/offering_projects.html'
131
141
permission = 'edit'
144
def __init__(self, req, subject, year, semester):
145
self.context = req.store.find(Offering,
146
Offering.subject_id == Subject.id,
147
Subject.short_name == subject,
148
Offering.semester_id == Semester.id,
149
Semester.year == year,
150
Semester.semester == semester).one()
134
155
def project_url(self, projectset, project):
135
156
return "/subjects/%s/%s/%s/+projects/%s" % (
186
207
permission = "edit"
210
def __init__(self, req, subject, year, semester, project):
211
self.context = req.store.find(Project,
212
Project.short_name == project,
213
Project.project_set_id == ProjectSet.id,
214
ProjectSet.offering_id == Offering.id,
215
Offering.semester_id == Semester.id,
216
Semester.year == year,
217
Semester.semester == semester,
218
Offering.subject_id == Subject.id,
219
Subject.short_name == subject).one()
220
if self.context is None:
189
223
def build_subversion_url(self, svnroot, submission):
190
224
princ = submission.assessed.principal
213
247
ctx['project'] = self.context
214
248
ctx['user'] = req.user
216
class OfferingEnrolmentSet(object):
217
def __init__(self, offering):
218
self.offering = offering
220
250
class Plugin(ViewPlugin, MediaPlugin):
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)
225
views = [(ApplicationRoot, ('subjects', '+index'), SubjectsView),
226
(Offering, ('+enrolments', '+new'), EnrolView),
227
(Offering, ('+projects', '+index'), OfferingProjectsView),
228
(Project, '+index', ProjectView),
230
(Offering, ('+projectsets', '+new'), OfferingRESTView, 'api'),
231
(ProjectSet, ('+projects', '+new'), ProjectSetRESTView, 'api'),
232
(Project, '+index', ProjectRESTView, 'api'),
252
('subjects/', SubjectsView),
253
('subjects/:subject/:year/:semester/+enrolments/+new', EnrolView),
254
('subjects/:subject/:year/:semester/+projects', OfferingProjectsView),
255
('subjects/:subject/:year/:semester/+projects/:project', ProjectView),
257
('api/subjects/:subject/:year/:semester/+projectsets/+new',
259
('api/subjects/:subject/:year/:semester/+projectsets/:projectset/+projects/+new',
261
('api/subjects/:subject/:year/:semester/+projects/:project',
236
267
('subjects', 'Subjects',