Created
April 16, 2013 09:38
-
-
Save tisto/5394676 to your computer and use it in GitHub Desktop.
p.a.discussion edit-comment-form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
configure.zcml:: | |
<browser:page | |
for="plone.app.discussion.interfaces.IComment" | |
name="edit-comment" | |
class=".comment.EditComment" | |
permission="cmf.ModifyPortalContent" | |
/> | |
comment.py:: | |
class EditCommentForm(CommentForm): | |
"""Form to edit an existing comment. | |
""" | |
ignoreContext = True | |
id = "edit-comment-form" | |
label = _(u'edit_comment_form_title', default=u'Edit comment') | |
def updateWidgets(self): | |
super(EditCommentForm, self).updateWidgets() | |
self.widgets['text'].value = self.context.text | |
# We have to rename the id, otherwise TinyMCE can't initialize | |
# because there are two textareas with the same id. | |
self.widgets['text'].id = 'overlay-comment-text' | |
def _redirect(self, target=''): | |
if not target: | |
portal_state = getMultiAdapter((self.context, self.request), | |
name=u'plone_portal_state') | |
target = portal_state.portal_url() | |
self.request.response.redirect(target) | |
@button.buttonAndHandler(_(u"edit_comment_form_button", | |
default=u"Edit comment"), name='comment') | |
def handleComment(self, action): | |
# Validate form | |
data, errors = self.extractData() | |
if errors: | |
return | |
# Check permissions | |
can_reply = getSecurityManager().checkPermission( | |
'Modify portal content', | |
self.context) | |
mtool = getToolByName(self.context, 'portal_membership') | |
if mtool.isAnonymousUser() or not can_reply: | |
return | |
# Update text | |
self.context.text = data['text'] | |
# Redirect to comment | |
IStatusMessage(self.request).add(_(u'comment_edit_notification', | |
default="Comment was edited"), | |
type='info') | |
return self._redirect(target=self.action.replace("/edit-comment", "") + '#' + str(self.context.id)) | |
@button.buttonAndHandler(_(u'cancel_form_button', default=u'Cancel'), name='cancel') | |
def handle_cancel(self, action): | |
IStatusMessage(self.request).add(_(u'comment_edit_cancel_notification', | |
default=u'Edit comment cancelled'), | |
type='info') | |
return self._redirect(target=self.context.absolute_url()) | |
EditComment = wrap_form(EditCommentForm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment