anonymous comments added.

svn path=/plone.app.discussion/trunk/; revision=27352
This commit is contained in:
Timo Stollenwerk 2009-06-08 08:00:15 +00:00
parent 22a4916afa
commit 353c6acfd0
2 changed files with 135 additions and 7 deletions

View File

@ -1,5 +1,6 @@
<tal:block define="userHasReplyPermission view/can_reply;
isDiscussionAllowed view/is_discussion_allowed;
isAnonymousDiscussionAllowed view/anonymous_discussion_allowed;
replies view/get_replies;
isAnon view/is_anonymous;
errors options/state/getErrors|nothing;"
@ -7,7 +8,7 @@
i18n:domain="plone">
<div class="reply"
tal:condition="isAnon">
tal:condition="python:isAnon and not isAnonymousDiscussionAllowed">
<form tal:attributes="action view/login_action">
<input class="standalone"
style="margin-bottom: 1.25em;"
@ -95,7 +96,7 @@
</div>
<div class="reply"
tal:condition="python: isAnon and replies">
tal:condition="python: isAnon and not isAnonymousDiscussionAllowed and replies">
<form tal:attributes="action view/login_action">
<input class="standalone"
style="margin-bottom: 1.25em;"
@ -183,4 +184,120 @@
</fieldset>
</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>

View File

@ -4,8 +4,7 @@ from urllib import quote as url_quote
from zope.interface import implements
from zope.component import createObject
from zope.component import getMultiAdapter
from zope.component import createObject, getMultiAdapter, queryUtility
from zope.viewlet.interfaces import IViewlet
@ -18,9 +17,11 @@ from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.CMFCore.utils import getToolByName
from plone.registry.interfaces import IRegistry
from plone.app.layout.viewlets.common import ViewletBase
from plone.app.discussion.interfaces import IComment, IReplies
from plone.app.discussion.interfaces import IComment, IReplies, IDiscussionSettings
from plone.app.discussion.conversation import conversationAdapterFactory
from plone.app.discussion.comment import CommentFactory
@ -80,6 +81,12 @@ class CommentsViewlet(ViewletBase):
else:
return self.portal_membership.getPersonalPortrait(username);
def anonymous_discussion_allowed(self):
# Check if anonymous comments are allowed in the registry
registry = queryUtility(IRegistry)
settings = registry.for_interface(IDiscussionSettings)
return settings.anonymous_comments
def is_anonymous(self):
return self.portal_state.anonymous()
@ -102,6 +109,8 @@ class AddComment(BrowserView):
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')
# The add-comment view is called on the conversation object
conversation = self.context
@ -114,8 +123,10 @@ class AddComment(BrowserView):
portal_membership = getToolByName(self.context, 'portal_membership')
if portal_membership.isAnonymousUser():
# TODO: Not implemented yet
pass
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()
comment.creator = member.getProperty('fullname')