~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-12-01 14:54:33 UTC
  • mfrom: (14400.2.27 dsp-vocab-unknown-distro)
  • Revision ID: launchpad@pqm.canonical.com-20111201145433-u5ahqdo1rl9mkybh
[r=abentley][bug=889192] DSP vocabulary must handle the case where
 the distribution is not yet known.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
    Item,
18
18
    )
19
19
from lazr.lifecycle.event import ObjectCreatedEvent
20
 
from lazr.restful.interface import copy_field
21
20
from z3c.ptcompat import ViewPageTemplateFile
22
21
from zope.app.form.browser import DropdownWidget
23
22
from zope.app.form.interfaces import MissingInputError
287
286
        else:
288
287
            task_target = data['distribution']
289
288
            if data.get('sourcepackagename') is not None:
290
 
                task_target = task_target.getSourcePackage(
291
 
                    data['sourcepackagename'])
 
289
                spn_or_dsp = data['sourcepackagename']
 
290
                if IDistributionSourcePackage.providedBy(spn_or_dsp):
 
291
                    task_target = spn_or_dsp
 
292
                else:
 
293
                    task_target = task_target.getSourcePackage(spn_or_dsp)
292
294
        self.task_added = self.context.bug.addTask(
293
295
            getUtility(ILaunchBag).user, task_target)
294
296
        task_added = self.task_added
344
346
        self.next_url = canonical_url(task_added)
345
347
 
346
348
 
 
349
class IAddDistroBugTaskForm(IAddBugTaskForm):
 
350
 
 
351
    sourcepackagename = Choice(
 
352
        title=_("Source Package Name"), required=False,
 
353
        description=_("The source package in which the bug occurs. "
 
354
                      "Leave blank if you are not sure."),
 
355
        vocabulary='DistributionSourcePackage')
 
356
 
 
357
 
347
358
class DistroBugTaskCreationStep(BugTaskCreationStep):
348
359
    """Specialized BugTaskCreationStep for reporting a bug in a distribution.
349
360
    """
350
361
 
 
362
    @property
 
363
    def schema(self):
 
364
        if bool(getFeatureFlag('disclosure.dsp_picker.enabled')):
 
365
            return IAddDistroBugTaskForm
 
366
        else:
 
367
            return IAddBugTaskForm
 
368
 
351
369
    custom_widget(
352
370
        'sourcepackagename', BugTaskAlsoAffectsSourcePackageNameWidget)
353
371
 
356
374
    label = "Also affects distribution/package"
357
375
    target_field_names = ('distribution', 'sourcepackagename')
358
376
 
359
 
    def setUpFields(self):
360
 
        super(DistroBugTaskCreationStep, self).setUpFields()
361
 
        if bool(getFeatureFlag('disclosure.dsp_picker.enabled')):
362
 
            # Replace the default field with a field that uses the better
363
 
            # vocabulary.
364
 
            self.form_fields = self.form_fields.omit('sourcepackagename')
365
 
            new_sourcepackagename = copy_field(
366
 
                IAddBugTaskForm['sourcepackagename'],
367
 
                vocabulary='DistributionSourcePackage')
368
 
            self.form_fields += form.Fields(new_sourcepackagename)
369
 
 
370
377
    @property
371
378
    def initial_values(self):
372
379
        """Return the initial values for the view's fields."""
441
448
                distribution.displayname, entered_package,
442
449
                binary_tracking)
443
450
            self.setFieldError('sourcepackagename', error)
444
 
        else:
 
451
        elif not IDistributionSourcePackage.providedBy(sourcepackagename):
445
452
            try:
446
453
                target = distribution
447
454
                if sourcepackagename: