fix commenting for anonymous users.

svn path=/plone.app.discussion/trunk/; revision=28363
This commit is contained in:
Timo Stollenwerk 2009-08-04 20:47:25 +00:00
parent 355f50388c
commit eadbb55a87
2 changed files with 57 additions and 200 deletions

View File

@ -142,8 +142,7 @@
</form> </form>
</div> </div>
<div id="commenting" class="reply" <div id="commenting" class="reply">
tal:condition="not:isAnon">
<fieldset> <fieldset>
@ -154,188 +153,8 @@
</p> </p>
<div tal:replace="structure view/contents" /> <div tal:replace="structure view/contents" />
<!--
<form name="reply"
action=""
method="get"
tal:attributes="action string:${context/absolute_url}/++conversation++default/@@add-comment">
<div class="field"
tal:define="error errors/subject|nothing;"
tal:attributes="class python: error and 'field error' or 'field'">
<label for="subject" i18n:translate="label_subject">Subject</label>
<span class="fieldRequired" title="Required"
i18n:attributes="title title_required;"
i18n:translate="label_required">(Required)</span>
<div tal:content="error">Validation error output</div>
<input name="subject"
id="subject"
value=""
size="40"
tal:attributes="value request/subject|request/title_override|nothing;" />
</div>
<div class="field"
tal:define="error errors/body_text|nothing;"
tal:attributes="class python: error and 'field error' or 'field'">
<label for="body_text" i18n:translate="label_comment">Comment</label>
<span class="fieldRequired" title="Required"
i18n:attributes="title title_required;"
i18n:translate="label_required">(Required)</span>
<div tal:content="error">Validation error output</div>
<textarea name="body_text"
id="body_text"
cols="40"
rows="8"
tal:content="request/body_text|request/text_override | nothing"></textarea>
</div>
<div class="formControls">
<input class="context"
type="submit"
value="Add Comment"
name="form.button.AddComment"
i18n:attributes="value label_add_comment;" />
<input class="standalone cancelreplytocomment"
type="submit"
name="form.button.Cancel"
value="Cancel"
i18n:attributes="value label_cancel;" />
</div>
<input type="hidden" name="form.submitted" value="1" />
</form>
-->
</fieldset> </fieldset>
</div> </div>
<div id="commenting" class="reply"
tal:condition="python:isAnon and isAnonymousDiscussionAllowed">
<fieldset>
<legend i18n:translate="legend_add_comment">Add comment</legend>
<p i18n:translate="description_add_comment">
You can add a comment by filling out the form below. Plain text
formatting.
</p>
<form name="reply"
action=""
method="get"
tal:attributes="action string:${context/absolute_url}/++conversation++default/@@add-comment">
<div class="field"
tal:define="error errors/subject|nothing;"
tal:attributes="class python: error and 'field error' or 'field'">
<label for="author_username" i18n:translate="label_author_username">Author username</label>
<span class="fieldRequired" title="Required"
i18n:attributes="title title_required;"
i18n:translate="label_required">(Required)</span>
<div tal:content="error">Validation error output</div>
<input name="author_username"
id="author_username"
value=""
size="40"
tal:attributes="value request/subject|request/title_override|nothing;" />
</div>
<div class="field"
tal:define="error errors/subject|nothing;"
tal:attributes="class python: error and 'field error' or 'field'">
<label for="author_email" i18n:translate="label_author_email">Author email</label>
<span class="fieldRequired" title="Required"
i18n:attributes="title title_required;"
i18n:translate="label_required">(Required)</span>
<div tal:content="error">Validation error output</div>
<input name="author_email"
id="author_email"
value=""
size="40"
tal:attributes="value request/subject|request/title_override|nothing;" />
</div>
<div class="field"
tal:define="error errors/subject|nothing;"
tal:attributes="class python: error and 'field error' or 'field'">
<label for="subject" i18n:translate="label_subject">Subject</label>
<span class="fieldRequired" title="Required"
i18n:attributes="title title_required;"
i18n:translate="label_required">(Required)</span>
<div tal:content="error">Validation error output</div>
<input name="subject"
id="subject"
value=""
size="40"
tal:attributes="value request/subject|request/title_override|nothing;" />
</div>
<div class="field"
tal:define="error errors/body_text|nothing;"
tal:attributes="class python: error and 'field error' or 'field'">
<label for="body_text" i18n:translate="label_comment">Comment</label>
<span class="fieldRequired" title="Required"
i18n:attributes="title title_required;"
i18n:translate="label_required">(Required)</span>
<div tal:content="error">Validation error output</div>
<textarea name="body_text"
id="body_text"
cols="40"
rows="8"
tal:content="request/body_text|request/text_override | nothing"></textarea>
</div>
<div class="formControls">
<input class="context"
type="submit"
value="Add Comment"
name="form.button.AddComment"
i18n:attributes="value label_add_comment;" />
<input class="standalone cancelreplytocomment"
type="submit"
name="form.button.Cancel"
value="Cancel"
i18n:attributes="value label_cancel;" />
</div>
<input type="hidden" name="form.submitted" value="1" />
</form>
</fieldset>
</div>
</tal:block> </tal:block>

