From 702f7e1f1d7c2d50621f2f326c185ddb2034d174 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sun, 17 Jun 2012 12:09:25 +0200 Subject: [PATCH] Make 'text/plain' the default mime type for comments and make sure the default type is set properly when creating a new comment. --- plone/app/discussion/browser/comments.py | 4 ++++ plone/app/discussion/comment.py | 6 +++++- plone/app/discussion/tests/test_comment.py | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index 1eddf0a..6be93a2 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -168,6 +168,10 @@ class CommentForm(extensible.ExtensibleForm, form.Form): # Create comment comment = createObject('plone.Comment') + + # Set comment mime type to current setting in the discussion registry + comment.mime_type = settings.text_transform + # Set comment attributes (including extended comment form attributes) for attribute in self.fields.keys(): setattr(comment, attribute, data[attribute]) diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py index 78baf8b..7b4c12c 100644 --- a/plone/app/discussion/comment.py +++ b/plone/app/discussion/comment.py @@ -90,7 +90,7 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable, title = u"" - mime_type = None + mime_type = "text/plain" text = u"" creator = None @@ -205,6 +205,10 @@ def notify_content_object(obj, event): """Tell the content object when a comment is added """ content_obj = aq_parent(aq_parent(obj)) + # set the modified date and reindex the item accordingly + # so that 304s work correctly. This means that adding a comment + # effectively counts as modifying the content type. + content_obj.setModificationDate() content_obj.reindexObject(idxs=('total_comments', 'last_comment_date', 'commentators', diff --git a/plone/app/discussion/tests/test_comment.py b/plone/app/discussion/tests/test_comment.py index 307c646..3afe87e 100644 --- a/plone/app/discussion/tests/test_comment.py +++ b/plone/app/discussion/tests/test_comment.py @@ -127,6 +127,10 @@ class CommentTest(unittest.TestCase): comment1 = createObject('plone.Comment') self.assertEqual(comment1.Type(), 'Comment') + def test_mime_type(self): + comment1 = createObject('plone.Comment') + self.assertEqual(comment1.mime_type, 'text/plain') + def test_getText(self): comment1 = createObject('plone.Comment') comment1.text = """First paragraph