need a simple wiki...

1,262 views
Skip to first unread message

Massimo Di Pierro

unread,
Aug 19, 2012, 7:45:34 PM8/19/12
to web...@googlegroups.com
...this is now a core web2py feature. Give it a try:

1) create a new app
2) edit default.py so that

   def index(): return auth.wiki()

3) navigate to http://..../yourappname

As you can see you have a wiki. Pages have permissions (group that can read, groups that can write, tags, and corresponding menu items). Each page has associated media files (accessible if you have permission to access the page).

It understands the oembed protocol. If you just type the link of a youtube page, it embeds the video for example.

wiki media are embedded with @////5/slug.jpg where 5 is the id of the media file. 

You can embed components with @{component:controller/function/args) -> LOAD('controller','function',args=args)
(not sure about this syntax, may still change it)

You can make multiple users groups wiki_editor and wiki_author. You can force authors to create pages with a prefix which is their username.

    def index(): return auth.wiki(force_prefix='%(username)s')

The plan is to deprecate plugin_wiki since this handles most of it and better.

Give it a try.

Pystar

unread,
Aug 19, 2012, 9:17:29 PM8/19/12
to web...@googlegroups.com
I just gave it a try and it didnt work as stated. 
In  my index.py file I have the return auth.wiki() directive there but whenever I try to view the page I get a login page and after that a 401 unauthorized error.

Massimo Di Pierro

unread,
Aug 20, 2012, 12:45:34 AM8/20/12
to web...@googlegroups.com
Try login into admin, then visit the page again.

It should create a group "wiki_editor" and make you member automatically.

Pystar

unread,
Aug 20, 2012, 1:43:34 AM8/20/12
to web...@googlegroups.com
Max, 
Tried it, still gives me the "401 unauthorized" error.

Calycé

unread,
Aug 20, 2012, 5:55:50 AM8/20/12
to web...@googlegroups.com
Pystar,

In the admin, add a group named 'wiki_editor' and put yourself in that group. Logout (if you were logged in the application), login and normally voilà!
That's what I did and it worked.

rif

unread,
Aug 20, 2012, 10:29:31 AM8/20/12
to web...@googlegroups.com
The Search Pages is also not working. If I enter a page title and hit Submit I get:

Traceback (most recent call last):
  File "/home/rif/Downloads/web2py/gluon/restricted.py", line 205, in restricted
    exec ccode in environment
  File "/home/rif/Downloads/web2py/applications/hopa/controllers/default.py", line 67, in <module>
  File "/home/rif/Downloads/web2py/gluon/globals.py", line 182, in <lambda>
    self._caller = lambda f: f()
  File "/home/rif/Downloads/web2py/applications/hopa/controllers/default.py", line 13, in index
    return auth.wiki()
  File "/home/rif/Downloads/web2py/gluon/tools.py", line 3146, in wiki
    return self._wiki.read(slug)['content'] if slug else self._wiki()
  File "/home/rif/Downloads/web2py/gluon/tools.py", line 4573, in __call__
    return self.search()
  File "/home/rif/Downloads/web2py/gluon/tools.py", line 4794, in search
    content.append(DIV(T("No results",_class='w2p_wiki_form')))
NameError: global name 'T' is not defined

Rob_McC

unread,
Aug 20, 2012, 10:29:58 AM8/20/12
to web...@googlegroups.com

Thanks guys,

I wanted to try out...

I followed what Pystar did,  (see screenshots), and it worked.

Version:

Version 2.0.0 (2012-08-09 04:44:17) dev

and there is a comment in default.py about this.

   
if you need a simple wiki simple replace the two lines below with:
   
return auth.wiki()


>  If you just type the link of a youtube page, it embeds the video for example.

I could only get a LINK to youtube, and not an embed


## Index Rob

page content

http
://youtu.be/AHBjHCAUjus



Looks interesting,

Rob

Screen Shot 2012-08-20 at 10.19.26 AM.png
Screen Shot 2012-08-20 at 10.21.26 AM.png

Alan Etkin

