~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/tutorial/__init__.py

  • Committer: Nick Chadwick
  • Date: 2009-03-10 13:35:39 UTC
  • mto: This revision was merged to the branch mainline in revision 1162.
  • Revision ID: chadnickbok@gmail.com-20090310133539-1zerqg77sy6izqku
Exercise objects in the database module, along with their test cases,
now have delete() methods, which allow for 'safe' removal. Calling
this method will only delete an exercise if it has no saves or attempts
associated with it.

Updated ExerciseDeleteView to make use of this new functionality.

Updated ExerciseDeleteView, and its template, to be clearer in their
control flow.

Show diffs side-by-side

added added

removed removed

Lines of Context:
535
535
        
536
536
        if self.context is None:
537
537
            raise NotFound()
538
 
    
539
 
    #Remove the context and all of its tests
540
 
    def remove_exercise(self, req):
541
 
        
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)
551
 
        
552
 
        
 
538
 
553
539
    def populate(self, req, ctx):
 
540
 
 
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)
 
546
 
 
547
        # If get, display a delete confirmation page
 
548
        else:
 
549
            ctx['method'] = 'GET'
 
550
            if self.context.worksheet_exercises.count() is not 0:
 
551
                ctx['has_worksheets'] = True
 
552
            else:
 
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
560
 
            else:
561
 
                self.remove_exercise(req)
562
 
                ctx['deleted'] = True
563
 
        else:
564
 
            if self.context.worksheet_exercises.count() is not 0:
565
 
                ctx['hasworksheets'] = True
566
 
            else:
567
 
                ctx['hasworksheets'] = False
568
557
 
569
558
class ExerciseAddView(XHTMLView):
570
559
    """View for creating a new exercise."""