~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Curtis Hovey
  • Date: 2011-06-02 21:19:01 UTC
  • mto: This revision was merged to the branch mainline in revision 13177.
  • Revision ID: curtis.hovey@canonical.com-20110602211901-q8hwmzsrnr4qh16y
RemoveĀ unneededĀ runner.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
    IBugTrackerSet,
78
78
    IRemoteBug,
79
79
    )
 
80
from lp.registry.interfaces.distribution import IDistributionSet
80
81
from lp.services.propertycache import cachedproperty
81
82
 
82
83
# A set of bug tracker types for which there can only ever be one bug
234
235
 
235
236
    @property
236
237
    def related_component_groups(self):
237
 
        """All component groups and components."""
 
238
        """Return all component groups and components
 
239
 
 
240
        This property was created for the Related components portlet in
 
241
        the bug tracker's page.
 
242
        """
238
243
        return self.context.getAllRemoteComponentGroups()
239
244
 
240
 
 
241
245
BUG_TRACKER_ACTIVE_VOCABULARY = SimpleVocabulary.fromItems(
242
246
    [('On', True), ('Off', False)])
243
247
 
466
470
    In this class we assume that bug tracker components are always
467
471
    linked to source packages in the Ubuntu distribution.
468
472
    """
 
473
 
469
474
    schema = IBugTrackerComponent
470
 
    custom_widget('sourcepackagename', UbuntuSourcePackageNameWidget)
471
 
    field_names = ['sourcepackagename']
472
 
    label = 'Link a distribution source package to the Example component'
473
 
    page_title = 'Link component'
 
475
    custom_widget('sourcepackagename',
 
476
                  UbuntuSourcePackageNameWidget)
 
477
 
 
478
    @property
 
479
    def page_title(self):
 
480
        return smartquote(
 
481
            u'Link a distribution source package to the %s component'
 
482
            % self.context.name)
 
483
 
 
484
    @property
 
485
    def field_names(self):
 
486
        field_names = [
 
487
            'sourcepackagename',
 
488
            ]
 
489
        return field_names
 
490
 
 
491
    def setUpWidgets(self, context=None):
 
492
        for field in self.form_fields:
 
493
            if (field.custom_widget is None and
 
494
                field.__name__ in self.custom_widgets):
 
495
                field.custom_widget = self.custom_widgets[field.__name__]
 
496
        self.widgets = form.setUpWidgets(
 
497
            self.form_fields, self.prefix, self.context, self.request,
 
498
            data=self.initial_values, adapters=self.adapters,
 
499
            ignore_request=False)
474
500
 
475
501
    @property
476
502
    def initial_values(self):
477
503
        """See `LaunchpadFormView.`"""
478
 
        field_values = dict(sourcepackagename='')
479
 
        dsp = self.context.distro_source_package
480
 
        if dsp is not None:
481
 
            field_values['sourcepackagename'] = dsp.name
 
504
        field_values = {}
 
505
        for name in self.field_names:
 
506
            if name == 'sourcepackagename':
 
507
                pkg = self.context.distro_source_package
 
508
                if pkg is not None:
 
509
                    field_values['sourcepackagename'] = pkg.name
 
510
                else:
 
511
                    field_values['sourcepackagename'] = ""
 
512
            else:
 
513
                field_values[name] = getattr(self.context, name)
 
514
 
482
515
        return field_values
483
516
 
484
517
    def updateContextFromData(self, data, context=None):
488
521
        look it up in Ubuntu to retrieve the distro_source_package
489
522
        object, and link it to this component.
490
523
        """
491
 
        sourcepackagename = data['sourcepackagename']
492
 
        distribution = self.widgets['sourcepackagename'].getDistribution()
493
 
        dsp = distribution.getSourcePackage(sourcepackagename)
 
524
        if context is None:
 
525
            context = self.context
 
526
        component = context
 
527
 
 
528
        sourcepackagename = self.request.form.get(
 
529
            self.widgets['sourcepackagename'].name)
 
530
 
 
531
        distro_name = self.widgets['sourcepackagename'].distribution_name
 
532
        distribution = getUtility(IDistributionSet).getByName(distro_name)
 
533
        pkg = distribution.getSourcePackage(sourcepackagename)
494
534
        bug_tracker = self.context.component_group.bug_tracker
 
535
 
495
536
        # Has this source package already been assigned to a component?
496
 
        component = bug_tracker.getRemoteComponentForDistroSourcePackage(
497
 
            distribution.name, sourcepackagename.name)
498
 
        if component is not None:
 
537
        link_comp = bug_tracker.getRemoteComponentForDistroSourcePackage(
 
538
            distro_name, sourcepackagename)
 
539
        if link_comp is not None:
499
540
            self.request.response.addNotification(
500
541
                "The %s source package is already linked to %s:%s in %s" % (
501
 
                    sourcepackagename.name,
502
 
                    component.component_group.name,
503
 
                    component.name, distribution.name))
 
542
                    sourcepackagename, link_comp.component_group.name,
 
543
                    link_comp.name, distro_name))
504
544
            return
505
 
        # The submitted component can be linked to the distro source package.
506
 
        component = context or self.context
507
 
        component.distro_source_package = dsp
 
545
 
 
546
        component.distro_source_package = pkg
508
547
        self.request.response.addNotification(
509
548
            "%s:%s is now linked to the %s source package in %s" % (
510
549
                component.component_group.name, component.name,
511
 
                sourcepackagename.name, distribution.name))
 
550
                sourcepackagename, distro_name))
512
551
 
513
552
    @action('Save Changes', name='save')
514
553
    def save_action(self, action, data):
515
554
        """Update the component with the form data."""
516
555
        self.updateContextFromData(data)
 
556
 
517
557
        self.next_url = canonical_url(
518
558
            self.context.component_group.bug_tracker)
519
559