unread,
Aug 20, 2012, 11:02:34 AM8/20/12
to web...@googlegroups.com
Incredible, this saves a lot of features development in pyodel. I was very worried on how to provide video streamming with rbac in the elearning plugin. The new changes should make it very easier. I'll try the changes as soon as possible.

Thanks

Massimo Di Pierro

unread,
Aug 20, 2012, 11:52:07 AM8/20/12
to web...@googlegroups.com
The generated HTML is always cached in DB. The tag search is also quite efficient. It shows a tagcloud in the search page.

You can also do in views:

{{=auth.wiki('header')}}
...
{{=auth.wiki('footer')}}

etc. and edit the header, footer, etc as normal wiki pages.

Tim Michelsen

unread,
Aug 20, 2012, 3:21:40 PM8/20/12
to web...@googlegroups.com
> I just gave it a try and it didnt work as stated.
> In my index.py file I have the return auth.wiki() directive there but
> whenever I try to view the page I get a login page and after that a 401
> unauthorized error.
I also have a problem to create a new user (register) from the frontend.

With current git, I create a welcome app.
1) Then I try to register a user -> nothing happens after hitting submit
2) when I create a new user, I am not able to log in from the frontend
to that user.

What could be the reason?



Is there a way to test this without the authentication?

Massimo Di Pierro

unread,
Aug 20, 2012, 9:30:09 PM8/20/12
to web...@googlegroups.com
I think the problem is that we broke trunk as we are running some tests... 

Massimo Di Pierro

unread,
Aug 20, 2012, 11:27:26 PM8/20/12
to web...@googlegroups.com
I reverted trunk to the older Storage but this is not the end of this. We are still working to replace it in a backward compatible way....

Alan Etkin

unread,
Aug 21, 2012, 11:25:57 AM8/21/12
to web...@googlegroups.com
Two issues for debugging:

-In a new scaffolding app with auth.wiki() appadmin does not show wiki tables, but they are defined (db.tables() return their names).
-There's an auth_membership for wiki_editor with user_id set to None, I suppose it was created when loading the wiki feature without a logged in user

Rob_McC

unread,
Aug 21, 2012, 2:20:08 PM8/21/12
to web...@googlegroups.com

Do I have to set something to get this to embedd youtube?

Thanks,
Rob
## Index Rob

page content

http
://youtu.be/AHBjHCAUjus



Massimo Di Pierro

unread,
Aug 21, 2012, 2:28:31 PM8/21/12
to web...@googlegroups.com
You have to use 


else web2py does not know what oembed service to use. youtu.be is not a well known oembed service provider.

Tim Michelsen

unread,
Aug 21, 2012, 3:03:46 PM8/21/12
to web...@googlegroups.com
> I reverted trunk to the older Storage but this is not the end of this.
> We are still working to replace it in a backward compatible way....
OK, now it works.

But why do I always get "Registration needs Verification"?

Can this be switched off?


Rob_McC

unread,
Aug 21, 2012, 5:17:42 PM8/21/12
to web...@googlegroups.com

Thanks !

works perfectly.


> youtu.be is not a well known oembed service provider.

Funny the

 tag, is all they've been using to SHARE a link lately.

Also, the markmin syntax seems to work well.  http://web2py.com/examples/static/markmin.html







Massimo Di Pierro

unread,
Aug 21, 2012, 6:47:05 PM8/21/12
to web...@googlegroups.com
In principle you can extend the rules for autolinks by registering additional oembed services:

import re
from gluon.contrib.autolinks import EMBED_MAPS
EMBED_MAPS.append((re.compile('http://\S*?flickr.com/\S*'), 'http://www.flickr.com/services/oembed/'))

but this cannot be done in a model or controller. This must be done in a module (your own module) and then you import the module that performs the extensions.

villas

unread,
Aug 21, 2012, 8:33:37 PM8/21/12
to web...@googlegroups.com
1. How does the menu field work?

2. Are we going to expose automenu option for auth.wiki(automenu=False)?  A separate top level menu for each page is impractical,  so at least we could turn it off.

