509
509
def populate(self, req, ctx):
510
510
self.plugin_styles[Plugin] = ['exercise_admin.css']
511
511
self.plugin_scripts[Plugin] = ['exercise_admin.js']
513
ctx['mediapath'] = media_url(req, Plugin, 'images/')
513
515
ctx['exercise'] = self.context
514
516
#XXX: These should come from somewhere else
520
522
ctx['test_types'] = ('norm', 'check')
524
class ExerciseDeleteView(XHTMLView):
525
"""View for confirming the deletion of an exercise."""
528
template = 'templates/exercise_delete.html'
530
def __init__(self, req, exercise):
531
self.context = req.store.find(Exercise,
532
Exercise.id == exercise).one()
534
if self.context is None:
537
def populate(self, req, ctx):
538
ctx['exercise'] = self.context
539
ctx['deleted'] = False
540
ctx['path'] = "/+exercises/" + self.context.id + "/+delete"
541
if req.method == 'POST':
542
if self.context.worksheet_exercises.count() is not 0:
543
ctx['hasworksheets'] = True
545
#TODO: DELETE the exercise and all its test cases
546
ctx['deleted'] = True
548
if self.context.worksheet_exercises.count() is not 0:
549
ctx['hasworksheets'] = True
551
ctx['hasworksheets'] = False
553
class ExercisesView(XHTMLView):
554
"""View for seeing the list of all exercises"""
557
template = 'templates/exercises.html'
559
def authorize(self, req):
560
for offering in req.store.find(Offering):
561
if 'edit' in offering.get_permissions(req.user):
565
def populate(self, req, ctx):
566
self.plugin_styles[Plugin] = ['exercise_admin.css']
567
ctx['exercises'] = req.store.find(Exercise).order_by(Exercise.id)
568
ctx['mediapath'] = media_url(req, Plugin, 'images/')
522
570
class Plugin(ViewPlugin, MediaPlugin):
524
572
# Worksheet View Urls
539
587
('api/subjects/:subject/:year/:semester/+worksheets/:worksheet/*exercise', WorksheetExerciseRESTView),
541
589
# Exercise View Urls
590
('+exercises', ExercisesView),
542
591
('+exercises/:exercise/+edit', ExerciseEditView),
592
('+exercises/:exercise/+delete', ExerciseDeleteView),
544
594
# Exercise Api Urls
545
595
('api/+exercises', ExercisesRESTView),