~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-09 01:15:33 UTC
  • mto: This revision was merged to the branch mainline in revision 1162.
  • Revision ID: chadnickbok@gmail.com-20090309011533-dw59mhauiysji3nt
Fixed a slight oversight, which meant there was no way to add a new
exercise through the ui.

In addition, entire exercises can now be deleted, providing they have
never been linked to a worksheet.

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
        
538
552
        
539
553
    def populate(self, req, ctx):
540
554
        ctx['exercise'] = self.context
544
558
            if self.context.worksheet_exercises.count() is not 0:
545
559
                ctx['hasworksheets'] = True
546
560
            else:
547
 
                #TODO: DELETE the exercise and all its test cases
 
561
                self.remove_exercise(req)
548
562
                ctx['deleted'] = True
549
563
        else:
550
564
            if self.context.worksheet_exercises.count() is not 0:
552
566
            else:
553
567
                ctx['hasworksheets'] = False
554
568
 
 
569
class ExerciseAddView(XHTMLView):
 
570
    """View for creating a new exercise."""
 
571
    
 
572
    permission = 'edit'
 
573
    template = 'templates/exercise_add.html'
 
574
    
 
575
    def authorize(self, req):
 
576
        for offering in req.store.find(Offering):
 
577
            if 'edit' in offering.get_permissions(req.user):
 
578
                return True
 
579
        return False
 
580
        
 
581
    def populate(self, req, ctx):
 
582
        self.plugin_scripts[Plugin] = ['exercise_admin.js']
 
583
 
 
584
 
555
585
class ExercisesView(XHTMLView):
556
586
    """View for seeing the list of all exercises"""
557
587
    
590
620
 
591
621
        # Exercise View Urls
592
622
        ('+exercises', ExercisesView),
 
623
        ('+exercises/+add', ExerciseAddView),
593
624
        ('+exercises/:exercise/+edit', ExerciseEditView),
594
625
        ('+exercises/:exercise/+delete', ExerciseDeleteView),
595
626