石圈内容类型扩展:文件夹
项目描述
menhir.contenttype.folder 为基于 Dolmen 的 Grok 应用程序提供文件夹式内容。此文件夹式类型有几种显示方式,允许编辑器选择是否显示内容的摘要或结构化和分页的渲染。
模式
文件夹没有特定的模式。它只使用来自 dolmen.app.content 的 IDescriptiveSchema,仅暴露 title 和 description 属性。
>>> from dolmen.content import schema >>> from menhir.contenttype.folder import Folder >>> print schema.bind().get(Folder) [<InterfaceClass dolmen.app.content.interfaces.IDescriptiveSchema>]
实例化提供了一个功能齐全的文件夹式对象。
>>> from zope.container.interfaces import IContainer >>> folder = Folder(title=u"Some title") >>> IContainer.providedBy(folder) True
Folder 类从 grokcore.content 有序容器继承:容器键是可排序的(可读可写)。
>>> from grokcore.content import OrderedContainer >>> isinstance(folder, OrderedContainer) True
本地测试
设置环境
>>> from zope.component.hooks import getSite >>> root = getSite()
创建一个文件夹。
>>> from menhir.contenttype.folder import Folder >>> root[u'folder'] = Folder() >>> folder = root.get(u'folder')
创建一个虚拟内容类型,以便我们可以将虚拟内容放入文件夹。
>>> import dolmen.content as content >>> class Dummy(content.Content): ... content.name("Dummy") ... # content.icon("dummy.png")
用一些虚拟内容填充文件夹。
>>> folder[u'books'] = Dummy(title=u"Books") >>> folder[u'films'] = Dummy(title=u"Films") >>> folder[u'music'] = Dummy(title=u"Music")>>> folder[u'subfolder'] = Folder(title=u"SubFolder") >>> folder[u'subfolder'][u'subfolder2'] = Folder(title=u'SubFolder Two') >>> folder[u'subfolder'][u'bogus'] = Dummy(title=u'Bogus') >>> folder[u'subfolder'][u'subfolder2'][u'hocus'] = Dummy(title=u"hocus")
验证内容是否正确。
>>> dict([x for x in folder.items()]) {u'films': <menhir.contenttype.folder.Dummy object at ...>, u'books': <menhir.contenttype.folder.Dummy object at ...>, u'music': <menhir.contenttype.folder.Dummy object at ...>, u'subfolder': <menhir.contenttype.folder.folder.Folder object at ...>}
让我们从浏览器的角度来看看。
>>> from zope.publisher.browser import TestRequest >>> from zope.component import getMultiAdapter >>> request = TestRequest()>>> view = getMultiAdapter((folder, request), name=folder.selected_view) >>> view.__class__.__name__ 'FolderListing'>>> view.update() >>> print view.render() <div class="folder-listing"> <h1>Content of the folder</h1> <div><table class="listing sortable"> <thead> <tr> <th>Title</th> <th>Modification date</th> </tr> </thead> <tbody> <tr class="even"> <td><a href="http://127.0.0.1/folder/books">books</a></td> <td></td> </tr> <tr class="odd"> <td><a href="http://127.0.0.1/folder/films">films</a></td> <td></td> </tr> <tr class="even"> <td><a href="http://127.0.0.1/folder/music">music</a></td> <td></td> </tr> <tr class="odd"> <td><img src="http://127.0.0.1/@@/menhir-contenttype-folder-folder-IFolder-icon.png" alt="Folder" width="16" height="16" border="0" /> <a href="http://127.0.0.1/folder/subfolder">SubFolder</a></td> <td></td> </tr> </tbody> </table></div> </div>
我们还应该查看默认视图(索引)。
>>> view = getMultiAdapter((folder, request), name='index') >>> view.__class__.__name__ 'SelectedView'>>> view.update() >>> print view.render() <div class="folder-listing"> <h1>Content of the folder</h1> <div><table class="listing sortable"> <thead> <tr> <th>Title</th> <th>Modification date</th> </tr> </thead> <tbody> <tr class="even"> <td><a href="http://127.0.0.1/folder/books">books</a></td> <td></td> </tr> <tr class="odd"> <td><a href="http://127.0.0.1/folder/films">films</a></td> <td></td> </tr> <tr class="even"> <td><a href="http://127.0.0.1/folder/music">music</a></td> <td></td> </tr> <tr class="odd"> <td><img src="http://127.0.0.1/@@/menhir-contenttype-folder-folder-IFolder-icon.png" alt="Folder" width="16" height="16" border="0" /> <a href="http://127.0.0.1/folder/subfolder">SubFolder</a></td> <td></td> </tr> </tbody> </table></div> </div>
最后,让我们将文件夹布局更改为此包中提供的完整渲染视图。
>>> folder.selected_view = u'compositeview' >>> view = getMultiAdapter((folder, request), name=folder.selected_view) >>> view.__class__.__name__ 'CompositeView'>>> view.update() >>> print view.content() <div class="composite-view"> <h1></h1> <div class="composite-body sequence-block"> <div><form action="http://127.0.0.1" method="post" enctype="multipart/form-data"> <h1>books</h1> </form> </div> </div> <div class="composite-body sequence-block"> <div><form action="http://127.0.0.1" method="post" enctype="multipart/form-data"> <h1>films</h1> </form> </div> </div> <div class="composite-body sequence-block"> <div><form action="http://127.0.0.1" method="post" enctype="multipart/form-data"> <h1>music</h1> </form> </div> </div> <div class="composite-body sequence-block"> <div><div class="folder-listing"> <h1>Content of the folder</h1> <div><table class="listing sortable"> <thead> <tr> <th>Title</th> <th>Modification date</th> </tr> </thead> <tbody> <tr class="even"> <td><img src="http://127.0.0.1/@@/menhir-contenttype-folder-folder-IFolder-icon.png" alt="Folder" width="16" height="16" border="0" /> <a href="http://127.0.0.1/folder/subfolder/subfolder2">SubFolder Two</a></td> <td></td> </tr> <tr class="odd"> <td><a href="http://127.0.0.1/folder/subfolder/bogus">bogus</a></td> <td></td> </tr> </tbody> </table></div> <BLANKLINE> </div> </div> </div> </div>
变更日志
0.4 (2011-02-14)
模式不再包括 IViewSelector。这阻止了字段在自动生成的表单中显示。
IFolder 现在从 zope.container 继承 IContainer。
使用统一的方法获取默认视图名称,合并了“复合视图”。现在我们测试视图是否存在以及它是否是有效的 IPage。
0.3 (2011-02-14)
针对 dolmen.content、dolmen.app.content 和 dolmen.app.container 的最新更改进行了更新。
清理了依赖关系。
0.2 (2010-07-27)
修正了打包(缺少图标)。
0.1 (2010-07-19)
初始发布
项目详情
关闭
menhir.contenttype.folder-0.4.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3bd4ed44aac5e38054999a330a193bc774e33a117515fc1f0022ac5b7e271cc2 |
|
MD5 | 0bee4bc138c00d8f9f48e0d30e4b22c1 |
|
BLAKE2b-256 | ae8cda2ff43d87030d53ec9c377e2dc2fe25d74f62b1c433db2841029030cea5 |