Few days ago Jean-Michel François proposed a useful patch for PlonePAS that can be applied for all Plone release until 3.2. Plone 3.3 will embed this patch.
How can we add this patch in a traceable way for an not so old Plone 3.1 or 3.2 ?
First, we can use the new release of Products.PlonePAS that should be compatible with our Plone installation. The second option is to add a monkey patch in the policy product of our site. One more monkey patch…
Some projects have so many monkey patches that it is difficult to know where is the code that run your site. Martin Aspeli did a tool to handle monkey patches in an elegant way for Zope 2 and Zope 3: collective.monkeypatcher. It allows you to plug your monkey patches with a simple ZCML directive. Later Gilles Lenfant added a control panel for Zope 2 to be able to have a visual way to follow patches with collective.monkeypatcherpanel.
How does it works?
In your buildout.cfg add :
eggs += collective.monkeypatcher collective.monkeypatcherpanel zcml += collective.monkeypatcher collective.monkeypatcherpanel
To create patches add a ‘patches.py‘ file in your egg (if you have more than 2 or 3 patches you should create a directory). Our performance patch looks like this:
import copy
def enumerateUsers( self
, id=None
, login=None
, exact_match=False
, **kw
):
""" See IUserEnumerationPlugin.
"""
plugin_id = self.getId()
criteria=copy.copy(kw)
if id is not None:
criteria["id"]=id
if login is not None:
criteria["login"]=login
if not kw and id:
data = self._storage.get(id, None)
if data is None:
user_info = []
else:
user_info=[ { 'id' : self.prefix + id,
'login' : id,
'title' : data.get('fullname', id),
'description' : data.get('fullname', id),
'email' : data.get('email', ''),
'pluginid' : plugin_id } ]
else:
users=[ (user,data) for (user,data) in self._storage.items()
if self.testMemberData(data, criteria, exact_match)]
user_info=[ { 'id' : self.prefix + user_id,
'login' : user_id,
'title' : data.get('fullname', user_id),
'description' : data.get('fullname', user_id),
'email' : data.get('email', ''),
'pluginid' : plugin_id } for (user_id, data) in users ]
return tuple(user_info)
In the configure.zcml of your policy product add an include:
<include file="patches.zcml" />
The file patches.zcml will contain following code:
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:monkey="http://namespaces.plone.org/monkey"
i18n_domain="collective.monkeypatcher">
<include package="collective.monkeypatcher" file="meta.zcml" />
<monkey:patch
original="enumerateUsers"
replacement=".patches.enumerateUsers"
docstringWarning="false"
/>
</configure>
Run your buildout, start your site and the patch is applied. You can go in the Zope Control Panel to see how many patches are already compatible with this tool.
Just a quick note – there’s only l in my surname.
By: Martin Aspeli on 2009 July 13
at 2:10 pm
-_-’
And it was Jean-Michel François (aka toutpt) not Jean-François Michel.
By: encolpe on 2009 July 13
at 2:24 pm
Martin, you should get the people that produce the GNU spellchecker “aspell” to change their name — I firmly believe it’s the reason for most of the mis-spellings of your name.
By: Alexander Limi on 2009 July 13
at 8:44 pm
My name is correctly spelled. Thanks Encolpe.
By: Gilles Lenfant on 2009 August 10
at 2:07 am