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

« back to all changes in this revision

Viewing changes to ivle/database.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:
454
454
    def get_description(self):
455
455
        return rst(self.description)
456
456
 
 
457
    def delete(self, store):
 
458
        """Deletes the exercise, providing it has no associated worksheets.
 
459
        
 
460
        Returns True if delete successful. Otherwise returns False."""
 
461
        if self.worksheet_exercises.count() > 0:
 
462
            return False
 
463
 
 
464
        for suite in self.test_suites:
 
465
            suite.delete()
 
466
        store.remove(self)
 
467
        return True
 
468
 
457
469
class Worksheet(Storm):
458
470
    __storm_table__ = "worksheet"
459
471
 
516
528
            return ws_xml
517
529
        else:
518
530
            return self.data
519
 
 
 
531
    
 
532
    def delete(self, store):
 
533
        """Deletes the worksheet, provided it has no attempts on any exercises.
 
534
        
 
535
        Returns True if delete succeeded, or False if this worksheet has
 
536
        attempts attached."""
 
537
        for ws_ex in self.all_worksheet_exercises:
 
538
            if ws_ex.saves.count() > 0 or ws_ex.attempts.count() > 0:
 
539
                return False
 
540
        
 
541
        self.remove_all_exercises()
 
542
        store.remove(self)
 
543
        return True
 
544
        
520
545
class WorksheetExercise(Storm):
521
546
    __storm_table__ = "worksheet_exercise"
522
547
    
541
566
 
542
567
    def get_permissions(self, user):
543
568
        return self.worksheet.get_permissions(user)
 
569
    
544
570
 
545
571
class ExerciseSave(Storm):
546
572
    """
607
633
    exercise = Reference(exercise_id, Exercise.id)
608
634
    test_cases = ReferenceSet(suiteid, 'TestCase.suiteid', order_by="seq_no")
609
635
    variables = ReferenceSet(suiteid, 'TestSuiteVar.suiteid', order_by='arg_no')
 
636
    
 
637
    def delete(self, store):
 
638
        """Delete this suite, without asking questions."""
 
639
        for vaariable in self.variables:
 
640
            variable.delete()
 
641
        for test_case in self.test_cases:
 
642
            test_case.delete()
 
643
        store.remove(self)
610
644
 
611
645
class TestCase(Storm):
612
646
    """A TestCase is a member of a TestSuite.
626
660
    parts = ReferenceSet(testid, "TestCasePart.testid")
627
661
    
628
662
    __init__ = _kwarg_init
 
663
    
 
664
    def delete(self, store):
 
665
        for part in self.parts:
 
666
            part.delete()
 
667
        store.remove(self)
629
668
 
630
669
class TestSuiteVar(Storm):
631
670
    """A container for the arguments of a Test Suite"""
643
682
    
644
683
    __init__ = _kwarg_init
645
684
    
 
685
    def delete(self, store):
 
686
        store.remove(self)
 
687
    
646
688
class TestCasePart(Storm):
647
689
    """A container for the test elements of a Test Case"""
648
690
    __storm_table__ = "test_case_part"
659
701
    test = Reference(testid, "TestCase.testid")
660
702
    
661
703
    __init__ = _kwarg_init
 
704
    
 
705
    def delete(self, store):
 
706
        store.remove(self)