~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-17 01:42:19 UTC
  • mto: This revision was merged to the branch mainline in revision 1162.
  • Revision ID: chadnickbok@gmail.com-20090317014219-e0dvzakaxw58b71p
Fixed a problem with exercise editor, which wasn't editing or adding
variables properly.

Fixed the final issues from the merge-proposal, which make deleting
exercises use appropriate functions, which now raise exceptions
if they fail.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
from storm.locals import create_database, Store, Int, Unicode, DateTime, \
31
31
                         Reference, ReferenceSet, Bool, Storm, Desc
32
 
from storm.exceptions import NotOneError
 
32
from storm.exceptions import NotOneError, IntegrityError
33
33
 
34
34
import ivle.conf
35
35
from ivle.worksheet.rst import rst
459
459
    def get_description(self):
460
460
        return rst(self.description)
461
461
 
462
 
    def delete(self, store):
463
 
        """Deletes the exercise, providing it has no associated worksheets.
464
 
        
465
 
        Returns True if delete successful. Otherwise returns False."""
466
 
        if self.worksheet_exercises.count() > 0:
467
 
            return False
468
 
 
 
462
    def delete(self):
 
463
        """Deletes the exercise, providing it has no associated worksheets."""
 
464
        if (self.worksheet_exercises.count() > 0):
 
465
            raise IntegrityError()
469
466
        for suite in self.test_suites:
470
467
            suite.delete()
471
 
        store.remove(self)
472
 
        return True
 
468
        Store.of(self).remove(self)
473
469
 
474
470
class Worksheet(Storm):
475
471
    __storm_table__ = "worksheet"
514
510
        return store.find(cls, cls.subject == unicode(subjectname),
515
511
            cls.name == unicode(worksheetname)).one()
516
512
 
517
 
    def remove_all_exercises(self, store):
 
513
    def remove_all_exercises(self):
518
514
        """
519
515
        Remove all exercises from this worksheet.
520
516
        This does not delete the exercises themselves. It just removes them
521
517
        from the worksheet.
522
518
        """
 
519
        store = Store.of(self)
 
520
        for ws_ex in self.all_worksheet_exercises:
 
521
            if ws_ex.saves.count() > 0 or ws_ex.attempts.count() > 0:
 
522
                raise IntegrityError()
523
523
        store.find(WorksheetExercise,
524
524
            WorksheetExercise.worksheet == self).remove()
525
525
            
534
534
        else:
535
535
            return self.data
536
536
    
537
 
    def delete(self, store):
 
537
    def delete(self):
538
538
        """Deletes the worksheet, provided it has no attempts on any exercises.
539
539
        
540
540
        Returns True if delete succeeded, or False if this worksheet has
541
541
        attempts attached."""
542
542
        for ws_ex in self.all_worksheet_exercises:
543
543
            if ws_ex.saves.count() > 0 or ws_ex.attempts.count() > 0:
544
 
                return False
 
544
                raise IntegrityError()
545
545
        
546
546
        self.remove_all_exercises()
547
 
        store.remove(self)
548
 
        return True
 
547
        Store.of(self).remove(self)
549
548
        
550
549
class WorksheetExercise(Storm):
551
550
    __storm_table__ = "worksheet_exercise"
639
638
    test_cases = ReferenceSet(suiteid, 'TestCase.suiteid', order_by="seq_no")
640
639
    variables = ReferenceSet(suiteid, 'TestSuiteVar.suiteid', order_by='arg_no')
641
640
    
642
 
    def delete(self, store):
 
641
    def delete(self):
643
642
        """Delete this suite, without asking questions."""
644
643
        for vaariable in self.variables:
645
644
            variable.delete()
646
645
        for test_case in self.test_cases:
647
646
            test_case.delete()
648
 
        store.remove(self)
 
647
        Store.of(self).remove(self)
649
648
 
650
649
class TestCase(Storm):
651
650
    """A TestCase is a member of a TestSuite.
666
665
    
667
666
    __init__ = _kwarg_init
668
667
    
669
 
    def delete(self, store):
 
668
    def delete(self):
670
669
        for part in self.parts:
671
670
            part.delete()
672
 
        store.remove(self)
 
671
        Store.of(self).remove(self)
673
672
 
674
673
class TestSuiteVar(Storm):
675
674
    """A container for the arguments of a Test Suite"""
687
686
    
688
687
    __init__ = _kwarg_init
689
688
    
690
 
    def delete(self, store):
691
 
        store.remove(self)
 
689
    def delete(self):
 
690
        Store.of(self).remove(self)
692
691
    
693
692
class TestCasePart(Storm):
694
693
    """A container for the test elements of a Test Case"""
707
706
    
708
707
    __init__ = _kwarg_init
709
708
    
710
 
    def delete(self, store):
711
 
        store.remove(self)
 
709
    def delete(self):
 
710
        Store.of(self).remove(self)