Remove "Plone 3 only" code; Do not monkey patch the BAD_TYPES vocabulary or plone.app.vocabularies anymore.

svn path=/plone.app.discussion/trunk/; revision=47311
This commit is contained in:
Timo Stollenwerk 2011-02-08 09:28:51 +00:00
parent 533fefa396
commit bf96d0082f
9 changed files with 46 additions and 157 deletions

View File

@ -1,6 +1,17 @@
Changelog Changelog
========= =========
2.0a1 (unreleased)
------------------
- Remove "Plone 3 only" code.
[timo]
- Do not monkey patch the BAD_TYPES vocabulary or plone.app.vocabularies
anymore.
[timo]
2.0a1 (2011-02-07) 2.0a1 (2011-02-07)
------------------ ------------------

View File

@ -1,16 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zope.i18nmessageid import MessageFactory from zope.i18nmessageid import MessageFactory
PloneAppDiscussionMessageFactory = MessageFactory('plone.app.discussion') PloneAppDiscussionMessageFactory = MessageFactory('plone.app.discussion')
# Monkey patch plone.app.vocabularies.types.BAD_TYPES and remove
# 'Discussion Item' from this tuple, so that Comments can be found
# in the search. This will become needless once plone.app.discussion
# will become a part of Plone 4.
import plone.app.vocabularies.types
new_bad_types = list(plone.app.vocabularies.types.BAD_TYPES)
if 'Discussion Item' in new_bad_types:
new_bad_types.remove('Discussion Item')
plone.app.vocabularies.types.BAD_TYPES = new_bad_types

View File

@ -4,21 +4,6 @@
xmlns:zcml="http://namespaces.zope.org/zcml" xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone.app.discussion"> i18n_domain="plone.app.discussion">
<!--
Plone 3 fixes
Plone 3 / Zope 2.10 does not recognize the meta:provides feature.
Therefore we claim to provide this feature when a suitable package is
installed.
-->
<configure zcml:condition="installed plone.formwidget.captcha">
<meta:provides feature="plone.app.discussion-captcha" />
</configure>
<configure zcml:condition="installed plone.formwidget.recaptcha">
<meta:provides feature="plone.app.discussion-captcha" />
</configure>
<!-- Captcha comment form extender --> <!-- Captcha comment form extender -->
<configure zcml:condition="have plone.app.discussion-captcha"> <configure zcml:condition="have plone.app.discussion-captcha">
<!-- <!--

View File

@ -11,26 +11,6 @@ from Products.statusmessages.interfaces import IStatusMessage
from plone.app.discussion.interfaces import _ from plone.app.discussion.interfaces import _
from plone.app.discussion.interfaces import IComment from plone.app.discussion.interfaces import IComment
# Begin ugly hack. It works around a ContentProviderLookupError:
# plone.htmlhead error caused by Zope 2 permissions.
# This error occured on Plone 3.3.x only!
#
# Source:
# http://athenageek.wordpress.com/2008/01/08/
# contentproviderlookuperror-plonehtmlhead/
#
# Bug report: https://bugs.launchpad.net/zope2/+bug/176566
#
def _getContext(self): # pragma: no cover
self = self.aq_parent
while getattr(self, '_is_wrapperish', None):
self = self.aq_parent
return self
ZopeTwoPageTemplateFile._getContext = _getContext # pragma: no cover
# End ugly hack.
class View(BrowserView): class View(BrowserView):
"""Main moderation View. """Main moderation View.

View File

