用于筛选收集结果的plone加载项。
collective.collectionfilter的Python项目详细描述
集合.collectionfilter
收集结果的分面导航过滤器。
此plone 5插件允许您筛选集合结果以获取其他目录元数据。 例如,可以添加主题筛选器,也可以添加作者或门户类型的筛选器。 这也可用于构建标记云。
可以扩展筛选器类型(请参见: collective.collectionfilter.vocabularies )。
有三个Portlet/Tiles可用于筛选:
< DL> 收集过滤器使用Portlet筛选结果
向您想要的任何上下文(很可能是源集合)添加上面的任意多个筛选portlet 并为其分配一个包含结果的集合。
从筛选器中选择值时,结果将异步加载到容器中。 使用字段 内容选择器中定义的选择器。确保选择器存在于 源集合模板和显示筛选结果的目标页。
马赛克集成
这三块瓷砖可以在马赛克编辑器中多次添加。只需在"插入"菜单中选择它们 然后给它分配一个集合。要显示集合的结果,只需添加 现有内容 链接到分配给您的筛选磁贴的同一集合的磁贴。
TOdo:现在集合需要一个默认的视图模板,它用一个唯一的选择器包装结果列表 在内容核心容器中。因此collectionfilter可以从 将集合放入现有内容磁贴中的容器中。
地理定位过滤器支持
如果安装了collective.geolocationBehavior,则此包提供一个单张js maps tile/portlet 如果 igeologatable 信息可用,则显示集合结果的每个项。 此外,您还可以激活 缩小结果范围 复选框以缩小收集结果范围,并 如果用户移动或缩放地图,则提供其他可用的筛选磁贴/Portlet。
我们提供了一个额外的包来安装所有需要的依赖项及其相应的版本。 只需在您的构建中的某个地方执行此操作:
[buildout] ... eggs += collective.collectionfilter[geolocation] ...
重载GroupByCriteria
collective.collectionfilter.vocabularies.groupbycriteria是一个单例,注册为全局实用程序,用于提供可能的索引列表,其中的分组值将提供您的筛选条件。
它使用这样的数据结构:
self._groupby = { it: { # Index name 'index': it, # Name of the index to use 'metadata': it, # Name of the metadata column to use 'display_modifier': _ , # Function to prepare the metadata column value for displaying 'index_modifier': None, # Function to transform the index search value. 'value_blacklist': [], # Blacklist of index values, which should not included in the filter selection. Can be a callable. 'sort_key_function': lambda it: it['title'].lower(), # sort key function. defaults to a lower-cased title } for it in metadata }
如您所见,标准的groupbycriteriavocabulary实现意味着索引名与元数据列名相同。 此外,我们使用 collective.collectionfilter 消息目录作为标准显示修饰符(您可以在 collective.collectionfilter 域下注册翻译以转换索引值)。
如果需要特殊的显示修饰符,或者索引列或元数据列没有相同的标识符,则可以修改此数据结构。 为此,为适应groupbycriteria实用程序的 iggroupbymodifier 注册适配器。 在这个适配器中,您可以修改已经填充的groupby属性(不要使用>groupby,这是一个属性方法,目前尚未完成。
就是这样。
编写适配器:
# -*- coding: utf-8 -*- from collective.collectionfilter.interfaces import IGroupByCriteria from collective.collectionfilter.interfaces import IGroupByModifier from zope.component import adapter from zope.interface import implementer sort_map = { 'VALUE1': 3, 'VALUE2': 1, 'VALUE3': 2, } def subjectsort(it): # Sorts the value after a fixed sort map val = it['title'] return sort_map.get(val, 0) @implementer(IGroupByModifier) @adapter(IGroupByCriteria) def groupby_modifier(groupby): groupby._groupby['Subject']['display_modifier'] = lambda x: x.upper() groupby._groupby['Subject']['sort_key_function'] = subjectsort groupby._groupby['my_new_index'] = { 'index': 'my_new_index', 'metadata': 'my_new_index_metadata_colum', 'display_modifier': lambda it: u'this is awesome: {0}'.format(it) }
注册适配器:
<configure xmlns="http://namespaces.zope.org/zope"> <adapter factory=".collectionfilter.groupby_modifier" name="modifier_1" /> </configure>
适配器由collective.collectionfilter.vocablaries.groupbycriteria.groupby调用
兼容性
此软件包与PLONE 5及以上版本兼容。注意,在5.0中,一些功能被减少了,比如ajax加载搜索结果。 如果您的主题不能很好地与ajax加载一起工作,可以在注册表中或通过diazo覆盖它。
作者
- 约翰内斯拉格姆
- 彼得·霍尔泽
这个包基于collective.portlet.collectionfilter 和collective.portlet.collectionbysubject