Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Plone add-on that allows to associate users groups with content objects

Project description


This package is a Plone add-on that allows to associate users groups with content objects. It works this way: the content type class implement IObjectWithGroup, normally inheriting from ObjectWithGroupMixin, and this package takes care of creating a correspondent users group for each new content object.


Tested with Plone 3.2.3, probably works with 3.x and 4.x.

Example usage

Use case: We want to create a Company content type. Each Company must have a correspondent users group.

First we create the content type class. It could be a common Archetype class, but here we’ll create a simpler one, without the AT base classes. We’ll use ObjectWithGroupMixin from the base module in order to get associated group support:

>>> from zope.event import notify
>>> from 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.__name__ = id
...         self.title = title
...         notify(ObjectInitializedEvent(self))
...     def getId(self):
...         return
...     def Title(self):
...         return self.title
...     def setTitle(self, title):
...         self.title = title
...         notify(ObjectEditedEvent(self))
...     def delete_me(self):
...         notify(ObjectRemovedEvent(self))
... = self.title = None

Now we can create a Company instance and see if we get a correspondent group created:

>>> 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()

Let’s check if the group’s name and title were generated as expected by the ContentWithGroupMixin class:

>>> c.getId() in c.get_group_name()
>>> c.Title() in c.get_group_title()

Let’s change the company title and see if the group’s title also changes:

>>> c.setTitle('ACME co.')
>>> group = gtool.getGroupById(c.get_group_name())
>>> group.getProperty('title') == c.get_group_title()

Let’s delete the company and see if the group is also removed:

>>> group_name = c.get_group_name() # Save the group name before it's
>>>                                 # deleted.
>>> c.delete_me()
>>> gtool.getGroupById(group_name) is None

Customizing aspects of group creation, removal and edition

The group managing is done through the IGroupManager interface. An instance of this interface is acquired via adaptaion every time a group operation has to be done. One can customize the group managing operations by registering an adapter for an specific content type, providing IGroupManager.

The default adapter is registered in ZCML like this:


In the groupmanager module there’s also the DGPGroupsGroupManager which uses the DynamicGroupsPlugin. It allows for creation of dynamic groups, i.e, the members of the group are dynamically calculated.



0.1b3 - 18mai2010

  • Removed buggy cache in DynamicGroupsPlugin method.

0.1b2 - 18mai2010

  • Added support to DynamicGroupsPlugin, i.e, an IGroupManager which uses this plugin was created.
  • Added @@fix-content-groups view.

0.1b1 - 15feb2010

  • First release.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for collective.contentgroup, version 0.1b3
Filename, size File type Python version Upload date Hashes
Filename, size (17.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page