3. Can we have a configurable menu like we had with meta-menu on plugin_wiki?  I think that is great.

4. BTW  the link to Database Admin button doesn't seem to work at the moment (appadmin).

Many thanks, David

Massimo Di Pierro

unread,
Aug 21, 2012, 11:22:10 PM8/21/12
to web...@googlegroups.com
2. ok in trunk.
4. fixed in trunk
2+3.

right now the menu field is a path:

   /menu/submenu/subsubmenu

and based on the path the page is added to the menu. You can sort manues with

   /0:menu/2:submenu/3:subsubmenu

so menu is the top first top menu item, submenu is the second item in the menu submenu, etc.
For one more day is still negotiable. Do you prefer and approach like plugin_wiki instead? (all menu items in one page)?

Andrew

unread,
Aug 22, 2012, 7:20:27 AM8/22/12
to web...@googlegroups.com
Would you mind giving a simple example on how I could use markmin2pdf with the auth.wiki (or any markmin text in an app).    The book just gives a print example, but how would it be used for real in an app to view/print a pdf.   I'm also looking at pyfpdf but I think I'm getting mixed up between the two.  Or do I just use it as a stand alone app to create pdf docs ?

is the sample generic.pdf produced with markmin2pdf  in https://groups.google.com/forum/?fromgroups=#!searchin/web2py/markmin2pdf/web2py/WaATh3r6-20/AbxBGZmJpNAJ  still relevant today?

villas

unread,
Aug 22, 2012, 7:57:32 AM8/22/12
to web...@googlegroups.com
Regarding the menu,  I can see there is a point in having both:

1. The 'menu field' may be better for anyone wishing to change the menus dynamically.
2. The 'menu page' is ideal for those wishing to visualize the menu in one easy place.

My other reason for suggesting that is because you have already written the code for both. 

Maybe it could be implemented with the automenu parameter:
automenu='field'  | 'page:nameofmenupage' | None

If you think it is overkill to have two menu schemes,  then I would choose the plugin_wiki 'menu page'.   That was so simple that I managed to teach someone else to use it in seconds,  and that doesn't happen very often!

Thanks,  D

Massimo Di Pierro

unread,
Aug 22, 2012, 8:13:45 AM8/22/12
to web...@googlegroups.com
Having it both ways will be a mess. We need to choose one way.

villas

unread,
Aug 22, 2012, 8:34:33 AM8/22/12
to web...@googlegroups.com
Yes,  in that case I would personally recommend the plugin_wiki method,  it was above all easy (and I suppose that is what a wiki is all about?).

In any case,  the wiki should not be assumed to be always activated from the main index function of the site. 

I mean,  the wiki section might be available under app/default/wiki.  In which case the wiki menu should only appear from pages under that path.  All other areas of the site would have the normal menu.  I think it is already working like that,  I just wanted to mention it again so you don't change that  :)

Thanks.  D

Alan Etkin

unread,
Aug 26, 2012, 2:06:15 PM8/26/12
to web...@googlegroups.com

I mean,  the wiki section might be available under app/default/wiki.  In which case the wiki menu should only appear from pages under that path.  All other areas of the site would have the normal menu.  I think it is already working like that,  I just wanted to mention it again so you don't change that  :)

 
The wiki menu will appear only if you created an auth.wiki in the action controller, but only there, as far as I know.

Now, since crud.create(db.wiki_page) fails, wiki records appear to behave in a different way as normal.
Is there any help available for the new wiki feature?

What I want to do is to link other tables to wikis, for example add reference wiki_page fields in other table definitions, link more than one wiki to a table with list:reference wiki_page, in a word, access wiki tables with the usual command syntax.

Massimo Di Pierro

unread,
Aug 26, 2012, 2:50:51 PM8/26/12
to web...@googlegroups.com
You should be able to do:

in models/db.py

   wiki = auth.wiki()

in model/menu.py remove any reference to response.menu

in controllers/defaulty.py

   def index(): return wiki

Alan Etkin

