~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/browser/bugalsoaffects.py

  • Committer: Steve Kowalik
  • Date: 2011-07-26 23:37:30 UTC
  • mfrom: (13528 devel)
  • mto: This revision was merged to the branch mainline in revision 13536.
  • Revision ID: stevenk@ubuntu.com-20110726233730-mh04vxxvth98z9ps
Merge devel, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
from lazr.lifecycle.event import ObjectCreatedEvent
17
17
from z3c.ptcompat import ViewPageTemplateFile
18
18
from zope.app.form.browser import DropdownWidget
19
 
from zope.app.form.interfaces import (
20
 
    MissingInputError,
21
 
    WidgetsError,
22
 
    )
 
19
from zope.app.form.interfaces import MissingInputError
23
20
from zope.component import getUtility
24
21
from zope.event import notify
25
22
from zope.formlib import form
34
31
    MultiStepView,
35
32
    StepView,
36
33
    )
37
 
from canonical.launchpad.interfaces.validation import (
38
 
    valid_upstreamtask,
39
 
    validate_new_distrotask,
40
 
    )
41
34
from canonical.launchpad.webapp import canonical_url
42
35
from canonical.launchpad.webapp.interfaces import ILaunchBag
43
36
from canonical.launchpad.webapp.menu import structured
62
55
    BugTaskStatus,
63
56
    IAddBugTaskForm,
64
57
    IAddBugTaskWithProductCreationForm,
 
58
    IllegalTarget,
65
59
    valid_remote_bug_url,
66
60
    )
67
61
from lp.bugs.interfaces.bugtracker import (
73
67
    NoBugTrackerFound,
74
68
    UnrecognizedBugTrackerURL,
75
69
    )
 
70
from lp.bugs.model.bugtask import (
 
71
    validate_new_target,
 
72
    validate_target,
 
73
    )
76
74
from lp.registry.interfaces.distributionsourcepackage import (
77
75
    IDistributionSourcePackage,
78
76
    )
157
155
        upstream = bugtask.target.upstream_product
158
156
        if upstream is not None:
159
157
            try:
160
 
                valid_upstreamtask(bugtask.bug, upstream)
161
 
            except WidgetsError:
 
158
                validate_target(bugtask.bug, upstream)
 
159
            except IllegalTarget:
162
160
                # There is already a task for the upstream.
163
161
                pass
164
162
            else:
173
171
    def validateStep(self, data):
174
172
        if data.get('product'):
175
173
            try:
176
 
                valid_upstreamtask(self.context.bug, data.get('product'))
177
 
            except WidgetsError, errors:
178
 
                for error in errors:
179
 
                    self.setFieldError('product', error.snippet())
 
174
                validate_target(self.context.bug, data.get('product'))
 
175
            except IllegalTarget as e:
 
176
                self.setFieldError('product', e[0])
180
177
            return
181
178
 
182
179
        entered_product = self.request.form.get(self.widgets['product'].name)
431
428
            self.setFieldError('sourcepackagename', error)
432
429
        else:
433
430
            try:
434
 
                validate_new_distrotask(
435
 
                    self.context.bug, distribution, sourcepackagename)
436
 
            except LaunchpadValidationError, error:
437
 
                self.setFieldError('sourcepackagename', error.snippet())
 
431
                target = distribution
 
432
                if sourcepackagename:
 
433
                    target = target.getSourcePackage(sourcepackagename)
 
434
                validate_new_target(self.context.bug, target)
 
435
            except IllegalTarget as e:
 
436
                self.setFieldError('sourcepackagename', e[0])
438
437
 
439
438
        super(DistroBugTaskCreationStep, self).validateStep(data)
440
439
 
659
658
 
660
659
        if not target.bugtracker:
661
660
            return None
662
 
        else:
663
 
            bug = self.context.bug
664
 
            title = bug.title
665
 
            description = u"Originally reported at:\n  %s\n\n%s" % (
666
 
                canonical_url(bug), bug.description)
667
 
            return target.bugtracker.getBugFilingAndSearchLinks(
668
 
                target.remote_product, title, description)
 
661
 
 
662
        bug = self.context.bug
 
663
        title = bug.title
 
664
        description = u"Originally reported at:\n  %s\n\n%s" % (
 
665
            canonical_url(bug), bug.description)
 
666
        return target.bugtracker.getBugFilingAndSearchLinks(
 
667
            target.remote_product, title, description)
669
668
 
670
669
 
671
670
class BugTrackerCreationStep(AlsoAffectsStep):
812
811
        self._validate(action, data)
813
812
        project = data.get('existing_product')
814
813
        try:
815
 
            valid_upstreamtask(self.context.bug, project)
816
 
        except WidgetsError, errors:
817
 
            for error in errors:
818
 
                self.setFieldError('existing_product', error.snippet())
 
814
            validate_target(self.context.bug, project)
 
815
        except IllegalTarget as e:
 
816
            self.setFieldError('existing_product', e[0])
819
817
 
820
818
    @action('Use Existing Project', name='use_existing_product',
821
819
            validator=validate_existing_product)