[Mailman-Developers] extend.py examples

Barry A. Warsaw barry@zope.com
Tue, 22 Jan 2002 01:25:03 -0500


>>>>> "ES" == Ellen Spertus <spertus@mills.edu> writes:

    ES> Does anyone have an extend.py file that I can see to get an
    ES> idea of the functionality?

I used to, but I don't think I've got it online anymore.

It all depends on what you want to do.  Let's say for example, you
want to disable the membership admin pages, perhaps because you're
doing membership from an LDAP database instead of from Mailman's
internal data structions.  Here's how to simply rip out that page.

-------------------- snip snip --------------------extend.py
# Extension mechanism for a list.  This removes the entire Membership GUI from
# the list of components, the effect of which is to rip out the membership
# admin pages.

from Mailman.Logging.Syslog import syslog
from Mailman.Gui import Membership

# This is necessary in order to remove the `member' category.  See
# MailList.GetConfigCategories() for details.
def makefunc(oldfunc):
    def new_GetConfigCategories(oldfunc=oldfunc):
        categories = oldfunc()
        categories.keysinorder.remove('members')
        return categories
    return new_GetConfigCategories


def extend(mlist):
    newgui = []
    for gui in mlist._gui:
        # Ignore the Membership component
        if isinstance(gui, Membership):
            continue
        newgui.append(gui)
    mlist._gui = newgui
    # Interpose our specialized method
    oldfunc = mlist.GetConfigCategories
    mlist.GetConfigCategories = makefunc(oldfunc)
-------------------- snip snip --------------------

To write an effective extend.py, you do have to probably know a lot
about the internals of the MailList class.

Hope this helps,
-Barry