Make 'text/plain' the default mime type for comments and make sure the default type is set properly when creating a new comment.

This commit is contained in:
Timo Stollenwerk 2012-06-17 12:09:25 +02:00
parent f45373b311
commit 702f7e1f1d
3 changed files with 13 additions and 1 deletions

View File

@ -168,6 +168,10 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
# Create comment # Create comment
comment = createObject('plone.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) # Set comment attributes (including extended comment form attributes)
for attribute in self.fields.keys(): for attribute in self.fields.keys():
setattr(comment, attribute, data[attribute]) setattr(comment, attribute, data[attribute])

View File

@ -90,7 +90,7 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
title = u"" title = u""
mime_type = None mime_type = "text/plain"
text = u"" text = u""
creator = None creator = None
@ -205,6 +205,10 @@ def notify_content_object(obj, event):
"""Tell the content object when a comment is added """Tell the content object when a comment is added
""" """
content_obj = aq_parent(aq_parent(obj)) 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', content_obj.reindexObject(idxs=('total_comments',
'last_comment_date', 'last_comment_date',
'commentators', 'commentators',

View File

@ -127,6 +127,10 @@ class CommentTest(unittest.TestCase):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
self.assertEqual(comment1.Type(), '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): def test_getText(self):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
comment1.text = """First paragraph comment1.text = """First paragraph