unread,
Aug 26, 2012, 3:56:43 PM8/26/12
to web...@googlegroups.com
> The wiki menu will appear only if you created an auth.wiki in the action controller, but only there, as far as I know.

Thanks Massimo. That line is wrong. I meant that there's no wiki menu unless you create it, since if the action does not call wiki() the entry will not be added.

About crud.create(db.wiki_page) I belive there's a bug in somewhere, because doing a .select() of wiki_page works as expected. I will post back if I find a patch

Alan Etkin

unread,
Aug 26, 2012, 4:12:59 PM8/26/12
to web...@googlegroups.com
Found the problem. No bug, it was my code. I was trying to use a wiki table before calling auth.wiki(), so the tablename was not available :P

Alan Etkin

unread,
Aug 27, 2012, 7:06:00 AM8/27/12
to web...@googlegroups.com
I'be been testing the wiki for a while and have some random comments.

-I created .wiki() in the model and used it in a given function, but it doesn't add by default the menu entries
-Doing auth.wiki() in any function is not apt for lazyness. i'd add the option to decorate them:

@auth.wikify()
def afunction():
   
...
   
return dict()

-And also a app-wide command to make any action a wiki would be cool
-I think that the scaffolding layout should have a wiki block or similar to automagically put the wiki contents
-There's need for sort of a request arguments handling, to support using the wiki with other objects in the view. For instance:
If you create the wiki in the model to allow crud with appadmin, insert/select/... commands fail for wiki rewrites the request
I managed to filter the appadmin controller in the wiki code so it prevents it, but it will fail with other features like custom .grid objects arguments exposed in the same view

Current auth.wiki rocks, but with those enhancements, I think it would be even better.

Alan Etkin

unread,
Aug 27, 2012, 7:20:54 AM8/27/12
to web...@googlegroups.com
> El lunes, 27 de agosto de 2012 08:06:00 UTC-3, Alan Etkin escribió:I'be been testing the wiki for a while and have some random
> comments.

Wouldn't be better to separate the Wiki class setup and plugging phases?

For example, set welcome by default with something like:

# model
wiki = Wiki(opt=val)

# controller
@auth.wiki() # optional
def index():
    return dict()

# layout.html
{{block wiki}}
{{if "_wiki" in locals():}}
  {{=_wiki.content}}
{{pass}}
{{end}}

Massimo Di Pierro

unread,
Aug 27, 2012, 5:49:36 PM8/27/12
to web...@googlegroups.com
I am not sure I fully understand the reason for these suggestions. You seem to need access to the Wiki object in more then one controller. Why?
I can see why one may want to define the wiki outside of an action to benefit from the menu (if you delete models/menu.py) all actions will have the wiki menu but only one action should actually expose the menu. Perhaps I misunderstood.

massimo

Alan Etkin

unread,
Aug 28, 2012, 7:17:41 PM8/28/12
to web...@googlegroups.com
> You seem to need access to the Wiki object in more then one controller. Why?

One case of use is described in issue 962 (now fixed, about re-using the wiki model)
Other possible case: I intend to give access to wiki documents from a view in a plugin, i.e.:

controllers/plugin_bavaria.py

def wiki():
   
# another wiki interface
   
# for customizing with
   
# plugin layout elements
   
return auth.wiki()

link in plugin_bavaria/views/menu.html

{{=more_plugin_stuff}}
<!-- Ja, a link to a real bavarian speciality!-->
<!-- Not sure if I am using a valid link here -->
{{=URL(c="plugin_bavaria", f="wiki.html", args=["my-bavarian-menu-slug",]))}}

I can see why one may want to define the wiki outside of an action to benefit from the menu (if you delete models/menu.py) all actions will have the wiki menu but only one action should actually expose the menu.

You're right, I was not following correctly the way the new wiki works.
 

Andrew W

unread,
Sep 3, 2012, 1:51:47 AM9/3/12
to web...@googlegroups.com
Hi Massimo,

