~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/model/bugtask.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-11-19 05:44:39 UTC
  • mfrom: (14307.1.2 delete-all-bugtasks-889202)
  • Revision ID: launchpad@pqm.canonical.com-20111119054439-j50wq607sp3mpmrm
[r=sinzui][bug=889202] Display a user friendly error message when a
        user attempts to delete the last bug task.

Show diffs side-by-side

added added

removed removed

Lines of Context:
640
640
        return self._status in RESOLVED_BUGTASK_STATUSES
641
641
 
642
642
    def canBeDeleted(self):
 
643
        try:
 
644
            self.checkCanBeDeleted()
 
645
        except Exception:
 
646
            return False
 
647
        return True
 
648
 
 
649
    def checkCanBeDeleted(self):
643
650
        num_bugtasks = Store.of(self).find(
644
651
            BugTask, bug=self.bug).count()
645
652
 
646
 
        return num_bugtasks > 1
 
653
        if num_bugtasks < 2:
 
654
            raise CannotDeleteBugtask(
 
655
                "Cannot delete only bugtask affecting: %s."
 
656
                % self.target.bugtargetdisplayname)
647
657
 
648
658
    def delete(self, who=None):
649
659
        """See `IBugTask`."""
650
660
        if who is None:
651
661
            who = getUtility(ILaunchBag).user
652
662
 
653
 
        if not self.canBeDeleted():
654
 
            raise CannotDeleteBugtask(
655
 
                "Cannot delete bugtask: %s" % self.title)
 
663
        # Raise an error if the bugtask cannot be deleted.
 
664
        self.checkCanBeDeleted()
 
665
 
656
666
        bug = self.bug
657
667
        target = self.target
658
668
        notify(ObjectDeletedEvent(self, who))