29
29
from storm.locals import Desc
30
31
from genshi.filters import HTMLFormFiller
32
from genshi.template import Context, TemplateLoader
33
35
from ivle.webapp.base.xhtml import XHTMLView
34
36
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
35
37
from ivle.webapp.errors import NotFound
36
from ivle.database import Subject, Semester, Offering, Enrolment, User
38
from ivle.database import Subject, Semester, Offering, Enrolment, User,\
37
40
from ivle import util
42
from ivle.webapp.admin.projectservice import ProjectSetRESTView,\
44
from ivle.webapp.admin.offeringservice import OfferingRESTView
40
47
class SubjectsView(XHTMLView):
41
48
'''The view of the list of subjects.'''
42
template = 'subjects.html'
49
template = 'templates/subjects.html'
45
52
def authorize(self, req):
140
147
if not self.context:
150
def project_url(self, projectset, project):
151
return "/subjects/" + self.context.subject.short_name + "/" +\
152
self.context.semester.year + "/" + \
153
self.context.semester.semester + "/+projectsets/" +\
154
str(projectset.id) + "/+projects/" + project.short_name
156
def new_project_url(self, projectset):
157
return "/api/subjects/" + self.context.subject.short_name + "/" +\
158
self.context.semester.year + "/" + \
159
self.context.semester.semester + "/+projectsets/" +\
160
str(projectset.id) + "/+projects/+new"
143
162
def populate(self, req, ctx):
144
163
self.plugin_styles[Plugin] = ["project.css"]
164
self.plugin_scripts[Plugin] = ["project.js"]
145
165
ctx['offering'] = self.context
147
class ProjectSetView(XHTMLView):
166
ctx['subject'] = self.context.subject.short_name
167
ctx['year'] = self.context.semester.year
168
ctx['semester'] = self.context.semester.semester
170
ctx['projectsets'] = []
172
#Open the projectset Fragment, and render it for inclusion
173
#into the ProjectSets page
174
#XXX: This could be a lot cleaner
175
loader = genshi.template.TemplateLoader(".", auto_reload=True)
177
set_fragment = os.path.join(os.path.dirname(__file__),
178
"templates/projectset_fragment.html")
179
project_fragment = os.path.join(os.path.dirname(__file__),
180
"templates/project_fragment.html")
182
for projectset in self.context.project_sets:
183
settmpl = loader.load(set_fragment)
185
setCtx['group_size'] = projectset.max_students_per_group
186
setCtx['projectset_id'] = projectset.id
187
setCtx['new_project_url'] = self.new_project_url(projectset)
188
setCtx['projects'] = []
190
for project in projectset.projects:
191
projecttmpl = loader.load(project_fragment)
192
projectCtx = Context()
193
projectCtx['project'] = project
194
projectCtx['project_url'] = self.project_url(projectset, project)
196
setCtx['projects'].append(
197
projecttmpl.generate(projectCtx))
199
ctx['projectsets'].append(settmpl.generate(setCtx))
202
class ProjectView(XHTMLView):
148
203
"""View the submissions for a ProjectSet"""
149
template = 'projectsubmissions.html'
204
template = "templates/project.html"
207
def __init__(self, req, subject, year, semester, projectset, project):
208
self.context = req.store.find(Project,
209
Project.short_name == project,
210
Project.project_set_id == ProjectSet.id,
211
ProjectSet.offering_id == Offering.id,
212
Offering.semester_id == Semester.id,
213
Semester.year == year,
214
Semester.semester == semester,
215
Offering.subject_id == Subject.id,
216
Subject.short_name == subject).one()
217
if self.context is None:
220
def populate(self, req, ctx):
221
ctx['project'] = self.context
222
ctx['assesseds'] = self.context.assesseds
152
225
class Plugin(ViewPlugin, MediaPlugin):
154
227
('subjects/', SubjectsView),
155
228
('subjects/:subject/:year/:semester/+enrolments/+new', EnrolView),
156
229
('subjects/:subject/:year/:semester/+projects', SubjectProjectSetView),
230
('subjects/:subject/:year/:semester/+projectsets/:projectset/+projects/:project', ProjectView),
232
('api/subjects/:subject/:year/:semester/+projectsets/+new',
234
('api/subjects/:subject/:year/:semester/+projectsets/:projectset/+projects/+new',
236
('api/subjects/:subject/:year/:semester/+projectsets/:projectset/+projects/:project',