42
42
from ivle.webapp.base.views import BaseView
43
43
from ivle.webapp.base.xhtml import XHTMLView
44
44
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
45
from ivle.webapp.media import BaseMediaFileView
45
from ivle.webapp.media import BaseMediaFileView, media_url
46
46
from ivle.webapp.errors import NotFound, Forbidden
47
47
from ivle.webapp.tutorial.rst import rst as rstfunc
48
48
from ivle.webapp.tutorial.service import AttemptsRESTView, AttemptRESTView, \
457
457
#XXX: Get the list of formats from somewhere else
458
458
ctx['formats'] = ['xml', 'rst']
460
class WorksheetsEditView(XHTMLView):
461
"""View for arranging worksheets."""
464
template = 'templates/worksheets_edit.html'
466
def __init__(self, req, subject, year, semester):
467
self.context = req.store.find(Offering,
468
Offering.semester_id == Semester.id,
469
Semester.year == year,
470
Semester.semester == semester,
471
Offering.subject_id == Subject.id,
472
Subject.code == subject
475
self.subject = subject
477
self.semester = semester
479
if self.context is None:
482
def populate(self, req, ctx):
483
self.plugin_styles[Plugin] = ['tutorial_admin.css']
484
self.plugin_scripts[Plugin] = ['tutorial_admin.js']
486
ctx['subject'] = self.subject
487
ctx['year'] = self.year
488
ctx['semester'] = self.semester
490
ctx['worksheets'] = self.context.worksheets
492
ctx['mediapath'] = media_url(req, Plugin, 'images/')
461
496
class Plugin(ViewPlugin, MediaPlugin):
463
498
('subjects/:subject/:year/:semester/+worksheets', OfferingView),
464
499
('subjects/:subject/:year/:semester/+worksheets/+add', WorksheetAddView),
465
500
('subjects/:subject/+worksheets/+media/*(path)', SubjectMediaView),
501
('subjects/:subject/:year/:semester/+worksheets/+edit', WorksheetsEditView),
466
502
('subjects/:subject/:year/:semester/+worksheets/:worksheet', WorksheetView),
467
503
('subjects/:subject/:year/:semester/+worksheets/:worksheet/+edit', WorksheetEditView),
468
504
('api/subjects/:subject/:year/:semester/+worksheets', WorksheetsRESTView),