536
536
if self.context is None:
539
#Remove the context and all of its tests
540
def remove_exercise(self, req):
542
for suite in self.context.test_suites:
543
for var in suite.variables:
544
req.store.remove(var)
545
for case in suite.test_cases:
546
for part in case.parts:
547
req.store.remove(part)
548
req.store.remove(case)
549
req.store.remove(suite)
550
req.store.remove(self.context)
553
539
def populate(self, req, ctx):
541
# If post, delete the exercise, or display a message explaining that
542
# the exercise cannot be deleted
543
if req.method == 'POST':
544
ctx['method'] = 'POST'
545
ctx['deleted'] = self.context.delete(req.store)
547
# If get, display a delete confirmation page
549
ctx['method'] = 'GET'
550
if self.context.worksheet_exercises.count() is not 0:
551
ctx['has_worksheets'] = True
553
ctx['has_worksheets'] = False
554
# Variables for the template
554
555
ctx['exercise'] = self.context
555
ctx['deleted'] = False
556
556
ctx['path'] = "/+exercises/" + self.context.id + "/+delete"
557
if req.method == 'POST':
558
if self.context.worksheet_exercises.count() is not 0:
559
ctx['hasworksheets'] = True
561
self.remove_exercise(req)
562
ctx['deleted'] = True
564
if self.context.worksheet_exercises.count() is not 0:
565
ctx['hasworksheets'] = True
567
ctx['hasworksheets'] = False
569
558
class ExerciseAddView(XHTMLView):
570
559
"""View for creating a new exercise."""