@ -38,19 +38,9 @@ from plone.app.discussion.interfaces import IComment
from plone.app.discussion.interfaces import IConversation from plone.app.discussion.interfaces import IConversation
from plone.app.discussion.interfaces import IDiscussionSettings from plone.app.discussion.interfaces import IDiscussionSettings
try: from Products.CMFCore.CMFCatalogAware import CatalogAware
# Plone 4: from Products.CMFCore.CMFCatalogAware import WorkflowAware
# Mixin CatalogAware and WorkflowAware into the Comment class
# is necessary for comments to be indexed in Plone4.
from Products.CMFCore.CMFCatalogAware import CatalogAware # pylint: disable-msg=W0611
from Products.CMFCore.CMFCatalogAware import WorkflowAware # pylint: disable-msg=W0611
PLONE_4 = True
except: # pragma: no cover
# Plone 3:
# Dummy imports to make Comment class happy
from OFS.Traversable import Traversable as CatalogAware # pylint: disable-msg=W0611
from OFS.Traversable import Traversable as WorkflowAware # pylint: disable-msg=W0611
PLONE_4 = False
COMMENT_TITLE = _(u"comment_title", COMMENT_TITLE = _(u"comment_title",
default=u"${creator} on ${content}") default=u"${creator} on ${content}")
@ -240,30 +230,17 @@ def notify_user(obj, event):
context=obj.REQUEST) context=obj.REQUEST)
for email in emails: for email in emails:
# Send email # Send email
if PLONE_4: try:
try: mail_host.send(message,
mail_host.send(message, email,
email, sender,
sender, subject,
subject, charset='utf-8')
charset='utf-8') except SMTPException:
except SMTPException: logger.error('SMTP exception while trying to send an ' +
logger.error('SMTP exception while trying to send an ' + 'email from %s to %s',
'email from %s to %s', sender,
sender, email)
email)
else: # pragma: no cover
try:
mail_host.secureSend(message,
email,
sender,
subject=subject,
charset='utf-8')
except SMTPException:
logger.error('SMTP exception while trying to send an ' +
'email from %s to %s',
sender,
email)
def notify_moderator(obj, event): def notify_moderator(obj, event):
@ -307,29 +284,13 @@ def notify_moderator(obj, event):
context=obj.REQUEST) context=obj.REQUEST)
# Send email # Send email
if PLONE_4: try:
try: mail_host.send(message, mto, sender, subject, charset='utf-8')
mail_host.send(message, mto, sender, subject, charset='utf-8') except SMTPException, e:
except SMTPException, e: logger.error('SMTP exception (%s) while trying to send an ' +
logger.error('SMTP exception (%s) while trying to send an ' + 'email notification to the comment moderator ' +
'email notification to the comment moderator ' + '(from %s to %s, message: %s)',
'(from %s to %s, message: %s)', e,
e, sender,
sender, mto,
mto, message)
message)
else: # pragma: no cover
try:
mail_host.secureSend(message,
mto,
sender,
subject=subject,
charset='utf-8')
except SMTPException, e:
logger.error('SMTP exception (%s) while trying to send an ' +
'email notification to the comment moderator ' +
'(from %s to %s, message: %s)',
e,
sender,
mto,
message)

View File

@ -40,24 +40,13 @@ from zope.container.contained import ContainerModifiedEvent
from zope.lifecycleevent import ObjectCreatedEvent from zope.lifecycleevent import ObjectCreatedEvent
try: from zope.lifecycleevent import ObjectAddedEvent
# Plone 4 from zope.lifecycleevent import ObjectRemovedEvent
from zope.lifecycleevent import ObjectAddedEvent
from zope.lifecycleevent import ObjectRemovedEvent
except ImportError: # pragma: no cover
# Plone 3.x
from zope.app.container.contained import ObjectAddedEvent # pragma: no cover
from zope.app.container.contained import ObjectRemovedEvent # pragma: no cover
from BTrees.OIBTree import OIBTree from BTrees.OIBTree import OIBTree
try: from BTrees.LOBTree import LOBTree
# These exist in new versions, but not in the one that comes with Zope 2.10. from BTrees.LLBTree import LLSet
from BTrees.LOBTree import LOBTree
from BTrees.LLBTree import LLSet
except ImportError: # pragma: no cover
from BTrees.OOBTree import OOBTree as LOBTree # pragma: no cover
from BTrees.OOBTree import OOSet as LLSet # pragma: no cover
from plone.app.discussion.interfaces import IConversation from plone.app.discussion.interfaces import IConversation
from plone.app.discussion.interfaces import IDiscussionSettings from plone.app.discussion.interfaces import IDiscussionSettings