View File

@ -37,7 +37,6 @@ from plone.app.discussion.interfaces import IConversation, IComment, IReplies, I
from plone.z3cform import layout, z2 from plone.z3cform import layout, z2
from plone.z3cform.fieldsets import extensible from plone.z3cform.fieldsets import extensible
class View(BrowserView): class View(BrowserView):
"""Comment View. """Comment View.
@ -56,24 +55,38 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
ignoreContext = True # don't use context to get widget data ignoreContext = True # don't use context to get widget data
label = _(u"Add a comment") label = _(u"Add a comment")
fields = field.Fields(IComment).omit('portal_type', @property
'__parent__', def fields(self):
'__name__', portal_membership = getToolByName(self.context, 'portal_membership')
'comment_id', if portal_membership.isAnonymousUser():
'mime_type', return field.Fields(IComment).omit('portal_type',
'creator', '__parent__',
'creation_date', '__name__',
'modification_date', 'comment_id',
'author_username', 'mime_type',
'author_name', 'creator',
'author_email',) 'creation_date',
'modification_date',
'author_username',)
else:
return field.Fields(IComment).omit('portal_type',
'__parent__',
'__name__',
'comment_id',
'mime_type',
'creator',
'creation_date',
'modification_date',
'author_username',
'author_name',
'author_email',)
def updateWidgets(self): def updateWidgets(self):
super(CommentForm, self).updateWidgets() super(CommentForm, self).updateWidgets()
self.widgets['in_reply_to'].mode = interfaces.HIDDEN_MODE self.widgets['in_reply_to'].mode = interfaces.HIDDEN_MODE
@button.buttonAndHandler(_(u"Comment")) @button.buttonAndHandler(_(u"Comment"))
def handleApply(self, action): def handleComment(self, action):
data, errors = self.extractData() data, errors = self.extractData()
if data.has_key('title') and data.has_key('text'): if data.has_key('title') and data.has_key('text'):
@ -81,6 +94,21 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
title = data['title'] title = data['title']
text = data['text'] text = data['text']
if data.has_key('author_name'):
author_name = data['author_name']
else:
author_name = u""
if data.has_key('author_username'):
author_name = data['author_username']
else:
author_username = u""
if data.has_key('author_email'):
author_email = data['author_email']
else:
author_email = u""
# The add-comment view is called on the conversation object # The add-comment view is called on the conversation object
conversation = IConversation(self.__parent__) conversation = IConversation(self.__parent__)
@ -92,8 +120,8 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
portal_membership = getToolByName(self.context, 'portal_membership') portal_membership = getToolByName(self.context, 'portal_membership')
if portal_membership.isAnonymousUser(): if portal_membership.isAnonymousUser():
comment.creator = author_username comment.creator = author_name
comment.author_name = author_username comment.author_name = author_name
comment.author_email = author_email comment.author_email = author_email
comment.creation_date = comment.modification_date = datetime.now() comment.creation_date = comment.modification_date = datetime.now()
else: else:
@ -127,10 +155,20 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
text = data['text'] text = data['text']
reply_to_comment_id = data['in_reply_to'] reply_to_comment_id = data['in_reply_to']
if data.has_key('author_name'):
author_name = data['author_name']
else:
author_name = u""
if data.has_key('author_username'): if data.has_key('author_username'):
author_username = data['author_username'] author_name = data['author_username']
else:
author_username = u""
if data.has_key('author_email'): if data.has_key('author_email'):
author_email = data['author_email'] author_email = data['author_email']
else:
author_email = u""
# The add-comment view is called on the conversation object # The add-comment view is called on the conversation object
conversation = IConversation(self.__parent__) conversation = IConversation(self.__parent__)
@ -148,8 +186,8 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
portal_membership = getToolByName(self.context, 'portal_membership') portal_membership = getToolByName(self.context, 'portal_membership')
if portal_membership.isAnonymousUser(): if portal_membership.isAnonymousUser():
comment.creator = author_username comment.creator = author_name
comment.author_name = author_username comment.author_name = author_name
comment.author_email = author_email comment.author_email = author_email
comment.creation_date = comment.modification_date = datetime.now() comment.creation_date = comment.modification_date = datetime.now()
else: else: