236
237
def related_component_groups(self):
237
"""All component groups and components."""
238
"""Return all component groups and components
240
This property was created for the Related components portlet in
241
the bug tracker's page.
238
243
return self.context.getAllRemoteComponentGroups()
241
245
BUG_TRACKER_ACTIVE_VOCABULARY = SimpleVocabulary.fromItems(
242
246
[('On', True), ('Off', False)])
466
470
In this class we assume that bug tracker components are always
467
471
linked to source packages in the Ubuntu distribution.
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)
479
def page_title(self):
481
u'Link a distribution source package to the %s component'
485
def field_names(self):
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)
476
502
def initial_values(self):
477
503
"""See `LaunchpadFormView.`"""
478
field_values = dict(sourcepackagename='')
479
dsp = self.context.distro_source_package
481
field_values['sourcepackagename'] = dsp.name
505
for name in self.field_names:
506
if name == 'sourcepackagename':
507
pkg = self.context.distro_source_package
509
field_values['sourcepackagename'] = pkg.name
511
field_values['sourcepackagename'] = ""
513
field_values[name] = getattr(self.context, name)
482
515
return field_values
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.
491
sourcepackagename = data['sourcepackagename']
492
distribution = self.widgets['sourcepackagename'].getDistribution()
493
dsp = distribution.getSourcePackage(sourcepackagename)
525
context = self.context
528
sourcepackagename = self.request.form.get(
529
self.widgets['sourcepackagename'].name)
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
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))
505
# The submitted component can be linked to the distro source package.
506
component = context or self.context
507
component.distro_source_package = dsp
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))
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)
517
557
self.next_url = canonical_url(
518
558
self.context.component_group.bug_tracker)