个人工具
119.28.94.63
该IP地址的讨论
登录
查看“Zope3宝典/开发新皮肤”的源代码 - Ubuntu中文
页面
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“Zope3宝典/开发新皮肤”的源代码
来自Ubuntu中文
←
Zope3宝典/开发新皮肤
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
=== 24.7 Step VII: Reviewing “pending” Messages(24.7 步骤 VII: 复审 “待审” 消息) === Did you try to add a message? But where did it go? Well, remember that only published messages are visible. <br>你想添加消息?但它到哪去了?呵,请记住只有发布了的消息才是可见。 While we have a message review screen for the management interface, it is not very usable. So we develop a much more simplified functionality in the board skin that can only publish messages. The following template displays all the pending messages and provides a checkbox for the moderator to select whether this message is about to be published ( board_review.pt): <br>尽管我们在管理接口上有一个消息复审屏幕,但它并不很有用。因此我们在 board 皮肤中开发一个非常简单的只能发布信息的功能。下面的模块将显示所有的待审消息并提供一个检查框以便让版主选择该消息是否要发布( board_review.pt ): <pre><nowiki> 1 <html metal:use-macro="views/standard_macros/page"> 2 <body> 3 <div metal:fill-slot="body" i18n:domain="messageboard"> 4 5 <h2 i18n:translate="">Review Pending Posts</h2> 6 7 <form action="updateStatus.html" method="POST"> 8 9 <div id="message_line" 10 tal:repeat="post view/getPendingMessagesInfo"> 11 <input type="checkbox" name="messages" value="" 12 tal:attributes="value post/path" /> 13 <a href="" tal:attributes="href post/url" 14 tal:content="post/title">Message Title</a> 15 <div style="font-size: 70%"> 16 (Posted by <b tal:content="post/creator">Creator</b> 17 on <b tal:replace="post/created">2003/01/01</b>) 18 </div> 19 </div> 20 <br /> 21 <input type="submit" value="Publish" 22 i18n:attributes="value" /> 23 24 </form> 25 26 </div> 27 <div id="actions" metal:fill-slot="actions"> 28 <a href="posts.html" i18n:translate="">View Posts</a> 29 </div> 30 </body> 31 </html> </nowiki></pre> In the corresponding Python view class, we can simply reuse the code we developed for the management version: <br>在相应的 Python 视图类中,我们可以简单的在管理版本中复用我们开发的代码: <pre><nowiki>#!python from zope.app.import zapi from zope.app.dublincore.interfaces import ICMFDublinCore from zope.app.interfaces.workflow import IProcessInstanceContainer from book.messageboard.browser.messageboard import ReviewMessages class Review(ReviewMessages): """Review messages for publication.""" def getPendingMessagesInfo(self): """Get all the display info for pending messages""" msg_infos = [] for msg in self.getPendingMessages(self.context): dc = ICMFDublinCore(msg) info = {} info['path'] = zapi.getPath(msg) info['title'] = msg.title info['creator'] = dc.creators[0] formatter = self.request.locale.dates.getFormatter( 'dateTime', 'medium') info['created'] = formatter.format(dc.created) info['url'] = zapi.getView( msg, 'absolute_url', self.request)() + \ '/@@details.html' msg_infos.append(info) return msg_infos def updateStatus(self, messages): """Upgrade the stati from 'pending' to 'published'.""" if not isinstance(messages, (list, tuple)): messages = [messages] for path in messages: msg = zapi.traverse(self.context, path) adapter = IProcessInstanceContainer(msg) adapter['publish-message'].fireTransition('pending_published') return self.request.response.redirect('@@review.html') </nowiki></pre> * Line 5, 7, & 13: We are going to reuse some code from the other implementation. <br>第 5,7 & 13 行: 我们打算复用来自其他实现的部分代码 * Line 28-39: This is the interesting method, since it actually fires the transition from “pending” to “published” status. <br>第 28-39 行: 这是个有趣的方法,因为它实际上将状态从“待审”转换成“发布”。 ** Line 33-34: Since we were clever, we passed the path as checkbox value, so that we can now simply traverse to it. <br>第 33-34 行: 由于我们的明智,我们把通过的路径作为了检查框的值,所以我们现在可以简单地穿过它。 ** Line 36-37: Once we have the message, we get its process container and fire the transition. <br>第 36-37 行: 一旦我们有了消息,我们将得到它的处理容器和转换 The new review view can now be registered using the pages directive: <br>新的复审视图现在可以用页面语句注册了: <pre><nowiki> 1 <pages 2 for="book.messageboard.interfaces.IMessageBoard" 3 class=".views.Review" 4 permission="book.messageboard.PublishContent" 5 layer="board"> 6 <page name="review.html" template="board_review.pt"/> 7 <page name="updateStatus.html" attribute="updateStatus"/> 8 </pages> </nowiki></pre> Now restart Zope 3. Before we can enjoy publishing messages, we need to automate the transition from the “private” to “pending” status. To do that, go to the “default” Site-Management folder, and from there to your “publish-message” workflow definition. There you will find an option called “Manage Transitions”. Click on it and choose the transition named “private_pending”. In the following edit form, there is a “Trigger Mode” option that is set to “Manual”. Set it to “Automatic”. This will cause the messages to move automatically from “initial” to “pending”. If you now create a message, it will be automatically placed on the review list, from which you can then publish it as messageboard moderator. If you do not want any workflow at all, you can also set the “pending_published” “Trigger Mode” to “Automatic” and all newly created messages will automatically be published. <br>现在重启 zope 3,之前我们已经完成了消息发布,现在我们需要自动将状态从“私有”变成“待审”。为了做到这一点,到“缺省”的站点管理文件夹,从那到你的“消息发布” 工作流定义。你可以发现有个选项叫“Manage Transitions”。点击它并选择名为 “private_pending” 的转换。在下面的编辑表单中有个 “Trigger Mode” 是被设为 “Manual(手动)”的。将其设为“Automatic(自动)”。这将引起消息自动从 “initial” 状态变为 “pending” 状态。如果你现在创建一个消息的话,它将自动出现在复审列表中,以便你可以作为留言薄版主来发布它。如果你根本不想用任何工作流的话,你也可以将 “pending_published” 的 “Trigger Mode” 设为 “Automatic” ,这样所有新建的消息就会被自动发布了。 PIC Figure 24.3: Review of all pending messages. <br>
返回至
Zope3宝典/开发新皮肤
。