跳转到主要内容

石圈内容类型扩展:文件夹

项目描述

menhir.contenttype.folder 为基于 DolmenGrok 应用程序提供文件夹式内容。此文件夹式类型有几种显示方式,允许编辑器选择是否显示内容的摘要或结构化和分页的渲染。

模式

文件夹没有特定的模式。它只使用来自 dolmen.app.contentIDescriptiveSchema,仅暴露 titledescription 属性。

>>> 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.contentdolmen.app.contentdolmen.app.container 的最新更改进行了更新。

  • 清理了依赖关系。

0.2 (2010-07-27)

  • 修正了打包(缺少图标)。

0.1 (2010-07-19)

  • 初始发布

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分发

menhir.contenttype.folder-0.4.tar.gz (8.0 kB 查看哈希值)

上传时间

支持者

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误日志StatusPageStatusPage状态页面