Some questions on auth.wiki,  in anticipation of some details in the book.
Have you finalised the syntax for adding components ?
How do I embed media eg images?  Do I follow the markmin reference doc, or is it a combo of the two:  I've added the media to the page
[[some image @////5/slug.jpg right 200px]] or [[some image http://www.web2py.com/examples/static/web2py logo.png right 200px]] or just @////5/slug.jpg.

I'm updating pages but they don't get refreshed - is there caching on by default ?  This might have been causing my earlier issue as I'm not seeing an updated page.
Does you have to be in default/index to call auth.wiki() ?
Do users have to log in to see the wiki pages ?  The login screen comes up by default.  I would like a wik page to come up by default.

Thanks

Andrew W

Massimo Di Pierro

unread,
Sep 3, 2012, 9:34:25 AM9/3/12
to web...@googlegroups.com


On Monday, 3 September 2012 00:51:47 UTC-5, Andrew W wrote:
Hi Massimo,

Some questions on auth.wiki,  in anticipation of some details in the book.
Have you finalised the syntax for adding components ?

I think we can keep @{component:url}
 
How do I embed media eg images?  Do I follow the markmin reference doc, or is it a combo of the two:  I've added the media to the page
[[some image @////5/slug.jpg right 200px]] or [[some image http://www.web2py.com/examples/static/web2py logo.png right 200px]] or just @////5/slug.jpg.

The syntax is @/app/controller/function/args maps into URL('app','controller','function',args=args) and you can omit app/controller and args. Thus simply @///function. This can be used as an URL anywhere in the markmin source. If it is the URL of an image or a video or an audio, file, markmin will embed the content sing the appropriate tag (<img>, <video>, <audio>).


I'm updating pages but they don't get refreshed - is there caching on by default ?  This might have been causing my earlier issue as I'm not seeing an updated page.

How do you update them? The html is cached in db but should be updated when you use the edit action.
 
Does you have to be in default/index to call auth.wiki() ?

No. But it should be exposed by one single web2py action.
 
Do users have to log in to see the wiki pages ?  The login screen comes up by default.  I would like a wik page to come up by default.

No, unless you set permissions=True. The caveat is that when you first start the app there are no wiki pages so nothing to see. Web2py assumes you must create some pages and therefore requires login to do that. After you create some pages (or only one), then they can be accessed publicly (unless permissions=True and you set restrictions on individual pages).

I will soon document this in the book a little better.

Andrew W

unread,
Sep 3, 2012, 7:42:48 PM9/3/12
to web...@googlegroups.com
I can create pages OK,  but when I click on Edit, make some changes and then press Submit, the changes do not get displayed.  The changes are still there if I open up the Edit screen again, but the html won't change.  I've stopped and restarted rocket but the old html stays.  I've tried on a few different installations   ???
If it is cached in the db, then a restart should have reset the cache.
They're not saved to a file are they ?

Andrew W

unread,
Sep 3, 2012, 7:47:03 PM9/3/12
to web...@googlegroups.com
P.S.  Menu changes work, in that the menu text gets updated, but the displayed menu text in the "content" area after I press submit still has the old text.

Andrew W

unread,
Sep 3, 2012, 9:16:19 PM9/3/12
to web...@googlegroups.com
I've just done some tests on tools.py
On edit:  The page.body is being updated correctly, but page.html does not change. 

I've added some print statements and markmin_render() (the compute functions for page.html) is called on the intial page create, but is not called on subsequent updates - page.html is not getting updated when editing an existing page.

Hope this helps.  Not sure how to fix it though.  Is it the SQLFORM call not triggering a compute of page.html?

Tito Garrido

unread,
Sep 8, 2012, 4:44:03 PM9/8/12
to web...@googlegroups.com
auth.wiki shouldn't include a WYSIWYG widget by default instead of a text box?

--
 
 
 



--

Linux User #387870
.........____
.... _/_õ|__|
..º[ .-.___.-._| . . . .
.__( o)__( o).:_______

Andrew W

unread,
Sep 8, 2012, 4:46:16 PM9/8/12
to web...@googlegroups.com
Good point.

Massimo Di Pierro

unread,
Sep 8, 2012, 5:16:32 PM9/8/12