~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-08-02 04:21:43 UTC
  • mfrom: (13571.2.4 createtask-and-addtask)
  • Revision ID: launchpad@pqm.canonical.com-20110802042143-26jeqxhukor1eg0e
[r=benji][no-qa] Bug.addTask and BugTaskSet.createTask now take an
 IBugTarget directly instead of a target key.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2699
2699
            omit_dupes=True, exclude_conjoined_tasks=True)
2700
2700
        return self.search(params)
2701
2701
 
2702
 
    def createTask(self, bug, owner, product=None, productseries=None,
2703
 
                   distribution=None, distroseries=None,
2704
 
                   sourcepackagename=None,
 
2702
    def createTask(self, bug, owner, target,
2705
2703
                   status=IBugTask['status'].default,
2706
2704
                   importance=IBugTask['importance'].default,
2707
2705
                   assignee=None, milestone=None):
2715
2713
        if not milestone:
2716
2714
            milestone = None
2717
2715
 
2718
 
        # Raise a WidgetError if this product bugtask already exists.
2719
 
        target = None
2720
 
        stop_checking = False
2721
 
        if sourcepackagename is not None:
2722
 
            # A source package takes precedence over the distro series
2723
 
            # or distribution in which the source package is found.
2724
 
            if distroseries is not None:
2725
 
                # We'll need to make sure there's no bug task already
2726
 
                # filed against this source package in this
2727
 
                # distribution series.
2728
 
                target = distroseries.getSourcePackage(sourcepackagename)
2729
 
            elif distribution is not None:
2730
 
                # Make sure there's no bug task already filed against
2731
 
                # this source package in this distribution.
2732
 
                validate_new_target(
2733
 
                    bug, distribution.getSourcePackage(sourcepackagename))
2734
 
                stop_checking = True
2735
 
 
2736
 
        if target is None and not stop_checking:
2737
 
            # This task is not being filed against a source package. Find
2738
 
            # the prospective target.
2739
 
            if productseries is not None:
2740
 
                # Bug filed against a product series.
2741
 
                target = productseries
2742
 
            elif product is not None:
2743
 
                # Bug filed against a product.
2744
 
                target = product
2745
 
            elif distroseries is not None:
2746
 
                # Bug filed against a distro series.
2747
 
                target = distroseries
2748
 
            elif distribution is not None and not stop_checking:
2749
 
                # Bug filed against a distribution.
2750
 
                validate_new_target(bug, distribution)
2751
 
                stop_checking = True
2752
 
 
2753
 
        if target is not None and not stop_checking:
2754
 
            # Make sure there's no task for this bug already filed
2755
 
            # against the target.
2756
 
            validate_target(bug, target)
 
2716
        # Make sure there's no task for this bug already filed
 
2717
        # against the target.
 
2718
        validate_new_target(bug, target)
 
2719
 
 
2720
        target_key = bug_target_to_key(target)
2757
2721
 
2758
2722
        if not bug.private and bug.security_related:
 
2723
            product = target_key['product']
 
2724
            distribution = target_key['distribution']
2759
2725
            if product and product.security_contact:
2760
2726
                bug.subscribe(product.security_contact, owner)
2761
2727
            elif distribution and distribution.security_contact:
2762
2728
                bug.subscribe(distribution.security_contact, owner)
2763
2729
 
2764
 
        assert (product or productseries or distribution or distroseries), (
2765
 
            'Got no bugtask target.')
2766
 
 
2767
2730
        non_target_create_params = dict(
2768
2731
            bug=bug,
2769
2732
            status=status,
2771
2734
            assignee=assignee,
2772
2735
            owner=owner,
2773
2736
            milestone=milestone)
2774
 
        bugtask = BugTask(
2775
 
            product=product,
2776
 
            productseries=productseries,
2777
 
            distribution=distribution,
2778
 
            distroseries=distroseries,
2779
 
            sourcepackagename=sourcepackagename,
2780
 
            **non_target_create_params)
 
2737
        create_params = non_target_create_params.copy()
 
2738
        create_params.update(target_key)
 
2739
        bugtask = BugTask(**create_params)
2781
2740
 
2782
 
        if distribution:
 
2741
        if target_key['distribution']:
2783
2742
            # Create tasks for accepted nominations if this is a source
2784
2743
            # package addition.
2785
2744
            accepted_nominations = [
2786
 
                nomination for nomination in bug.getNominations(distribution)
 
2745
                nomination for nomination in
 
2746
                bug.getNominations(target_key['distribution'])
2787
2747
                if nomination.isApproved()]
2788
2748
            for nomination in accepted_nominations:
2789
2749
                accepted_series_task = BugTask(
2790
2750
                    distroseries=nomination.distroseries,
2791
 
                    sourcepackagename=sourcepackagename,
 
2751
                    sourcepackagename=target_key['sourcepackagename'],
2792
2752
                    **non_target_create_params)
2793
2753
                accepted_series_task.updateTargetNameCache()
2794
2754