520
520
ctx['test_types'] = ('norm', 'check')
522
class ExerciseDeleteView(XHTMLView):
523
"""View for confirming the deletion of an exercise."""
526
template = 'template/exercise_delete.html'
528
def __init__(self, req, exercise):
529
self.context = req.store.find(Exercise,
530
Exercise.id == exercise).one()
532
if self.context is None:
535
def populate(self, req, ctx):
536
ctx['exercise'] = self.context
538
if self.context.worksheet_exercises.count() is not 0:
539
ctx['hasworksheets'] = True
541
class ExercisesView(XHTMLView):
542
"""View for seeing the list of all exercises"""
545
template = 'templates/exercises.html'
547
def authorize(self, req):
548
for offering in req.store.find(Offering):
549
if 'edit' in offering.get_permissions(req.user):
553
def populate(self, req, ctx):
554
self.plugin_styles[Plugin] = ['exercise_admin.css']
555
ctx['exercises'] = req.store.find(Exercise).order_by(Exercise.id)
556
ctx['mediapath'] = media_url(req, Plugin, 'images/')
522
558
class Plugin(ViewPlugin, MediaPlugin):
524
560
# Worksheet View Urls
539
575
('api/subjects/:subject/:year/:semester/+worksheets/:worksheet/*exercise', WorksheetExerciseRESTView),
541
577
# Exercise View Urls
578
('+exercises', ExercisesView),
542
579
('+exercises/:exercise/+edit', ExerciseEditView),
580
('+exercises/:exercise/+edit', ExerciseDeleteView),
544
582
# Exercise Api Urls
545
583
('api/+exercises', ExercisesRESTView),