← Back to team overview

launchpad-reviewers team mailing list archive

Re: [Merge] lp:~cjwatson/launchpad/snap-build-channels-ui into lp:launchpad

 

Review: Approve code



Diff comments:

> === modified file 'lib/lp/snappy/browser/snap.py'
> --- lib/lp/snappy/browser/snap.py	2018-04-21 10:01:22 +0000
> +++ lib/lp/snappy/browser/snap.py	2018-04-30 16:52:16 +0000
> @@ -512,6 +531,7 @@
>              auto_build=data['auto_build'],
>              auto_build_archive=data['auto_build_archive'],
>              auto_build_pocket=data['auto_build_pocket'],
> +            auto_build_channels=data.get('auto_build_channels'),

Won't the field always be present after cleaning?

>              processors=data['processors'], private=private,
>              build_source_tarball=data['build_source_tarball'],
>              store_upload=data['store_upload'],
> 
> === added file 'lib/lp/snappy/browser/widgets/snapbuildchannels.py'
> --- lib/lp/snappy/browser/widgets/snapbuildchannels.py	1970-01-01 00:00:00 +0000
> +++ lib/lp/snappy/browser/widgets/snapbuildchannels.py	2018-04-30 16:52:16 +0000
> @@ -0,0 +1,99 @@
> +# Copyright 2018 Canonical Ltd.  This software is licensed under the
> +# GNU Affero General Public License version 3 (see the file LICENSE).
> +
> +"""XXX: Module docstring goes here."""

Indeed.

> +
> +from __future__ import absolute_import, print_function, unicode_literals
> +
> +__metaclass__ = type
> +__all__ = [
> +    'SnapBuildChannelsWidget',
> +    ]
> +
> +from z3c.ptcompat import ViewPageTemplateFile
> +from zope.formlib.interfaces import IInputWidget
> +from zope.formlib.utility import setUpWidget
> +from zope.formlib.widget import (
> +    BrowserWidget,
> +    InputErrors,
> +    InputWidget,
> +    )
> +from zope.interface import implementer
> +from zope.schema import TextLine
> +from zope.security.proxy import isinstance as zope_isinstance
> +
> +from lp.app.errors import UnexpectedFormData
> +from lp.services.webapp.interfaces import (
> +    IAlwaysSubmittedWidget,
> +    ISingleLineWidgetLayout,
> +    )
> +
> +
> +@implementer(ISingleLineWidgetLayout, IAlwaysSubmittedWidget, IInputWidget)
> +class SnapBuildChannelsWidget(BrowserWidget, InputWidget):
> +
> +    template = ViewPageTemplateFile("templates/snapbuildchannels.pt")
> +    hint = False
> +    snap_names = ["core", "snapcraft"]
> +    _widgets_set_up = False
> +
> +    def setUpSubWidgets(self):
> +        if self._widgets_set_up:
> +            return
> +        fields = [
> +            TextLine(
> +                __name__=snap_name, title="%s channel" % snap_name,
> +                required=False)
> +            for snap_name in self.snap_names
> +            ]
> +        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 not zope_isinstance(value, dict):
> +            value = {}
> +        self.core_widget.setRenderedValue(value.get("core"))
> +        self.snapcraft_widget.setRenderedValue(value.get("snapcraft"))
> +
> +    def hasInput(self):
> +        """See `IInputWidget`."""
> +        return any(
> +            "%s.%s" % (self.name, snap_name) in self.request.form
> +            for snap_name in self.snap_names)
> +
> +    def hasValidInput(self):
> +        """See `IInputWidget`."""
> +        try:
> +            self.getInputValue()
> +            return True
> +        except (InputErrors, UnexpectedFormData):
> +            return False
> +
> +    def getInputValue(self):
> +        """See `IInputWidget`."""
> +        self.setUpSubWidgets()
> +        channels = {}
> +        for snap_name in self.snap_names:
> +            widget = getattr(self, snap_name + "_widget")
> +            channel = widget.getInputValue()
> +            if channel:
> +                channels[snap_name] = channel
> +        return channels
> +
> +    def error(self):
> +        """See `IBrowserWidget`."""
> +        try:
> +            if self.hasInput():
> +                self.getInputValue()
> +        except InputErrors as error:
> +            self._error = error
> +        return super(SnapBuildChannelsWidget, self).error()
> +
> +    def __call__(self):
> +        """See `IBrowserWidget`."""
> +        self.setUpSubWidgets()
> +        return self.template()


-- 
https://code.launchpad.net/~cjwatson/launchpad/snap-build-channels-ui/+merge/344859
Your team Launchpad code reviewers is subscribed to branch lp:launchpad.


References