betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

26 May 2008

How to add a Zwiki programmatically

Up to your own choices

Zwiki of course has a method manage_addWiki to add a wiki from a script. But this will add the "basic" standard wiki to your Zope ZODB. We had a plan here where we would add a special wiki for each user account... wasn't done (yet), but out of it came a simple code snippet that shows how to do it...


This is a method in one of our "container" products. It's not part of the class, as the plan was to run it from manage_afterAdd, but of course you could change it a bit and run it from the class too (in which case you'd probably change "add_point" to "self").

def add_user_wiki(add_point):
    # we're using BTreeFolder2
    # could be that someone wants a real big wiki
    # but also it's showing another difference to manage_addWiki
    add_point.manage_addProduct['BTreeFolder2'].manage_addBTreeFolder(
        'notebook', 'My Notebook Wiki')
    nb = add_point.notebook
    # add a wiki page with minimal welcome text
    nb.manage_addProduct['ZWiki'].manage_addZWikiPage('Hello')
    # set properties
    nb.manage_addProperty('allowed_page_types',
        ['rst','html'],'lines')
    nb.manage_addProperty('default_page','Hello','string')
    # set permissions
    nb.manage_permission('Zwiki: Add pages',
        ('staff','account','user'), acquire=1)
    nb.manage_permission('Zwiki: Add comments',
        ('staff','account','user'), acquire=1)
    nb.manage_permission('Zwiki: Edit pages',
        ('staff','account','user'), acquire=1)
    nb.manage_permission('Zwiki: Delete pages',
        ('staff','account','user'), acquire=1)
    nb.manage_permission('Delete objects',
        ('staff','account','user'), acquire=1)
    nb.manage_permission('Copy or Move',
        ('staff','account','user'), acquire=1)
    # shortcut to create catalog, create index_html:
    nb.Hello.upgradeAll()
    hello_text = """Hello!
----------

This is your **notebook**, where you can leave notes,
instructions, thoughts,... anything for you and your
friends to work together!

You can edit the text of this page and add new pages
as you please."""
    nb.Hello.edit(text=hello_text, log='initial content', type='rst')

The result is a properly set up wiki, but with just this one page and the permissions set to allow actions for a certain set of roles only. It wouldn't make sense to have a method like this in the Zwiki code, as the code is mainly setup and choices of configuration - everybody would likely want to run something different here.

Posted by betabug at 11:26 | Comments (0) | Trackbacks (0)
ch athens
Life in Athens (Greece) for a foreigner from the other side of the mountains. And with an interest in digital life and the feeling of change in a big city. Multilingual English - German - Greek.
Main blog page
Recent Entries
Best of
Some of the most sought after posts, judging from access logs and search engine queries.

Apple & Macintosh:
Security & Privacy:
Misc technical:
Athens for tourists and visitors:
Life in general:
<< Η εκδίκηση τον γρήκλης | Main | Open Source Conference in Athens >>
Comments
There are no comments.
Trackbacks
You can trackback to: http://betabug.ch/blogs/ch-athens/831/tbping
There are no trackbacks.
Leave a comment