# -*- coding: utf-8 -*-
# this file is released under public domain and you can use without limitations

#########################################################################
## This is a samples controller
## - index is the default action of any application
## - user is required for authentication and authorization
## - download is for downloading files uploaded in the db (does streaming)
## - call exposes all registered services (none by default)
#########################################################################
@auth.requires_login()
def index():
    """
    example action using the internationalization operator T and flash
    rendered by views/default/index.html or views/generic.html
    """
    #response.flash = "Welcome to Document Clasifier!"
    #Document = db().select(db.Document.ALL, orderby=db.Document.Name)
    #return dict(Document=Document)
    grid = SQLFORM.smartgrid(db.Document)
    return dict(grid=grid)
    
@auth.requires_login()
def show():
    #Document = db(db.Document.id==request.args(0)).select().first()
    Document = db.Document(request.args(0)) or redirect(URL('index'))
    db.Document_Annotaion.DocumentId.default = Document.id

    #form = SQLFORM(db.Document_Annotaion)
    #if form.process().accepted:
    #    response.flash = 'your annotation is posted'
    form = crud.create(db.Document_Annotaion,
                   message='your annotation is posted',
        next=URL(args=Document.id))
    Document_Annotaions = db(db.Document_Annotaion.DocumentId==Document.id).select()
    return dict(Document=Document, Document_Annotaions=Document_Annotaions, form=form)

@auth.requires_login()        
def manage():
    grid = SQLFORM.smartgrid(db.FIBO)
    return dict(grid=grid)
    
def user():
    """
    exposes:
    http://..../[app]/default/user/login
    http://..../[app]/default/user/logout
    http://..../[app]/default/user/register
    http://..../[app]/default/user/profile
    http://..../[app]/default/user/retrieve_password
    http://..../[app]/default/user/change_password
    use @auth.requires_login()
        @auth.requires_membership('group name')
        @auth.requires_permission('read','table name',record_id)
    to decorate functions that need access control
    """
    return dict(form=auth())


def download():
    """
    allows downloading of uploaded files
    http://..../[app]/default/download/[filename]
    """
    return response.download(request,db)


def call():
    """
    exposes services. for example:
    http://..../[app]/default/call/jsonrpc
    decorate with @services.jsonrpc the functions to expose
    supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
    """
    return service()


@auth.requires_signature()
def data():
    """
    http://..../[app]/default/data/tables
    http://..../[app]/default/data/create/[table]
    http://..../[app]/default/data/read/[table]/[id]
    http://..../[app]/default/data/update/[table]/[id]
    http://..../[app]/default/data/delete/[table]/[id]
    http://..../[app]/default/data/select/[table]
    http://..../[app]/default/data/search/[table]
    but URLs must be signed, i.e. linked with
      A('table',_href=URL('data/tables',user_signature=True))
    or with the signed load operator
      LOAD('default','data.load',args='tables',ajax=True,user_signature=True)
    """
    return dict(form=crud())

Add a code snippet to your website: www.paste.org