Looks like I worked most of the bugs out of this. Hope it saves someone a
lot of time. If you know of a more *obvious or elegant* solution please
post it. Also, my slug field is returning a tuple now. Still works as a
slug but I wish I didn't have the |slug|None| format.
def insert_wiki_if_not_exists(table, s, f):
"""Used for auto creation of wiki pages for use with items already
in your table. On any update to the table set the wiki pages will be
create if it
doesn't exist.
To use:
In model file after table definition enter lines:
db.extracted_linear.wiki_page.required=False
db.mytable._before_update.append(lambda s,f: \
insert_wiki_if_not_exist(db.mytable, s,
f))
@see_also gluon.dal.RecordUpdater,
@see_also
http://web2py.com/books/default/chapter/29/06?search=_before_update
"""
tablename=table._tablename
table_wikis_set=db(db.wiki_page.tablename==tablename)
for s_row in s.select():
for row in table_wikis_set.select():
id = s_row.id
name = s_row.name or tablename + ' ' + id
f['wiki_page']=db.wiki_page.update_or_insert(
db.wiki_page.title==name,
title=name,
slug=table_slug(name.strip()),
body='#ADD PLUGIN CODE TO DISPLAY GRAPHS HERE\n' + \
'##Use WIKI menu to edit or delete this page',
changelog='inserted after ' + tablename + ' table
update',
tags=None,
tablename=tablename,
record_id=id)
s.update_naive()
return
--