Remove the hard coded check for title and text when the comment form is submitted. This allows integrators to write schema extenders that remove the title from the comment form.

svn path=/plone.app.discussion/trunk/; revision=37341
This commit is contained in:
Timo Stollenwerk 2010-06-17 18:56:26 +00:00
parent 6e98edf54f
commit 12589d9fd2
2 changed files with 66 additions and 58 deletions

View File

@ -4,6 +4,11 @@ Changelog
1.0b5 (unreleased) 1.0b5 (unreleased)
------------------ ------------------
* Remove the hard coded check for title and text when the comment form is
submitted. This allows integrators to write schema extenders that remove the
title from the comment form.
[timo]
* Move captcha registration to its own captcha.zcml file. * Move captcha registration to its own captcha.zcml file.
[timo] [timo]

View File

@ -102,7 +102,10 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
def handleComment(self, action): def handleComment(self, action):
context = aq_inner(self.context) context = aq_inner(self.context)
wf = getToolByName(context, 'portal_workflow') wf = getToolByName(context, 'portal_workflow')
data, errors = self.extractData() data, errors = self.extractData()
if errors:
return
title = u"" title = u""
text = u"" text = u""
@ -128,72 +131,72 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
else: else:
return return
if 'title' in data and 'text' in data: if 'title' in data:
title = data['title'] title = data['title']
if 'text' in data:
text = data['text'] text = data['text']
if 'author_name' in data:
author_name = data['author_name']
if 'author_username' in data:
author_username = data['author_username']
if 'author_email' in data:
author_email = data['author_email']
if 'author_notification' in data:
author_notification = data['author_notification']
if 'author_name' in data: # The add-comment view is called on the conversation object
author_name = data['author_name'] conversation = IConversation(self.__parent__)
if 'author_username' in data:
author_username = data['author_username']
if 'author_email' in data:
author_email = data['author_email']
if 'author_notification' in data:
author_notification = data['author_notification']
# The add-comment view is called on the conversation object if data['in_reply_to']:
conversation = IConversation(self.__parent__) # Fetch the comment we want to reply to
conversation_to_reply_to = conversation.get(data['in_reply_to'])
replies = IReplies(conversation_to_reply_to)
if data['in_reply_to']: # Create the comment
# Fetch the comment we want to reply to comment = createObject('plone.Comment')
conversation_to_reply_to = conversation.get(data['in_reply_to']) comment.title = title
replies = IReplies(conversation_to_reply_to) comment.text = text
# Create the comment portal_membership = getToolByName(self.context, 'portal_membership')
comment = createObject('plone.Comment')
comment.title = title
comment.text = text
portal_membership = getToolByName(self.context, 'portal_membership') if portal_membership.isAnonymousUser():
comment.creator = None
comment.author_name = author_name
comment.author_email = author_email
#comment.author_notification = author_notification
comment.creation_date = comment.modification_date = datetime.now()
else:
member = portal_membership.getAuthenticatedMember()
comment.creator = member.id
comment.author_username = member.getUserName()
comment.author_name = member.getProperty('fullname')
comment.author_email = member.getProperty('email')
#comment.author_notification = comment.author_notification
comment.creation_date = comment.modification_date = datetime.now()
if portal_membership.isAnonymousUser(): # Check if the added comment is a reply to an existing comment
comment.creator = None # or just a regular reply to the content object.
comment.author_name = author_name if data['in_reply_to']:
comment.author_email = author_email # Add a reply to an existing comment
#comment.author_notification = author_notification comment_id = replies.addComment(comment)
comment.creation_date = comment.modification_date = datetime.now() else:
else: # Add a comment to the conversation
member = portal_membership.getAuthenticatedMember() comment_id = conversation.addComment(comment)
comment.creator = member.id
comment.author_username = member.getUserName()
comment.author_name = member.getProperty('fullname')
comment.author_email = member.getProperty('email')
#comment.author_notification = comment.author_notification
comment.creation_date = comment.modification_date = datetime.now()
# Check if the added comment is a reply to an existing comment # If a user post a comment and moderation is enabled, a message is shown
# or just a regular reply to the content object. # to the user that his/her comment awaits moderation. If the user has manage
if data['in_reply_to']: # right, he/she is redirected directly to the comment.
# Add a reply to an existing comment can_manage = getSecurityManager().checkPermission('Manage portal', context)
comment_id = replies.addComment(comment) if wf.getChainForPortalType('Discussion Item') == \
else: ('comment_review_workflow',) and not can_manage:
# Add a comment to the conversation # Show info message when comment moderation is enabled
comment_id = conversation.addComment(comment) IStatusMessage(self.context.REQUEST).addStatusMessage(
_("Your comment awaits moderator approval."),
# If a user post a comment and moderation is enabled, a message is shown type="info")
# to the user that his/her comment awaits moderation. If the user has manage self.request.response.redirect(context.absolute_url())
# right, he/she is redirected directly to the comment. else:
can_manage = getSecurityManager().checkPermission('Manage portal', context) # Redirect to comment (inside a content object page)
if wf.getChainForPortalType('Discussion Item') == \ self.request.response.redirect(context.absolute_url() + '#' + str(comment_id))
('comment_review_workflow',) and not can_manage:
# Show info message when comment moderation is enabled
IStatusMessage(self.context.REQUEST).addStatusMessage(
_("Your comment awaits moderator approval."),
type="info")
self.request.response.redirect(context.absolute_url())
else:
# Redirect to comment (inside a content object page)
self.request.response.redirect(context.absolute_url() + '#' + str(comment_id))
@button.buttonAndHandler(_(u"Cancel")) @button.buttonAndHandler(_(u"Cancel"))
def handleCancel(self, action): def handleCancel(self, action):