445
455
return RemoteBug(self.context, remotebug, bugs)
447
457
@stepthrough("+components")
448
def component_groups(self, name):
449
return self.context.getRemoteComponentGroup(name)
458
def component_groups(self, id):
459
# Navigate by id (component group name should work too)
460
return self.context.getRemoteComponentGroup(id)
463
class BugTrackerEditComponentView(LaunchpadEditFormView):
464
"""Provides editing form for setting source packages for components.
466
In this class we assume that bug tracker components are always
467
linked to source packages in the Ubuntu distribution.
469
schema = IBugTrackerComponent
470
custom_widget('sourcepackagename', UbuntuSourcePackageNameWidget)
471
field_names = ['sourcepackagename']
472
page_title = 'Link component'
477
'Link a distribution source package to %s component' %
481
def initial_values(self):
482
"""See `LaunchpadFormView.`"""
483
field_values = dict(sourcepackagename='')
484
dsp = self.context.distro_source_package
486
field_values['sourcepackagename'] = dsp.name
491
return canonical_url(self.context.component_group.bug_tracker)
493
cancel_url = next_url
495
def updateContextFromData(self, data, context=None):
496
"""Link component to specified distro source package.
498
Get the user-provided source package name from the form widget,
499
look it up in Ubuntu to retrieve the distro_source_package
500
object, and link it to this component.
502
sourcepackagename = data['sourcepackagename']
503
distribution = self.widgets['sourcepackagename'].getDistribution()
504
dsp = distribution.getSourcePackage(sourcepackagename)
505
bug_tracker = self.context.component_group.bug_tracker
506
# Has this source package already been assigned to a component?
507
component = bug_tracker.getRemoteComponentForDistroSourcePackageName(
508
distribution, sourcepackagename)
509
if component is not None:
510
self.request.response.addNotification(
511
"The %s source package is already linked to %s:%s in %s." % (
512
sourcepackagename.name,
513
component.component_group.name,
514
component.name, distribution.name))
516
# The submitted component can be linked to the distro source package.
517
component = context or self.context
518
component.distro_source_package = dsp
519
if sourcepackagename is None:
520
self.request.response.addNotification(
521
"%s:%s is now unlinked." % (
522
component.component_group.name, component.name))
524
self.request.response.addNotification(
525
"%s:%s is now linked to the %s source package in %s." % (
526
component.component_group.name, component.name,
527
sourcepackagename.name, distribution.name))
529
@action('Save Changes', name='save')
530
def save_action(self, action, data):
531
"""Update the component with the form data."""
532
self.updateContextFromData(data)
452
535
class BugTrackerComponentGroupNavigation(Navigation):
454
537
usedfor = IBugTrackerComponentGroup
456
def traverse(self, name):
457
return self.context.getComponent(name)
539
def traverse(self, id):
540
return self.context.getComponent(id)
460
543
class BugTrackerSetBreadcrumb(Breadcrumb):