show login form instead of the commenting form to anonymous users.

svn path=/plone.app.discussion/trunk/; revision=27194
This commit is contained in:
Timo Stollenwerk 2009-05-28 11:39:36 +00:00
parent 77e8093c53
commit aa50c33d8d
2 changed files with 34 additions and 9 deletions

View File

@ -5,6 +5,18 @@
errors options/state/getErrors|nothing;" errors options/state/getErrors|nothing;"
i18n:domain="plone"> i18n:domain="plone">
<div class="reply"
tal:condition="isAnon">
<form tal:attributes="action view/login_action">
<input class="standalone"
style="margin-bottom: 1.25em;"
type="submit"
value="Log in to add comments"
i18n:attributes="value label_login_to_add_comments;"
/>
</form>
</div>
<div class="discussion" <div class="discussion"
tal:condition="python:replies or (userHasReplyPermission and isDiscussionAllowed) or (isAnon and not userHasReplyPermission and isDiscussionAllowed)"> tal:condition="python:replies or (userHasReplyPermission and isDiscussionAllowed) or (isAnon and not userHasReplyPermission and isDiscussionAllowed)">
<tal:getreplies repeat="reply_dict replies"> <tal:getreplies repeat="reply_dict replies">
@ -73,7 +85,21 @@
</tal:getreplies> </tal:getreplies>
</div> </div>
<div class="reply"> <div class="reply"
tal:condition="isAnon">
<form tal:attributes="action view/login_action">
<input class="standalone"
style="margin-bottom: 1.25em;"
type="submit"
value="Log in to add comments"
i18n:attributes="value label_login_to_add_comments;"
/>
</form>
</div>
<div class="reply"
tal:condition="not:isAnon">
<fieldset> <fieldset>
<legend i18n:translate="legend_add_comment">Add comment</legend> <legend i18n:translate="legend_add_comment">Add comment</legend>

View File

@ -1,5 +1,7 @@
from datetime import datetime from datetime import datetime
from urllib import quote as url_quote
from zope.interface import implements from zope.interface import implements
from zope.component import createObject from zope.component import createObject
@ -16,6 +18,8 @@ from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from plone.app.layout.viewlets.common import ViewletBase
from plone.app.discussion.interfaces import IComment, IReplies from plone.app.discussion.interfaces import IComment, IReplies
from plone.app.discussion.conversation import conversationAdapterFactory from plone.app.discussion.conversation import conversationAdapterFactory
@ -32,7 +36,7 @@ class View(BrowserView):
comment_id = aq_parent(self).id comment_id = aq_parent(self).id
self.request.response.redirect(aq_parent(aq_parent(aq_parent(self))).absolute_url() + '#comment-' + comment_id) self.request.response.redirect(aq_parent(aq_parent(aq_parent(self))).absolute_url() + '#comment-' + comment_id)
class CommentsViewlet(BrowserView): class CommentsViewlet(ViewletBase):
"""Discussion Viewlet """Discussion Viewlet
""" """
@ -40,13 +44,6 @@ class CommentsViewlet(BrowserView):
template = ViewPageTemplateFile('comments.pt') template = ViewPageTemplateFile('comments.pt')
def __init__(self, context, request, view, manager):
super(CommentsViewlet, self).__init__(context, request)
self.__parent__ = view
self.view = view
self.manager = manager
self.portal_state = getMultiAdapter((context, self.request), name=u"plone_portal_state")
def update(self): def update(self):
super(CommentsViewlet, self).update() super(CommentsViewlet, self).update()
self.portal_discussion = getToolByName(self.context, 'portal_discussion', None) self.portal_discussion = getToolByName(self.context, 'portal_discussion', None)
@ -69,6 +66,8 @@ class CommentsViewlet(BrowserView):
def is_anonymous(self): def is_anonymous(self):
return self.portal_state.anonymous() return self.portal_state.anonymous()
def login_action(self):
return '%s/login_form?came_from=%s' % (self.navigation_root_url, url_quote(self.request.get('URL', '')),)
def format_time(self, time): def format_time(self, time):
# TODO: to localized time not working!!! # TODO: to localized time not working!!!