1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- # -*- coding: utf-8 -*-
- # this file is released under public domain and you can use without limitations
- #########################################################################
- ## This is a sample 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)
- ## - api is an example of Hypermedia API support and access control
- #########################################################################
- def index():
- """
- example action using the internationalization operator T and flash
- rendered by views/default/index.html or views/generic.html
- if you need a simple wiki simply replace the two lines below with:
- return auth.wiki()
- """
- response.flash = T("Welcome to web2py!")
- print globals()['message']
- db1 = sql_dbs[0]
- row = db1().select(db1.experiment1.ALL).first().as_xml()
- #return dict(message=T('Hello World'))
- return dict(form=row)
- 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
- http://..../[app]/default/user/manage_users (requires membership in
- 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())
- @cache.action()
- 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_login()
- def api():
- """
- this is example of API with access control
- WEB2PY provides Hypermedia API (Collection+JSON) Experimental
- """
- from gluon.contrib.hypermedia import Collection
- rules = {
- '<tablename>': {'GET':{},'POST':{},'PUT':{},'DELETE':{}},
- }
- return Collection(db).process(request,response,rules)
|