Merge pull request #108 from plone/gforcada-use-zope-decorators

Use zope.interface decorator
This commit is contained in:
Gil Forcada Codinachs 2016-07-09 08:50:52 +02:00 committed by GitHub
commit edbca5d71e
8 changed files with 19 additions and 25 deletions

View File

@ -14,7 +14,8 @@ New features:
Bug fixes: Bug fixes:
- *add item here* - Use zope.interface decorator.
[gforcada]
2.4.16 (2016-06-27) 2.4.16 (2016-06-27)

View File

@ -18,10 +18,10 @@ from zope.interface import Interface
from zope.publisher.interfaces.browser import IDefaultBrowserLayer from zope.publisher.interfaces.browser import IDefaultBrowserLayer
@interface.implementer(ICaptcha)
class Captcha(Persistent): class Captcha(Persistent):
"""Captcha input field. """Captcha input field.
""" """
interface.implements(ICaptcha)
adapts(Comment) adapts(Comment)
captcha = u"" captcha = u""

View File

@ -6,13 +6,14 @@ into an actual comment object.
from plone.app.discussion.interfaces import IConversation from plone.app.discussion.interfaces import IConversation
from zope.component import adapts from zope.component import adapts
from zope.component import queryAdapter from zope.component import queryAdapter
from zope.interface import implements from zope.interface import implementer
from zope.interface import Interface from zope.interface import Interface
from zope.publisher.interfaces.browser import IBrowserRequest from zope.publisher.interfaces.browser import IBrowserRequest
from zope.traversing.interfaces import ITraversable from zope.traversing.interfaces import ITraversable
from zope.traversing.interfaces import TraversalError from zope.traversing.interfaces import TraversalError
@implementer(ITraversable)
class ConversationNamespace(object): class ConversationNamespace(object):
"""Allow traversal into a conversation via a ++conversation++name """Allow traversal into a conversation via a ++conversation++name
namespace. The name is the name of an adapter from context to namespace. The name is the name of an adapter from context to
@ -20,8 +21,6 @@ class ConversationNamespace(object):
(unnamed) adapter. This is to work around a bug in OFS.Traversable which (unnamed) adapter. This is to work around a bug in OFS.Traversable which
does not allow traversal to namespaces with an empty string name. does not allow traversal to namespaces with an empty string name.
""" """
implements(ITraversable)
adapts(Interface, IBrowserRequest) adapts(Interface, IBrowserRequest)
def __init__(self, context, request=None): def __init__(self, context, request=None):

View File

@ -11,7 +11,7 @@ from z3c.form.interfaces import IValidator
from zope.component import adapts from zope.component import adapts
from zope.component import getMultiAdapter from zope.component import getMultiAdapter
from zope.component import queryUtility from zope.component import queryUtility
from zope.interface import implements from zope.interface import implementer
from zope.interface import Interface from zope.interface import Interface
from zope.schema.interfaces import IField from zope.schema.interfaces import IField
@ -32,8 +32,8 @@ except ImportError:
pass pass
@implementer(IValidator)
class CaptchaValidator(validator.SimpleFieldValidator): class CaptchaValidator(validator.SimpleFieldValidator):
implements(IValidator)
adapts(Interface, IDiscussionLayer, Interface, IField, Interface) adapts(Interface, IDiscussionLayer, Interface, IField, Interface)
# Object, Request, Form, Field, Widget, # Object, Request, Form, Field, Widget,
# We adapt the CaptchaValidator class to all form fields (IField) # We adapt the CaptchaValidator class to all form fields (IField)

View File

@ -35,7 +35,7 @@ from zope.component.factory import Factory
from zope.event import notify from zope.event import notify
from zope.i18n import translate from zope.i18n import translate
from zope.i18nmessageid import Message from zope.i18nmessageid import Message
from zope.interface import implements from zope.interface import implementer
import logging import logging
@ -65,6 +65,7 @@ MAIL_NOTIFICATION_MESSAGE_MODERATOR = _(
logger = logging.getLogger('plone.app.discussion') logger = logging.getLogger('plone.app.discussion')
@implementer(IComment)
class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable, class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
RoleManager, Owned, Implicit, Persistent): RoleManager, Owned, Implicit, Persistent):
"""A comment. """A comment.
@ -73,8 +74,6 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
number of standard methods instead of subclassing, to have total control number of standard methods instead of subclassing, to have total control
over what goes into the object. over what goes into the object.
""" """
implements(IComment)
security = ClassSecurityInfo() security = ClassSecurityInfo()
meta_type = portal_type = 'Discussion Item' meta_type = portal_type = 'Discussion Item'

View File

