From 574c886d0e13f911140845a13e9d98c5ed5e581b Mon Sep 17 00:00:00 2001 From: Gil Forcada Date: Tue, 5 Jul 2016 23:13:53 +0200 Subject: [PATCH] Use zope.interface decorator This not only makes code more pleasent to read, but also makes the code python 3 compatible (while maintaining python 2 compatibility). --- CHANGES.rst | 3 ++- plone/app/users/browser/account.py | 5 ++--- plone/app/users/browser/schemaeditor.py | 6 +++--- plone/app/users/field_extender.py | 4 ++-- plone/app/users/schema.py | 4 ++-- plone/app/users/vocabularies.py | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 7d9fe20b..37a3b8ce 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,7 +14,8 @@ New features: Bug fixes: -- *add item here* +- Use zope.interface decorator. + [gforcada] 2.3.6 (2016-05-12) diff --git a/plone/app/users/browser/account.py b/plone/app/users/browser/account.py index bd8027a4..d782ed6e 100644 --- a/plone/app/users/browser/account.py +++ b/plone/app/users/browser/account.py @@ -23,7 +23,7 @@ from zope.component import getMultiAdapter from zope.component import getUtility from zope.event import notify -from zope.interface import implements +from zope.interface import implementer MESSAGE_EMAIL_CANNOT_CHANGE = \ @@ -127,10 +127,9 @@ def set_portrait(self, value): portrait = property(get_portrait, set_portrait) +@implementer(IAccountPanelForm) class AccountPanelForm(AutoExtensibleForm, form.Form): """A simple form to be used as a basis for account panel screens.""" - - implements(IAccountPanelForm) schema = IAccountPanelForm template = ViewPageTemplateFile('account-panel.pt') enableCSRFProtection = True diff --git a/plone/app/users/browser/schemaeditor.py b/plone/app/users/browser/schemaeditor.py index 249726ac..2445ae59 100644 --- a/plone/app/users/browser/schemaeditor.py +++ b/plone/app/users/browser/schemaeditor.py @@ -5,7 +5,7 @@ from zope.component import getGlobalSiteManager from zope.component.hooks import getSite from zope.annotation.interfaces import IAnnotations -from zope.interface import Interface, implements +from zope.interface import Interface, implementer from Products.CMFPlone import PloneMessageFactory as _ from Products.CMFPlone.interfaces import IPloneSiteRoot @@ -92,8 +92,8 @@ class SchemaListingPage(FormWrapper): index = ViewPageTemplateFile('schema_layout.pt') +@implementer(IMemberSchemaContext) class MemberSchemaContext(SchemaContext): - implements(IMemberSchemaContext) label = _(u"Edit Member Form Fields") @@ -181,10 +181,10 @@ def get_ttw_edited_schema(): return '' +@implementer(IFieldMetadataHandler) class UsersMetadataSchemaExporter(object): """Support the security: namespace in model definitions. """ - implements(IFieldMetadataHandler) namespace = ns = USERS_NAMESPACE prefix = USERS_PREFIX if_attrs = ( diff --git a/plone/app/users/field_extender.py b/plone/app/users/field_extender.py index 9895a9b1..690a4231 100644 --- a/plone/app/users/field_extender.py +++ b/plone/app/users/field_extender.py @@ -1,4 +1,4 @@ -from zope.interface import Interface, implements +from zope.interface import Interface, implementer from zope import schema from zope.component import adapts @@ -57,8 +57,8 @@ def _set_forms(self, value): forms = property(_get_forms, _set_forms) +@implementer(IFieldMetadataHandler) class UserFormSelectionMetadata(object): - implements(IFieldMetadataHandler) namespace = USERS_NAMESPACE prefix = USERS_PREFIX diff --git a/plone/app/users/schema.py b/plone/app/users/schema.py index ed80d929..cfb4329a 100644 --- a/plone/app/users/schema.py +++ b/plone/app/users/schema.py @@ -5,7 +5,7 @@ from Products.CMFPlone import PloneMessageFactory as _ from zope import schema from zope.component import getUtility -from zope.interface import Interface, implements, implementer +from zope.interface import Interface, implementer, implementer from ZTUtils import make_query from plone.formwidget.namedfile.widget import NamedImageWidget from plone.namedfile.interfaces import INamedImageField @@ -47,8 +47,8 @@ class ProtectedEmail(Email): pass +@implementer(IFieldFactory) class NotEditableFieldFactory(FieldFactory): - implements(IFieldFactory) title = _(u'(protected)') diff --git a/plone/app/users/vocabularies.py b/plone/app/users/vocabularies.py index 9942c1b5..023a2d77 100644 --- a/plone/app/users/vocabularies.py +++ b/plone/app/users/vocabularies.py @@ -4,7 +4,7 @@ from Products.CMFCore.utils import getToolByName from Products.CMFPlone.utils import normalizeString from Products.CMFPlone.utils import safe_unicode -from zope.interface import implements +from zope.interface import implementer from zope.schema import getFieldNames from zope.schema.interfaces import IVocabularyFactory from zope.schema.vocabulary import SimpleVocabulary @@ -19,6 +19,7 @@ JOIN_CONST = ['username', 'password', 'email', 'mail_me'] +@implementer(IVocabularyFactory) class UserRegistrationFieldsVocabulary(object): """Returns list of fields available for registration form. @@ -45,7 +46,6 @@ class UserRegistrationFieldsVocabulary(object): ('email', 'email', 'email') """ - implements(IVocabularyFactory) def __call__(self, context): # default list of Registration Form fields @@ -62,6 +62,7 @@ def __call__(self, context): UserRegistrationFieldsVocabularyFactory = UserRegistrationFieldsVocabulary() +@implementer(IVocabularyFactory) class GroupIdVocabulary(object): """ Return vocab of groups to add new user to. @@ -92,7 +93,6 @@ class GroupIdVocabulary(object): [u'Group Title (fancygroup)', u'Reviewers', u'Site Administrators'] """ - implements(IVocabularyFactory) def __call__(self, context): site = getSite()