View File

@ -71,15 +71,7 @@ class CommentTest(PloneTestCase):
conversation.addComment(comment1) conversation.addComment(comment1)
comment_brain = self.catalog.searchResults( comment_brain = self.catalog.searchResults(
portal_type = 'Discussion Item')[0] portal_type = 'Discussion Item')[0]
self.failUnless(comment_brain.UID)
# comment should only have a UID if plone.uuid is present
try:
from plone.uuid.interfaces import IUUID
IUUID # pyflakes
except ImportError:
self.failIf(comment_brain.UID)
else:
self.failUnless(comment_brain.UID)
def test_uid_is_unique(self): def test_uid_is_unique(self):
conversation = IConversation(self.portal.doc1) conversation = IConversation(self.portal.doc1)
@ -89,11 +81,7 @@ class CommentTest(PloneTestCase):
conversation.addComment(comment2) conversation.addComment(comment2)
brains = self.catalog.searchResults( brains = self.catalog.searchResults(
portal_type = 'Discussion Item') portal_type = 'Discussion Item')
self.assertNotEquals(brains[0].UID, brains[1].UID)
# make sure uids are either both None (i.e. without plone.uuid),
# or not equal
if brains[0].UID != None or brains[1].UID != None:
self.assertNotEquals(brains[0].UID, brains[1].UID)
def test_comment_uid_differs_from_content_uid(self): def test_comment_uid_differs_from_content_uid(self):
conversation = IConversation(self.portal.doc1) conversation = IConversation(self.portal.doc1)

View File

@ -680,14 +680,8 @@ class ConversationTest(PloneTestCase):
self.assertEquals(('', 'plone', 'doc1', '++conversation++default'), self.assertEquals(('', 'plone', 'doc1', '++conversation++default'),
conversation.getPhysicalPath()) conversation.getPhysicalPath())
# XXX: conversation.absolute_url() returns different values dependent self.assertEquals('http://nohost/plone/doc1/++conversation++default',
# on the Plone version used. conversation.absolute_url())
# Plone 3.3:
#self.assertEquals('plone/doc1/%2B%2Bconversation%2B%2Bdefault',
#conversation.absolute_url())
# Plone 4:
#self.assertEquals('http://nohost/plone/doc1/++conversation++default',
#conversation.absolute_url())
def test_parent(self): def test_parent(self):
# Check that conversation has a content object as parent # Check that conversation has a content object as parent
@ -701,7 +695,6 @@ class ConversationTest(PloneTestCase):
self.assertEquals(conversation.__parent__.getId(), 'doc1') self.assertEquals(conversation.__parent__.getId(), 'doc1')
def test_discussion_item_not_in_bad_types(self): def test_discussion_item_not_in_bad_types(self):
self.failIf('Discussion Item' in BAD_TYPES) self.failIf('Discussion Item' in BAD_TYPES)

View File

@ -214,14 +214,8 @@ class TestModeratorNotificationUnit(PloneTestCase):
self.failUnless(self.mailhost.messages[0]) self.failUnless(self.mailhost.messages[0])
msg = self.mailhost.messages[0] msg = self.mailhost.messages[0]
if not isinstance(msg, str): self.failUnless('To: portal@plone.test' in msg)
# Plone 3 self.failUnless('From: portal@plone.test' in msg)
self.failUnless('portal@plone.test' in msg.mfrom)
self.failUnless('portal@plone.test' in msg.mto)
else:
#Plone 4
self.failUnless('To: portal@plone.test' in msg)
self.failUnless('From: portal@plone.test' in msg)
#We expect the headers to be properly header encoded (7-bit): #We expect the headers to be properly header encoded (7-bit):
#>>> 'Subject: =?utf-8?q?Some_t=C3=A4st_subject=2E?=' in msg #>>> 'Subject: =?utf-8?q?Some_t=C3=A4st_subject=2E?=' in msg