move addComment view to z3cform.

svn path=/plone.app.discussion/trunk/; revision=28346
This commit is contained in:
Timo Stollenwerk 2009-08-04 11:56:52 +00:00
parent 878f45029b
commit 4876a5fb59
2 changed files with 46 additions and 82 deletions

View File

@ -107,8 +107,52 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
@button.buttonAndHandler(u'Post comment')
def handleApply(self, action):
data, errors = self.extractData()
if errors:
self.status = form.EditForm.formErrorsMessage
return
if data.has_key('title'):
print data['title'] # ... or do stuff
subject = data['title']
if data.has_key('text'):
text = data['text']
if data.has_key('author_username'):
author_username = data['author_username']
if data.has_key('author_email'):
author_email = data['author_email']
# The add-comment view is called on the conversation object
conversation = IConversation(self.__parent__)
# Create the comment
comment = CommentFactory()
comment.title = subject
comment.text = text
portal_membership = getToolByName(self.context, 'portal_membership')
if portal_membership.isAnonymousUser():
comment.creator = author_username
comment.author_name = author_username
comment.author_email = author_email
comment.creation_date = comment.modification_date = datetime.now()
else:
member = portal_membership.getAuthenticatedMember()
fullname = member.getProperty('fullname')
if fullname == '' or None:
comment.creator = member.id
else:
comment.creator = fullname
comment.author_username = member.getUserName()
comment.author_name = member.getProperty('fullname')
comment.author_email = member.getProperty('email')
comment.creation_date = comment.modification_date = datetime.now()
# Add comment to the conversation
comment_id = conversation.addComment(comment)
# Redirect to comment (inside a content object page)
#self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url() + '#comment-' + str(comment_id))
#self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url() + '#' + str(comment_id))
class ViewletFormWrapper(ViewletBase, layout.FormWrapper):
@ -216,77 +260,6 @@ class ViewletFormWrapper(ViewletBase, layout.FormWrapper):
CommentsViewlet = layout.wrap_form(CommentForm, __wrapper_class=ViewletFormWrapper)
class AddComment(BrowserView):
"""Add a comment to a conversation
"""
def __call__(self):
if self.request.has_key('form.button.AddComment'):
context = aq_inner(self.context)
subject = self.request.get('subject')
text = self.request.get('body_text')
author_username = self.request.get('author_username')
author_email = self.request.get('author_email')
# Check the form input
if author_username == '':
IStatusMessage(self.request).addStatusMessage(\
_("Username field is empty."),
type="info")
return self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url())
if author_email == '':
IStatusMessage(self.request).addStatusMessage(\
_("Email field is empty."),
type="info")
return self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url())
if subject == '':
IStatusMessage(self.request).addStatusMessage(\
_("Subject field is empty."),
type="info")
return self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url())
if text == '':
IStatusMessage(self.request).addStatusMessage(\
_("Comment field is empty."),
type="info")
return self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url())
# The add-comment view is called on the conversation object
conversation = context
# Create the comment
comment = CommentFactory()
comment.title = subject
comment.text = text
portal_membership = getToolByName(context, 'portal_membership')
if portal_membership.isAnonymousUser():
comment.creator = author_username
comment.author_name = author_username
comment.author_email = author_email
comment.creation_date = comment.modification_date = datetime.now()
else:
member = portal_membership.getAuthenticatedMember()
fullname = member.getProperty('fullname')
if fullname == '' or None:
comment.creator = member.id
else:
comment.creator = fullname
comment.author_username = member.getUserName()
comment.author_name = member.getProperty('fullname')
comment.author_email = member.getProperty('email')
comment.creation_date = comment.modification_date = datetime.now()
# Add comment to the conversation
comment_id = conversation.addComment(comment)
# Redirect to comment (inside a content object page)
#self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url() + '#comment-' + str(comment_id))
self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url() + '#' + str(comment_id))
class ReplyToComment(BrowserView):
"""Reply to a comment
"""

View File

@ -58,7 +58,7 @@
name="plone.comments"
for="Products.CMFCore.interfaces.IContentish"
layer="..interfaces.IDiscussionLayer"
view="plone.app.layout.globals.interfaces.IViewView"
view="plone.app.layout.globals.interfaces.IViewView"
manager="plone.app.layout.viewlets.interfaces.IBelowContent"
class=".comments.CommentsViewlet"
permission="zope2.View"
@ -73,15 +73,6 @@
permission="zope2.View"
/>
<!-- Add comment view -->
<browser:view
name="add-comment"
for="plone.app.discussion.interfaces.IConversation"
layer="..interfaces.IDiscussionLayer"
class=".comments.AddComment"
permission="zope2.View"
/>
<!-- Reply to comment view -->
<browser:view
name="reply-to-comment"