1. Marc Schlaich
  2. gbottle-wiki

Source

gbottle-wiki / model.py

from gluon.sql import DAL, Field

from gae import GAE_ENV

if GAE_ENV:            
    db = DAL('gae')                           
else:                                        
    db = DAL('sqlite://wiki.sqlite', folder='db') 
    
db.define_table('page',
   Field('name', required=True, unique=True),
   Field('content', 'text', required=True),
   Field('date', 'date'))

def get_page(page_name):
    pages = db(db.page.name==page_name).select()
    if len(pages) == 1:
        return pages[0]
    else:
        return None
    
def create_page(page_name):
    id = db.page.insert(name=page_name, content='%s\n===' % page_name)
    db.commit()
    return db(db.page.id==id).select()[0]

def save_new_page_content(page_name, new_content):
    page = get_page(page_name)
    page.content = new_content
    db.commit()