@ -34,7 +34,6 @@ from zope.component import adapts
from zope.container.contained import ContainerModifiedEvent from zope.container.contained import ContainerModifiedEvent
from zope.event import notify from zope.event import notify
from zope.interface import implementer from zope.interface import implementer
from zope.interface import implements
from zope.lifecycleevent import ObjectAddedEvent from zope.lifecycleevent import ObjectAddedEvent
from zope.lifecycleevent import ObjectCreatedEvent from zope.lifecycleevent import ObjectCreatedEvent
from zope.lifecycleevent import ObjectRemovedEvent from zope.lifecycleevent import ObjectRemovedEvent
@ -42,6 +41,7 @@ from zope.lifecycleevent import ObjectRemovedEvent
import time import time
@implementer(IConversation, IHideFromBreadcrumbs)
class Conversation(Traversable, Persistent, Explicit): class Conversation(Traversable, Persistent, Explicit):
"""A conversation is a container for all comments on a content object. """A conversation is a container for all comments on a content object.
@ -49,8 +49,6 @@ class Conversation(Traversable, Persistent, Explicit):
comment lookup. comment lookup.
""" """
implements(IConversation, IHideFromBreadcrumbs)
__allow_access_to_unprotected_subobjects__ = True __allow_access_to_unprotected_subobjects__ = True
def __init__(self, id='++conversation++default'): def __init__(self, id='++conversation++default'):
@ -327,13 +325,12 @@ else:
return conversationAdapterFactory(content) return conversationAdapterFactory(content)
@implementer(IReplies)
class ConversationReplies(object): class ConversationReplies(object):
"""An IReplies adapter for conversations. """An IReplies adapter for conversations.
This makes it easy to work with top-level comments. This makes it easy to work with top-level comments.
""" """
implements(IReplies)
adapts(Conversation) # relies on implementation details adapts(Conversation) # relies on implementation details
def __init__(self, context): def __init__(self, context):
@ -404,14 +401,13 @@ class ConversationReplies(object):
return self.conversation._children.get(self.comment_id, LLSet()) return self.conversation._children.get(self.comment_id, LLSet())
@implementer(IReplies)
class CommentReplies(ConversationReplies): class CommentReplies(ConversationReplies):
"""An IReplies adapter for comments. """An IReplies adapter for comments.
This makes it easy to work with replies to specific comments. This makes it easy to work with replies to specific comments.
""" """
implements(IReplies)
# depends on implementation details of conversation # depends on implementation details of conversation
# most likely, anyone writing a different type of Conversation will also # most likely, anyone writing a different type of Conversation will also
# have a different type of Comment # have a different type of Comment

View File

@ -6,13 +6,13 @@ from plone.app.discussion.interfaces import ICommentRemovedEvent
from plone.app.discussion.interfaces import IDiscussionEvent from plone.app.discussion.interfaces import IDiscussionEvent
from plone.app.discussion.interfaces import IReplyAddedEvent from plone.app.discussion.interfaces import IReplyAddedEvent
from plone.app.discussion.interfaces import IReplyRemovedEvent from plone.app.discussion.interfaces import IReplyRemovedEvent
from zope.interface import implements from zope.interface import implementer
@implementer(IDiscussionEvent)
class DiscussionEvent(object): class DiscussionEvent(object):
""" Custom event """ Custom event
""" """
implements(IDiscussionEvent)
def __init__(self, context, comment, **kwargs): def __init__(self, context, comment, **kwargs):
self.object = context self.object = context
@ -26,25 +26,25 @@ class DiscussionEvent(object):
request.set('event', self) request.set('event', self)
@implementer(ICommentAddedEvent)
class CommentAddedEvent(DiscussionEvent): class CommentAddedEvent(DiscussionEvent):
""" Event to be triggered when a Comment is added """ Event to be triggered when a Comment is added
""" """
implements(ICommentAddedEvent)
@implementer(ICommentRemovedEvent)
class CommentRemovedEvent(DiscussionEvent): class CommentRemovedEvent(DiscussionEvent):
""" Event to be triggered when a Comment is removed """ Event to be triggered when a Comment is removed
""" """
implements(ICommentRemovedEvent)
@implementer(IReplyAddedEvent)
class ReplyAddedEvent(DiscussionEvent): class ReplyAddedEvent(DiscussionEvent):
""" Event to be triggered when a Comment reply is added """ Event to be triggered when a Comment reply is added
""" """
implements(IReplyAddedEvent)
@implementer(IReplyRemovedEvent)
class ReplyRemovedEvent(DiscussionEvent): class ReplyRemovedEvent(DiscussionEvent):
""" Event to be triggered when a Comment reply is removed """ Event to be triggered when a Comment reply is removed
""" """
implements(IReplyRemovedEvent)

View File

@ -14,10 +14,9 @@ from zope import interface
from zope.component import queryUtility from zope.component import queryUtility
@interface.implementer(ICommentingTool)
class CommentingTool(UniqueObject, SimpleItem): class CommentingTool(UniqueObject, SimpleItem):
interface.implements(ICommentingTool)
meta_type = 'plone.app.discussion tool' meta_type = 'plone.app.discussion tool'
id = 'portal_discussion' id = 'portal_discussion'