Dolmen ContentType Extension:Folder
menhir.contenttype.folder的Python项目详细描述
menhir.contenttype.folder为
Dolmen
基于Grok
的应用程序。这种折叠式的有几个
展示自己的方式,允许编辑选择它是否应该
显示内容摘要或结构化分页呈现。
模式
Folder
没有特定的架构。它只使用
IDescriptiveSchema
来自dolmen.app.content,仅显示
title
和description
属性:
>>> from dolmen.content import schema >>> from menhir.contenttype.folder import Folder >>> print schema.bind().get(Folder) [<InterfaceClass dolmen.app.content.interfaces.IDescriptiveSchema>]
实例提供了一个功能齐全的folderish对象:
>>> from zope.container.interfaces import IContainer >>> folder = Folder(title=u"Some title") >>> IContainer.providedBy(folder) True
Folder
类继承自grokcore.content
orderedcontainer:容器的键是orderable(read mutable):
>>> 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.containerIContainer
。- 使用规范化的方法合并“复合视图”,以获得
默认视图名称。现在我们检查视图是否存在,如果它是
有效的
IPage
。
0.3(2011-02-14)
- 更新了dolmen.content中的最新更改, dolmen.app.content和dolmen.app.container。
- 已清理依赖项。
0.2(2010-07-27)
- 已更正的包装(缺少图标)
0.1(2010-07-19)
- 初始版本