def __init__(self, field, vocabulary, request): RadioWidget.__init__(self, field, vocabulary, request) self.url_widget = CustomWidgetFactory(URIWidget) setUpWidget( self, 'url', BugWatchEditForm['url'], IInputWidget, context=field.context) self.setUpJavascript()
def __init__(self, field, vocabulary, request): RadioWidget.__init__(self, field, vocabulary, request) self.url_widget = CustomWidgetFactory(URIWidget) setUpWidget(self, 'url', BugWatchEditForm['url'], IInputWidget, context=field.context) self.setUpJavascript()
def _toFieldValue(self, form_value): """Convert the textual token to a field value. If the form value is _new_bugwatch_value, create a new bug watch, otherwise look up an existing one. """ if form_value == self._new_bugwatch_value: try: url = self.url_widget.getInputValue() bugtracker, remote_bug = getUtility( IBugWatchSet).extractBugTrackerAndBug(url) bugtask = self.context.context return bugtask.bug.addWatch(bugtracker, remote_bug, getUtility(ILaunchBag).user) except WidgetInputError as error: # Prefix the error with the widget name, since the error # will be display at the top of the page, and not right # next to the widget. raise WidgetInputError(self.context.__name__, self.label, 'Remote Bug: %s' % error.doc()) except (NoBugTrackerFound, UnrecognizedBugTrackerURL) as error: raise WidgetInputError(self.context.__name__, self.label, 'Invalid bug tracker URL.') else: return RadioWidget._toFieldValue(self, form_value)
def _toFieldValue(self, form_value): """Convert the textual token to a field value. If the form value is _new_bugwatch_value, create a new bug watch, otherwise look up an existing one. """ if form_value == self._new_bugwatch_value: try: url = self.url_widget.getInputValue() bugtracker, remote_bug = getUtility( IBugWatchSet).extractBugTrackerAndBug(url) bugtask = self.context.context return bugtask.bug.addWatch( bugtracker, remote_bug, getUtility(ILaunchBag).user) except WidgetInputError as error: # Prefix the error with the widget name, since the error # will be display at the top of the page, and not right # next to the widget. raise WidgetInputError( self.context.__name__, self.label, 'Remote Bug: %s' % error.doc()) except (NoBugTrackerFound, UnrecognizedBugTrackerURL) as error: raise WidgetInputError( self.context.__name__, self.label, 'Invalid bug tracker URL.') else: return RadioWidget._toFieldValue(self, form_value)
def BooleanRadioWidget(field, request, true=_('on'), false=_('off')): vocabulary = SimpleVocabulary.fromItems( ((true, True), (false, False)) ) widget = RadioWidget(field, vocabulary, request) widget.required = False return widget
def setPrefix(self, prefix): RadioWidget.setPrefix(self, prefix) self.url_widget.setPrefix(prefix) self.setUpJavascript()
def BooleanRadioWidget(field, request, true=_('on'), false=_('off')): vocabulary = SimpleVocabulary.fromItems(((true, True), (false, False))) widget = RadioWidget(field, vocabulary, request) widget.required = False return widget