wikify: v. Act of wikifying anything whether it is by nature or art wikifyable or not.
The new wiki feature added to the framework allows to add a complete functional site wiki to your app in more or less a minute time (no, really, that's actually what it takes).
Disclaimer: most people will try to follow this guide with not much care of their keyboards, mouses etc. (as this is so simple and so super). The author of this recipe will not be responsible of soda spilling on any device or other equipment damage caused by sandwich sauces.
Note: wiki is available since about web2py 2.x or newer (not sure which exact version, you can check the feature anouncement at the web2py users Google group anyway)
Let's go step by step trough the recipe for deploying the whole wiki interface for your project:
1) Tell web2py we want to expose the wiki interface to the visitor
# This goes in the controller which will present # the wiki interface (usually default.py) def wiki(): return auth.wiki()
2) Create and edit a <controller>/wiki.html view with the following lines to present the wiki document or any other wiki interface element with the page
{{extend 'layout.html'}} <!-- Note that the response item named content contains the helper returned by the auth.wiki() call and you can choose where to place it within your view layout --> {{=content}}
I'd like to go on with more steps but that's it. There's a fully featured wiki interface for any app user with CRUD, tagging, menus an much more waiting at http://<app url>/<controller>/wiki
Customizing the wiki feature
Sometimes you'll need to customize the wiki db records managed by the Auth interface or expose customized forms for wiki CRUD. This is not allowed by default, since the wiki model is defined only after the wiki interface is requested with the auth.wiki() method. To allow access to the wiki specific model you must add the following sentence to your model file (i.e. db.py)
# Make sure this is called after the auth instance is created auth.wiki(resolve=False)
By using that line in your model, the wiki tables will be accessible (i.e. wiki_page and wiki_tag) for custom CRUD or other db tasks. Note that you still have to call auth.wiki() in the controller in order to expose the wiki interface, since resolve=False instructs the Auth class to avoid adding the wiki feature to the response. The wiki tables will be now available in the app default db interface (<app>/appadmin)
Another customization possible is adding extra fields to the standard wiki tables (in the same way as with the auth_user table). Here is how:
# This line adds a blob field to the wiki_page table auth.settings.extra_fields["wiki_page"] = [Field("ablob", "blob"),]
Wiki custom I/O example
This example was taken from a post by villas from the web2py users group
# Here we fetch the page content for the wiki with "index" slug # Use .body for Markmin or .html to get the processed input content = db(db.wiki_page.slug=="index").select().first().body
Comments (1)
1
wen-gong-10380 11 years ago
got 401 UNAUTHORIZED where accessing url: http://127.0.0.1:7000/w2p_tutor/default/wiki/_editmedia/index
replies (2)