Colin Watson has proposed merging
lp:~cjwatson/launchpad/custom-widget-no-class-advice-5 into lp:launchpad.
Commit message:
Finish removing Zope class advice from custom widget registration.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/custom-widget-no-class-advice-5/+merge/354843
--
Your team Launchpad code reviewers is requested to review the proposed merge of
lp:~cjwatson/launchpad/custom-widget-no-class-advice-5 into lp:launchpad.
=== modified file 'lib/lp/app/browser/launchpadform.py'
--- lib/lp/app/browser/launchpadform.py 2018-08-09 14:31:23 +
+++ lib/lp/app/browser/launchpadform.py 2018-09-13 08:25:30 +
@@ -8,7 +8,6 @@
__all__ = [
'action',
-'custom_widget',
'has_structured_doc',
'LaunchpadEditFormView',
'LaunchpadFormView',
@@ -41,7 +40,6 @@
implementer,
providedBy,
)
-from zope.interface.advice import addClassAdvisor
from zope.traversing.interfaces import (
ITraversable,
TraversalError,
@@ -80,8 +78,6 @@
schema = None
# Subset of fields to use
field_names = None
-# Dictionary mapping field names to custom widgets
-custom_widgets = {}
# The next URL to redirect to on successful form submission
next_url = None
@@ -205,8 +201,6 @@
if field.custom_widget is None:
widget = getattr(
self, 'custom_widget_%s' % field.__name__, None)
-if widget is None:
-widget = self.custom_widgets.get(field.__name__)
if widget is not None:
if IWidgetFactory.providedBy(widget):
field.custom_widget = widget
@@ -488,26 +482,6 @@
return was_changed
-class custom_widget:
-"""A class advisor for overriding the default widget for a field."""
-
-def __init__(self, field_name, widget, *args, **kwargs):
-self.field_name = field_name
-if widget is None:
-self.widget = None
-else:
-self.widget = CustomWidgetFactory(widget, *args, **kwargs)
-addClassAdvisor(self.advise)
-
-def advise(self, cls):
-if cls.custom_widgets is None:
-cls.custom_widgets = {}
-else:
-cls.custom_widgets = dict(cls.custom_widgets)
-cls.custom_widgets[self.field_name] = self.widget
-return cls
-
-
def safe_action(action):
"""A decorator used to mark a particular action as 'safe'.
=== modified file 'lib/lp/services/features/browser/edit.py'
--- lib/lp/services/features/browser/edit.py 2013-04-10 08:09:05 +
+++ lib/lp/services/features/browser/edit.py 2018-09-13 08:25:30 +
@@ -1,4 +1,4 @@
-# Copyright 2010 Canonical Ltd. This software is licensed under the
+# Copyright 2010-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""View and edit feature rules."""
@@ -13,13 +13,13 @@
from difflib import unified_diff
import logging
+from zope.formlib.widget import CustomWidgetFactory
from zope.formlib.widgets import TextAreaWidget
from zope.interface import Interface
from zope.schema import Text
from lp.app.browser.launchpadform import (
action,
-custom_widget,
LaunchpadFormView,
)
from lp.app.browser.stringformatter import FormattersAPI
@@ -59,7 +59,7 @@
page_title = label = 'Feature control'
diff = None
logger_name = 'lp.services.features'
-custom_widget('comment', TextAreaWidget, height=2)
+custom_widget_comment = CustomWidgetFactory(TextAreaWidget, height=2)
@property
def field_names(self):
=== modified file 'lib/lp/services/verification/browser/logintoken.py'
--- lib/lp/services/verification/browser/logintoken.py 2018-03-02 16:17:35 +
+++ lib/lp/services/verification/browser/logintoken.py 2018-09-13 08:25:30 +
@@ -1,4 +1,4 @@
-# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
@@ -18,6 +18,7 @@
import urllib
from zope.component import getUtility
+from zope.formlib.widget import CustomWidgetFactory
from zope.formlib.widgets import TextAreaWidget
from zope.interface import (
alsoProvides,
@@ -29,7 +30,6 @@
from lp import _
from lp.app.browser.launchpadform import (
action,
-custom_widget,
LaunchpadEditFormView,
LaunchpadFormView,
)
@@ -176,11 +176,12 @@
'teamowner', 'display_name', 'description', 'membership_policy',
'defaultmembershipperiod', 'renewal_policy', 'defaultrenewalperiod']
label = 'Claim Launchpad team'
-custom_widget('description', TextAreaWidget, height=10, width=30)
-custom_widget(
-'renewal_policy', LaunchpadRadioWidget, orientation='vertical')