launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #19328
Re: [Merge] lp:~cjwatson/launchpad/snap-canonicalise-git-path into lp:launchpad
Diff comments:
> === modified file 'lib/lp/app/templates/launchpad-widget-macros.pt'
> --- lib/lp/app/templates/launchpad-widget-macros.pt 2013-04-22 06:20:18 +0000
> +++ lib/lp/app/templates/launchpad-widget-macros.pt 2015-09-09 14:30:28 +0000
> @@ -29,7 +29,7 @@
> tal:define="error widget/error">
>
> <label tal:attributes="for widget/name"
> - tal:content="widget/label">Label</label>
> + tal:content="string:${widget/label}:">Label</label>
>
> <span tal:condition="widget/required"
> class="fieldRequired"
This change is consistent with how labels are handled in launchpad-form.pt. Most templates use launchpad-form rather than launchpad-widget-macros, but widgets don't implement most of the view methods that those macros need. All other widgets either use another bit of launchpad-widget-macros (display_raw_widget further down) or else write out the equivalent by hand. Neither was very appealing here.
>
> === added file 'lib/lp/code/browser/widgets/gitref.py'
> --- lib/lp/code/browser/widgets/gitref.py 1970-01-01 00:00:00 +0000
> +++ lib/lp/code/browser/widgets/gitref.py 2015-09-09 14:30:28 +0000
> @@ -0,0 +1,129 @@
> +# Copyright 2015 Canonical Ltd. This software is licensed under the
> +# GNU Affero General Public License version 3 (see the file LICENSE).
> +
> +__metaclass__ = type
> +
> +__all__ = [
> + 'GitRefWidget',
> + ]
> +
> +from z3c.ptcompat import ViewPageTemplateFile
> +from zope.formlib.interfaces import (
> + ConversionError,
> + IInputWidget,
> + MissingInputError,
> + WidgetInputError,
> + )
> +from zope.formlib.utility import setUpWidget
> +from zope.formlib.widget import (
> + BrowserWidget,
> + InputErrors,
> + InputWidget,
> + )
> +from zope.interface import implementer
> +from zope.schema import (
> + Choice,
> + TextLine,
> + )
> +
> +from lp.app.errors import UnexpectedFormData
> +from lp.app.validators import LaunchpadValidationError
> +from lp.services.webapp.interfaces import (
> + IAlwaysSubmittedWidget,
> + IMultiLineWidgetLayout,
> + )
> +
> +
> +@implementer(IMultiLineWidgetLayout, IAlwaysSubmittedWidget, IInputWidget)
> +class GitRefWidget(BrowserWidget, InputWidget):
> +
> + template = ViewPageTemplateFile("templates/gitref.pt")
> + display_label = False
> + _widgets_set_up = False
> +
> + def setUpSubWidgets(self):
> + if self._widgets_set_up:
> + return
> + fields = [
> + Choice(
> + __name__="repository", title=u"Git repository",
> + required=False, vocabulary="GitRepository"),
> + TextLine(
> + __name__="path", title=u"Git branch path", required=False),
I've made that change, although I'm not sure if it will always work well given that "Git branch" is also a relatively sensible way to refer to an entire GitRef in user-facing text. We'll see.
> + ]
> + for field in fields:
> + setUpWidget(
> + self, field.__name__, field, IInputWidget, prefix=self.name)
> + self._widgets_set_up = True
> +
> + def setRenderedValue(self, value):
> + """See `IWidget`."""
> + self.setUpSubWidgets()
> + if value is not None:
> + self.repository_widget.setRenderedValue(value.repository)
> + self.path_widget.setRenderedValue(value.path)
> + else:
> + self.repository_widget.setRenderedValue(None)
> + self.path_widget.setRenderedValue(None)
> +
> + def hasInput(self):
> + """See `IInputWidget`."""
> + return (
> + ("%s.repository" % self.name) in self.request.form or
> + ("%s.path" % self.name) in self.request.form)
> +
> + def hasValidInput(self):
> + """See `IInputWidget`."""
> + try:
> + self.getInputValue()
> + return True
> + except (InputErrors, UnexpectedFormData):
> + return False
> +
> + def getInputValue(self):
> + """See `IInputWidget`."""
> + self.setUpSubWidgets()
> + try:
> + repository = self.repository_widget.getInputValue()
> + except MissingInputError:
> + raise WidgetInputError(
> + self.name, self.label,
> + LaunchpadValidationError("Please choose a Git repository."))
> + except ConversionError:
> + entered_name = self.request.form_ng.getOne(
> + "%s.repository" % self.name)
> + raise WidgetInputError(
> + self.name, self.label,
> + LaunchpadValidationError(
> + "There is no Git repository named '%s' registered in "
> + "Launchpad." % entered_name))
> + if self.path_widget.hasInput():
> + path = self.path_widget.getInputValue()
> + else:
> + path = None
> + if not path:
> + raise WidgetInputError(
> + self.name, self.label,
> + LaunchpadValidationError("Please enter a Git branch path."))
> + ref = repository.getRefByPath(path)
> + if ref is None:
> + raise WidgetInputError(
> + self.name, self.label,
> + LaunchpadValidationError(
> + "The repository at %s does not contain a branch named "
> + "'%s'." % (repository.display_name, path)))
> + return ref
> +
> + def error(self):
> + """See `IBrowserWidget`."""
> + try:
> + if self.hasInput():
> + self.getInputValue()
> + except InputErrors as error:
> + self._error = error
> + return super(GitRefWidget, self).error()
> +
> + def __call__(self):
> + """See `IBrowserWidget`."""
> + self.setUpSubWidgets()
> + return self.template()
--
https://code.launchpad.net/~cjwatson/launchpad/snap-canonicalise-git-path/+merge/270543
Your team Launchpad code reviewers is subscribed to branch lp:launchpad.
References