Personal tools

让你的站点可匿名用户填写姓名可评注

Plone在默认情况下,开启评论的内容,用户需要登录才能发表评注。下面将讲述如何让匿名用户便可评注;然后做简单定制,实现让匿名用户填写姓名即可评注。

1. 打开评注功能


在编辑页面的属性标签页中如图:


点击“开放”,点击保存。

在Plone3.0中,点击Setting标签页,打开Allowed comments属性。

2. 开启匿名评注功能


你发现用匿名登录后,需要登录后发表评论。如下图:

那我们来开启匿名评注的功能吧:

  • 进入ZMI的根目录的 Security 标签页
  • 找到Reply to item权限项,取消选择Acquire,并选择允许Anonymous角色
  • 单击Save按钮,保存更改

这样,站点的内容如果开启了评论,匿名用户也可对内容进行评论。

3. 找到评注的逻辑及代码


匿名用户可评注,但是在评注表单中要填写用户名和密码才能用姓名发表评注,如下图:

我们在代码中去看这个发表评注的过程。去找评注功能的相关显示及逻辑代码。

我们在提交评注表单的HTML代码中找到提交的Form表单是这样的:

.../discussion_reply_form

那么,我们在Portal_skins中找到discussion_reply_form

这是一个CPT文件,你若不了解什么叫控制页面模板,简易先到CZUG的Plone中文书籍项目中了解第十三章的内容,项目地址:http://czug.everydo.com 登录用户名/密码用 guset/guest 。

在discussion_reply_form这个CPT页面的Actions标签页中,我们看到表单提交成功后会提交到discussion_reply,这便是表单的处理逻辑代码。

4. 定制可填写姓名发表评注


我们来处理表单,在表单中有这样的代码:

<div tal:condition="isAnon">
<dl class="portalMessage warning">
<dt i18n:translate="">
Info
</dt>
<dd i18n:translate="legend_note_reply_anonymous">
You are not logged in. You may optionally enter your
username and password below. If you don't enter anything,
this comment will be posted as 'Anonymous User'.
</dd>
</dl>
<div class="field">
<label for="username" i18n:translate="label_name">Name</label>
<input name="username"
id="username"
value="" alt="Username" title="Name"
size="40"
i18n:attributes="title label_name; alt label_username;" />
</div>
<div class="field">
<label for="password" i18n:translate="label_password">Password</label>
<input type="password"
id="password"
name="password"
value="" alt="Password" title="Password"
size="40"
i18n:attributes="title label_password; alt label_password;" />

</div>
</div>


<div class="field">
<label for="username" i18n:translate="label_name">Name</label>
<input name="username"
id="username"
value="" alt="Username" title="Name"
size="40"
i18n:attributes="title label_name; alt label_username;" />

</div>

现在来处理逻辑部分disscustion_relpy的代码,

这是一个Python Script,它有这样一些参数,在 Parameter List 中看到:

subject,body_text,text_format='plain',username=None,password=None

换成:

subject,body_text,text_format='plain',username=""


if username or password:
# The user username/password inputs on on the comment form were used,
# which might happen when anonymous commenting is enabled. If they typed
# something in to either of the inputs, we send them to 'logged_in'.
# 'logged_in' will redirect them back to this script if authentication
# succeeds with a query string which will post the message appropriately
# and show them the result. if 'logged_in' fails, the user will be
# presented with the stock login failure page. This all depends
# heavily on cookiecrumbler, but I believe that is a Plone requirement.
came_from = '%s?subject=%s&amp;body_text=%s' % (req['URL'], subject, body_text)
came_from = url_quote_plus(came_from)
portal_url = context.portal_url()

return req.RESPONSE.redirect(
'%s/logged_in?__ac_name=%s'
'&amp;__ac_password=%s'
'&amp;came_from=%s' % (portal_url,
url_quote_plus(username),
url_quote_plus(password),
came_from,
)
)

# if (the user is already logged in) or (if anonymous commenting is enabled and
# they posted without typing a username or password into the form), we do
# the following

creator = mtool.getAuthenticatedMember().getId()

if username == '':
username = '匿名用户'
creator = username
 

本站由 润普公司资助, 采用 易度CMS 构建。

广而告之:润普公司 易度在线工作平台,包括 易度文档管理系统 易度项目管理系统 , 易度部门管理 ,均采用Zope 3/BFG技术开发。
沪ICP备05008050