plone附加组件,允许将用户组与内容对象关联
collective.contentgroup的Python项目详细描述
概述
这个包是一个plone插件,允许将用户组与 内容对象。它是这样工作的:content-type类实现 IObjectWithGroup,通常从ObjectWithGroupMixin继承, 这个包负责为每个新用户创建一个对应的用户组 内容对象。
兼容性
用plone 3.2.3测试,可能与3.x和4.x一起工作。
示例用法
用例:我们想要创建一个Company内容类型。每个Company必须 有一个通讯用户组。
首先我们创建内容类型类。它可能是一个普通的原型类, 但是在这里我们将创建一个更简单的,没有at基类的。我们会用 ObjectWithGroupMixin从base模块获取关联 组支持:
>>> from zope.event import notify >>> from zope.app.container.contained import ObjectRemovedEvent >>> from Products.Archetypes.event import (ObjectInitializedEvent, ... ObjectEditedEvent) >>> from collective.contentgroup.base import ObjectWithGroupMixin >>> class Company(ObjectWithGroupMixin): ... __parent__ = None ... ... def __init__(self, id, title): ... self.id = self.__name__ = id ... self.title = title ... notify(ObjectInitializedEvent(self)) ... ... def getId(self): ... return self.id ... ... def Title(self): ... return self.title ... ... def setTitle(self, title): ... self.title = title ... notify(ObjectEditedEvent(self)) ... ... def delete_me(self): ... notify(ObjectRemovedEvent(self)) ... self.id = self.title = None
现在我们可以创建一个Company实例,看看是否有对应的 已创建组:
>>> from Products.CMFCore.utils import getToolByName >>> c = Company('acme', 'The ACME Corporation') >>> gtool = getToolByName(portal, 'portal_groups') >>> group = gtool.getGroupById(c.get_group_name()) >>> group.getProperty('title') == c.get_group_title() True
让我们检查组的名称和标题是否按 ContentWithGroupMixin类:
>>> c.getId() in c.get_group_name() True >>> c.Title() in c.get_group_title() True
让我们更改公司名称并查看组的名称是否也更改:
>>> c.setTitle('ACME co.') >>> group = gtool.getGroupById(c.get_group_name()) >>> group.getProperty('title') == c.get_group_title() True
让我们删除公司并查看是否也删除了组:
>>> group_name = c.get_group_name() # Save the group name before it's >>> # deleted. >>> c.delete_me() >>> gtool.getGroupById(group_name) is None True
自定义组的创建、删除和编辑方面
组管理通过IGroupManager接口完成。实例 每次组操作 待完成。可以通过注册 特定内容类型的适配器,提供IGroupManager。
默认适配器在zcml中注册如下:
<adapter for="*" provides=".interfaces.IGroupManager" factory=".groupmanager.PortalGroupsGroupManager" />
在groupmanager模块中还有DGPGroupsGroupManager,它 使用dynamicgroupsplugin。 它允许创建动态组,即组的成员是 动态计算。
学分
- 拉斐尔·奥利维拉:作者。
更改日志
2010年1月3日-18日
- 已删除dynamicgroupsplugin方法中的错误缓存。
2010年1月2日-18日
- 添加了对dynamicgroupsplugin的支持,即使用此 插件已创建。
- 添加了@@修复内容组视图。
2010年2月1日-15日
- 第一次释放。