default.py.bak 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. # this file is released under public domain and you can use without limitations
  3. #########################################################################
  4. ## This is a sample controller
  5. ## - index is the default action of any application
  6. ## - user is required for authentication and authorization
  7. ## - download is for downloading files uploaded in the db (does streaming)
  8. ## - api is an example of Hypermedia API support and access control
  9. #########################################################################
  10. def index():
  11. """
  12. example action using the internationalization operator T and flash
  13. rendered by views/default/index.html or views/generic.html
  14. if you need a simple wiki simply replace the two lines below with:
  15. return auth.wiki()
  16. """
  17. response.flash = T("Welcome to web2py!")
  18. print globals()['message']
  19. db1 = sql_dbs[0]
  20. row = db1().select(db1.experiment1.ALL).first().as_xml()
  21. #return dict(message=T('Hello World'))
  22. return dict(form=row)
  23. def user():
  24. """
  25. exposes:
  26. http://..../[app]/default/user/login
  27. http://..../[app]/default/user/logout
  28. http://..../[app]/default/user/register
  29. http://..../[app]/default/user/profile
  30. http://..../[app]/default/user/retrieve_password
  31. http://..../[app]/default/user/change_password
  32. http://..../[app]/default/user/manage_users (requires membership in
  33. use @auth.requires_login()
  34. @auth.requires_membership('group name')
  35. @auth.requires_permission('read','table name',record_id)
  36. to decorate functions that need access control
  37. """
  38. return dict(form=auth())
  39. @cache.action()
  40. def download():
  41. """
  42. allows downloading of uploaded files
  43. http://..../[app]/default/download/[filename]
  44. """
  45. return response.download(request, db)
  46. def call():
  47. """
  48. exposes services. for example:
  49. http://..../[app]/default/call/jsonrpc
  50. decorate with @services.jsonrpc the functions to expose
  51. supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
  52. """
  53. return service()
  54. @auth.requires_login()
  55. def api():
  56. """
  57. this is example of API with access control
  58. WEB2PY provides Hypermedia API (Collection+JSON) Experimental
  59. """
  60. from gluon.contrib.hypermedia import Collection
  61. rules = {
  62. '<tablename>': {'GET':{},'POST':{},'PUT':{},'DELETE':{}},
  63. }
  64. return Collection(db).process(request,response,rules)