LaunchpadRadioWidget ==================== There are two Launchpad radio widgets, one that shows descriptions, and one that doesn't. >>> from lp.app.widgets.itemswidgets import ( ... LaunchpadRadioWidget, LaunchpadRadioWidgetWithDescription) The LaunchpadRadioWidget is mostly used to display items from an enumerated type. >>> from BeautifulSoup import BeautifulSoup >>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest >>> from lp.code.interfaces.branch import IBranch >>> branch = factory.makeAnyBranch() >>> branch_type_field = IBranch['branch_type'].bind(branch) >>> request = LaunchpadTestRequest() >>> radio_widget = LaunchpadRadioWidget( ... branch_type_field, branch_type_field.vocabulary, request) >>> radio_widget.setRenderedValue(branch_type_field.vocabulary.HOSTED) The widget is rendered as a collection of labels with the radio buttons inside. >>> html = BeautifulSoup(radio_widget()) >>> for label in html.findAll('label'): ... print label.renderContents()  Hosted  Mirrored  Imported  Remote LaunchpadRadioWidgetWithDescription ----------------------------------- The LaunchpadRadioWidgetWithDescription widget renders the descriptions along with the titles from the enumerated type vocabulary. >>> radio_widget = LaunchpadRadioWidgetWithDescription( ... branch_type_field, branch_type_field.vocabulary, request) >>> radio_widget.setRenderedValue(branch_type_field.vocabulary.HOSTED) The widget is rendered in a table with the descriptions lined up under the labels. The labels are rendered next to the radio buttons, in a different table cell, and use the 'for' attribute of the label to associate the label with the radio button input. >>> print radio_widget()
Launchpad is the primary location of this branch.
Primarily hosted elsewhere and is periodically mirrored from the external location into Launchpad.
Branches that have been imported from an externally hosted branch in bzr or another VCS and are made available through Launchpad.
Registered in Launchpad with an external location, but is not to be mirrored, nor available through Launchpad.
If the enumerated type doesn't have any descriptions, then the extra rows are not rendered. >>> from lazr.enum import EnumeratedType, Item >>> class SomeFruit(EnumeratedType): ... "A choice of fruit." ... APPLE = Item('Apple') ... PEAR = Item('Pear') ... ORANGE = Item('Orange') >>> radio_widget = LaunchpadRadioWidgetWithDescription( ... branch_type_field, SomeFruit, request) >>> print radio_widget()
LaunchpadBooleanRadioWidget --------------------------- The LaunchpadBooleanRadioWidget renders a boolean field as radio buttons. This widget is uses the LaunchpadRadioWidget to render the items. The values are rendered as 'yes' and 'no'; a missing value radio item is not rendered. >>> from zope.schema import Bool >>> from lp.app.widgets.itemswidgets import LaunchpadBooleanRadioWidget >>> field = Bool( ... __name__='sentient', ... title=u"Are you sentient?", ... description=u"Are you human or a bot?", ... required=False, readonly=False, default=True) >>> class Agent: ... def __init__(self, sentient): ... self.sentient = sentient >>> agent = Agent(True) >>> bound_field = field.bind(agent) >>> radio_widget = LaunchpadBooleanRadioWidget(bound_field, request) >>> print radio_widget()
The labels for True and False values can be set using the true_label and false_label attributes. >>> radio_widget.true_label = 'I think therefore I am' >>> radio_widget.false_label = 'I am a turing test' >>> print radio_widget()